Search Unity

Sunshine! - Official Thread

Discussion in 'Assets and Asset Store' started by PolyVector, Aug 1, 2013.

  1. dshewmaker

    dshewmaker

    Joined:
    Oct 31, 2013
    Posts:
    18
    Thanks for you help and quick response.

    Fix for flickering/flashing on Android: I disabled the Multithreaded Rendering on the android build
     
  2. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Very interesting, thanks for the info!
     
  3. Jesse_Pixelsmith

    Jesse_Pixelsmith

    Joined:
    Nov 22, 2009
    Posts:
    296
    Apologize if this has been asked before, but Unity still doesn't have a "search in thread" option.

    Is Sunshine compatible with Andre Time of Day asset http://forum.unity3d.com/threads/time-of-day-dynamic-sky-dome.172763/ - and has anyone done previous integration of the two?

    I picked up Sunshine but I don't see anything out of the box re: day / night cycles? (not an expectation, just checking to make sure I didn't miss it)
     
  4. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    There's no day/night cycle out of the box, but it should integrate with most anything that uses the Directional light for a Sun/Moon. I'm not sure about the cloud shadows and scattering in the Time of Day asset though. Sunshine has it's own form of cloud shadows and scattering, and I'm not sure how the two would be mixed.
     
  5. Mihai77

    Mihai77

    Joined:
    Aug 7, 2013
    Posts:
    8
    The demo Robot.apk from http://unitysunshine.com/ does not work on Samsung Galaxy s2 with Android version 4.0.4.
    Any clue?
    Regards, Mihai.
     
  6. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The Tegra 3 chipset is the absolute bare minimum requirement to run Sunshine. I believe the s2 has a Tegra 2 chipset.

    I just realized, you must mean a newer version of the phone. If that's the case it might be "multithreaded rendering" which as dshewmaker just pointed out causes flickering on his device.
     
  7. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Hey, I've recently bought Sunshine, first off it's great to see this sort of stuff in Unity, thanks for making it & putting it on the store.

    I'm currently having one small issue, which is related to my complete lack of shader knowledge. I'm using Lux shaders, but when trying to edit the Lux/Bumped Specular shader, I get a shader error: "Too many texture interpolators would be used for ForwardBase pass". I've tried to google how to fix it, but I've never touched Shader code before, so I can't really understand what exactly is wrong.

    Anyways, left a rating on the store page, I'm very happy with Sunshine. Default Unity realtime shadows really do pale in comparison - no more tiny shadow distances, just to make Hard Shadows look half-decent.
     
    Last edited: Sep 13, 2014
  8. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    So glad it's working out for you, and thank you for the nice review.

    The interpolator problem is not an easy one to solve, especially if you're not a shader guru. The problem is that Unity's Surface Shaders (especially combined with physics based rendering) eat up every available interpolator for things that frankly only need to use 1/2. This leaves Sunshine without the single interpolator it needs, and the code isn't there to edit since it's generated behind the scenes. It may be possible to edit the "compiled" output of the surface shader to cut back on interpolators, but I haven't even attempted this yet to be honest.

    One solution would be to use the Deferred Renderer, since this means Sunshine can operate as a sort of post-process, but I know that's a big decisions to make just for shadows.
     
  9. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Hmmm, ok. I've had another play around and because I'm only using PBR for some objects, I should be able to get away with it as is, albeit with a few edge cases. On the plus side, I learnt something today, thanks!
     
  10. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Update: As it turns out, I won't be able to get away with it in forward, all my player characters are rendered in PBR, and they kinda need to receive shadows :D

    I've actually had a quick look into deferred rendering as an option, although I don't know too much about it past the basic Unity manual descriptions, and that BF4 uses it. Do you know of any extra caveats to it that are worth mentioning? If not, I may actually switch to deferred, since I'm only targeting newish PC hardware.
     
  11. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'm a fan of Deferred since it can handle many more lights (and Unity 5 will supposedly bring a "pure" deferred renderer, which is even better IMHO).

    If I had to generalize...
    Forward rendering is good for very simple scenes, mobile devices, and games that require a large number of custom shaders...
    Deferred rendering is great when you want to have more complex lighting in the scene, since it decouples the lighting from the shading (cutting down on the number of passes required).

    I would definitely give it a try and see how it works for your game.
     
  12. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    I'm now a fan of deferred. I got it working, and (with the help of sunshine) it also fixed an age-old problem of not having shadows cast on player arms+gun in first-person! http://pbrd.co/ZnFI7w
    I had to make a script to render to texture on my player viewmodel camera, because Unity still has a bug from 09' (http://forum.unity3d.com/threads/camera-depth-does-not-work-in-deferred-lighting-mode.82017/), but after that little fix, it's looking good :D

    Now I'm all set, I've got awesome shadows, FP-player shadows, still no FP model clipping into walls, and the player model now receives environmental shadows as well!
     
    Last edited: Sep 16, 2014
  13. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,363
    Have they said anything on the performance gain this new deferred mode will have ?

    The light handling is crucial in the GI Proxy system i am making, so this enchancement would be most welcome
     
  14. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'm betting it will be considerably faster since a "pure" deferred renderer only uses a single geometry pass, whereas the current "prepass" technique uses 2 passes. The other huge benefit, that I'm really hoping they take advantage of, is how decoupled all shading is from geometry. Letting users perform custom passes with the GBuffer could allow for custom shading/shadows/lighting techniques, which sounds like what you want... Just my own speculation though. ;)
     
    GoGoGadget likes this.
  15. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    13,363
    That would be awasome to have, would definitly open up a lot more possibilities.
     
  16. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Hey PolyVector!
    I have finally found what happens with my custom vertex shaders and sunshine's volumetric scattering not working!

    Quick recap:
    I made a custom surface shader with heavy vertex displacements in the vertex shader.
    I adapted it for receiving sunshine's shadows but didn't cast itself shadows.
    You told me to edit the "ocluders" shader to incorporate a rendertype for my custom shader.
    Sunshine's shadows finally worked perfectly both casting and receiving shadows.

    However:
    Sunshine's scattering wasn't working for my shader (no displacement).
    You told that was weird because the scatering used the same internals as the shadows.

    I have finally understood what happened: sunshine's scattering is using Unity's camera depth texture instead of it's own custom depth texture (the one used by the shadows).
    The problem was Unity couldn't generate the depth texture for my shader's displacement because it uses shader replacement internally (just like Sunshine) and I had to override the hidden and internal "Camera-DepthTexture.shader" for it to include my custom vertex displacement code.
    I was playing with image effects and, since some must use the camera depth texture and I wasn't generating it, I overrided the "Camera-DepthTexture.shader" for Unity to generate my displacement shader... and now Sunshine's scattering is working perfectly!

    However, this isn't practical because I have to render 3 times my custom displacement shader:
    1 time for the frame buffer
    1 time for Sunshine's internal shadow buffer
    1 time more for Unity's internal camera depth buffer

    The third one shouldn't be needed!
    It makes my FPS drop like crazy!
    Is this a bug, or is Sunshine really unable to make it's scatering without Unity camera depth texture help? (instead of using only it's own custom depth texture)

    Thanks
     
  17. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'm glad you figured it out! I'll attempt to clarify Sunshine's design choices a bit.

    Warning: This post grew way large than I intended!

    Scatter is essentially a vanilla post-process effect which leverages the same post-processing pipeline as other effects Unity, so the camera Depth buffer is the regular one that Unity provides (with the shader requirements you mentioned). This buffer is used to reconstruct the world position of each pixel, which is absolutely essential data to have before we can reproject into the shadowmap's depth buffer. The two buffers are completely different in their cameras/formats/projections, so they are both needed and can't be swapped for one another.

    That said, an argument could be made for having the shadowmap's depth buffer use the same shader as the camera Depth, but this unfortunately isn't practical. If Sunshine used the built-in depth shader for shadowmap generation, then it couldn't run on unsupported platforms like the Ouya/Tegra3, since depth textures are not supported, and there are a variety of technical features like depth biasing and the potential for future shadowmap techniques that would have to be dropped.

    Conversely, if we were to construct a screen-space depth buffer using Sunshine's "Occluder" shader, we would be wastefully recreating what is already available in Unity for post-processing by doing the same work over again with a slightly different shader. This could kill performance if you used other postprocess effects.

    Simply put, we have to accept the annoyance of writing vertex-related shader code 3x (or 2x without Sunshine). In projects I've worked on, we would write a .cginc file containing the vertex code so it could be reused by all relevant shaders, which works out really nicely in practice.

    Now, about performance. You most likely are seeing a performance drop because your custom shader was previously not being rendered into the camera Depth buffer (since it's RenderType wasn't supported, so I'll bet the Draw Calls/fill went up). This cost would be nearly identical with Sunshine's Occluder shader, so I don't think the performance hit is related to the particular shader used, just that there is more being rendered.

    Something you'll want to watch out for, which could be related, is to avoid using post-process effects that use DepthNormals AND effects that use Depth. If your camera is generating both buffers, this is an entire wasted pass, very expensive! One thing I've done in projects that needed that extra perf boost, was to tweak all my post-process effects to use one format or the other, and make sure to not enable both on the camera.

    Okay, so that was really long, I hope it helped though. :)
     
  18. atomicjoe

    atomicjoe

    Joined:
    Apr 10, 2013
    Posts:
    1,869
    Ok, I understand and it's true: my case is a very specific one and priority must be in compatibility and general usage :)
    I just wanted to know if it was the expected behaviour.
    Real scattering is not that important for me anyway: I can fake it with the SunShafts image effects and it's good enough for me :)
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Haha, well I guess that solves that. ;)

    I'm still rooting for some kind of "Shadowmap API" in Unity so we can add scatter effects without an entirely separate shadowing system, just not going to hold my breath.
     
  20. h4ndi

    h4ndi

    Joined:
    Sep 18, 2013
    Posts:
    3
    Hi, just bought sunshine yesterday; Blown Away!

    I'm currently adding it manually to custom vert frag shaders, and i've noticed that their is an issue with what appears to be biasing. In the attached image the sphere on the left is using "Sunshine/Examples/VertFrag Example" and the right is using "Sunshine/Examples/Surface Shader Example". I'm seeing the same selfshadowing biasing issues in my own shaders. any thoughts on how to solve this.
     

    Attached Files:

  21. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Glad to hear you're liking it so far. :)

    This type of effect shows up in shaders without any form of light attenuation (ie. N dot L). The VertFrag sample is overly simplified to demonstrate integration, and not really meant to be used.

    Normally the intensity of the shadow casting light would be zero, or 100% shadowed by the time self-shadowing kicks in, like the sphere on the right. Note that the shadow artifacts are all on the back side of the sphere.

    If you need to use shadows without a lighting model, or a "wrap around" model that makes these artifacts visible, you'll have to play with the following settings:
    • Sunshine's Lightmap Resolution, Distance, and Cascade settings.
    • The Light's Bias setting.
    • The Filter used in your shader (A higher PCF filter can help)
     
  22. h4ndi

    h4ndi

    Joined:
    Sep 18, 2013
    Posts:
    3
    Ah yes, thanks. I was using a half lambert. fixed by coloring the shadow based on half-lambert shift.
     
  23. zugsoft

    zugsoft

    Joined:
    Apr 23, 2014
    Posts:
    453
    I don't have shadow on my Android mobile with your apk example.
    Mediatek MT6572 2x 1.3Ghz CPU
    Mali-400 MP GPU.
     

    Attached Files:

  24. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Getting an issue with Sunshine that I also had with Shadow Softener. It doesn't happen on my desktop that I have Unity/etc on, but happens on other devices (One laptop with Win7 64bit running a GT540M, one Windows 8 laptop with an Nvidia card). Pics below show in-editor (how it should look), and the issue as screenshot in a standalone player. Using deferred renderer, and it happens with or without volumetric scattering.

    Ineditor.png Standalone.png
    I can actually reproduce the same effect that the issue has in-editor, by disabling the GameObject that holds my directional light. The console error shown in the screenshot is probably irrelevant, it's Bolt related.
     
  25. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    This GPU looks to support GLES2. Now, Sunshine does work with a Tegra 3 which also uses GLES2, but I haven't been able to test support outside of the Tegra 3. It may just be incompatible.

    Are you using any other packages that replace the "Internal-PrePassLighting" shader (ie, Shadow Softener)? If you have more of these shaders, it's almost certainly a conflict.

    A solution would be to delete all other replacement "Internal-PrePassLighting" shaders, optionally integrating their modifications into Sunshine's copy. After restarting the Editor, it should clear up.
     
  26. tripknotix

    tripknotix

    Joined:
    Apr 21, 2011
    Posts:
    744
    i also used to get shadows on my HTC Tmobile G2 device, with your demo, but i could never get the fog, but thats ok, except now i dont even get shadows when i build, im guessing over time through changes in the shader, it no longer works on some opengl es2 devices, my device in particular doesnt have the depth thing, which i think is whats required for the fog itself.
     
  27. GoGoGadget

    GoGoGadget

    Joined:
    Sep 23, 2013
    Posts:
    864
    Ah, that'd be it. Lux has it's own Internal-PrePass lighting shader. Hate to ask, but is there any chance you'd be able to bring built-in Lux support to Sunshine anytime soon? (One of the biggest reasons I've chosen Sunshine is because I'm very unfamiliar with shader code myself.) I really think it'd be worth it, as there are a huge number of Lux users in the community.
     
  28. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The included mobile scene is botched up in the current public release, I think the materials have the wrong shaders set. Double check that they are actually using Sunshine shaders.

    Scatter can't work on GLES2 because it does need the screenspace depth buffer. Also, a GLES2 chipset probably wouldn't be fast enough to actually use it in practice.
     
  29. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I can't keep up versions of the deferred shader for every package (lux, alloy, marmoset, etc). It is unfortunate the way Unity has the deferred shaders set up to only support one replacement, but if you PM me a project I'll look for a simple way to integrate Sunshine for you.
     
  30. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Hi PolyVector,

    I'm trying to integrate Sunshine shadows and Volumetric Scattering into a Deferred rendering project.
    Terrain is Forward rendering and its is using RTP as a shader.
    I've seen RTP has a support for Shadow Softener and already tried it with Sunshine with no luck.
    I've tried adding the lines to RTP as shown in the included Sunshine documentation.
    I had to remove "Lambert vertex:sunshine_surf_vert" (it was giving a warning and RTP has a "CustomBlinnPhong vertex:vert" at the same line)
    At the moment I'm getting one error which is;

    I think it is somehow related to the Sunshine.cginc.

    Having said all that; I should add that I'm not really sure I'm doing everything right. I just copied lines from the docs to rtp's shader and edited a bit down to this one error.
    Maybe I need them copied into multiple places, I'm not sure since RTP is big shader.

    Anyway, I hope you can show me the sunshine :)
     
  31. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hehe, I'll do my best to shine some light on the situation.

    Without seeing it though, it sounds like you may have missed the macro for Input structures:
    Code (csharp):
    1. SUNSHINE_INPUT_PARAMS;
    Also, if RTP already has a vertex shader make sure you use the "Piggyback" version of Sunshine's vertex macro:
    Code (csharp):
    1. SUNSHINE_SURFACE_VERT_PIGGYBACK(my_custom_vertex_modifier, Input)
    But of course, feel free to send me a small scene/projects, and I'll do my best to get your shader(s) working. :)
     
  32. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    The problem might be RTP also uses its own Input structure for surface shader ... :). You'll need to merge fields from RTP and Sunshine Input struct then I guess.

    Tom
     
  33. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Well, I know I've tried :) but I also know where to stop too.
    While juggling lines of code, I've stumbled to this error.
    a_small_error.jpg
    I immediately understood that I need to go no further :)

    So how can I resolve this?
    Is it OK to send PolyVector a small project that includes RTP shaders?
    or do we continue with suggestions and pasting codes?

    I can imagine, merging Sunshine and RTP is going to worth the results but it seems way out of my league.
     
  34. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I've definitely seen my share of that ever-so-helpful error... classic, heh.

    Adding sunshine support to RTP's Input structure directly should be relatively easy, it needs this single parameter:

    Code (csharp):
    1. float4 sunshine_lightData;
    Although you'll have to search or ask Tom where the structure is defined.

    About sending a test project, I can't speak for Tom but I've always felt that asset support is "fair use" of packages. I have no interest in nabbing up other people's code and always delete anything people send me after resolving issues... But I'm sure a whole ethics debate could be had on the subject. ;)
     
  35. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    So, try to find this line in RTP_Base.cginc (and RTP_AddBase.cginc) in RTP:

    Code (csharp):
    1.  
    2. struct Input {
    3.  
    and add Polyvector line
    Code (csharp):
    1. float4 sunshine_lightData;
    inside (before color:COLOR line).

    Tom
     
  36. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Tom thanks for taking a look.
    Unfortunately I couldn't managed to make this work. Here is what I did.
    and I get
    Lightmap-FirstPass?!?How did I do that :) I even don't want to use lightmaps (I used "no lightmaps in the RTP_LODmanager if that's relevant)
     
  37. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Too many interpolators doesn't look good. This means we've just run out of resources available. RTP itself works on the edge of possible interpolators count. It looks like Sunshine needs some interpolators itself. You could use "nolightmaps" in RTP LOD_manager. This saves 1 interpolator in some variants, but hard to tell if this would work.

    Tom
     
  38. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Well I've already tried that :)
    I'm using dx 9/11 as target platforms. 4 layers with No lightmaps and no ambient + holes is disabled + all RTP features disabled + PM as max LOD but still the same.
    I suspect it is something else, since I've nearly shut down all rtp features just to get the shadows but it doesn't change..
    Is there anyhing else I can do?
     
  39. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    Shutting down all RTP features makes no sense if you need them. RTP relies on parameters that need to be passed from vertex processor to fragment (pixel) processor. These are "interpolators". There are always lack of them, even for moderately simple shaders... In worst case if you're 100% sure what kind of scenario you need, I could try to implement it custom way to force RTP work with Sunshine. For such job you would need to contact Polyvector if he doesn't mind I look around his package on your sample project. 2nd - I need to know if you're my customer or "user". So - contact me in private, because such integration job is far beyond standard customer support one should expect here.

    Tom
     
  40. gurayg

    gurayg

    Joined:
    Nov 28, 2013
    Posts:
    269
    Oh! we're going underground... I like that :)
    Jokes aside, thanks both for helping out.

    I shutdown features to test if I can bring shadows. Cannot trust compile errors when it comes to shaders.
    I understand more clearly what those mysterious "v2f" are now.

    Clearly understood the rest;
    I'm pretty sure about my scenario and will send you my proof of purchase (will send you via pm)
    Will ask PolyVector via pm as well.

    Not to leave with an empty post, I'd like to post a short selected list of new features in V5 that I think related to shader devs.

    link

    -Shadows: Added PCF (5x5) filtering for soft directional light shadows.
    -Shadows: in Forward rendering, directional light shadows are computed from camera's depth texture instead of a separate "shadow collector" rendering pass.
    -Graphics: Support for more shader keywords (128 instead of 64)
    -Shaders: Surface shaders allow more texture interpolators, when targeting shader model 4.0+ (up to 32).
    -Shaders: Fog handling in shaders was changed.
    -Shaders: Some shader compilers have changed:

    What do you guys think about new features in shaders?
     
  41. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,862
    I've downloaded U5 beta as pre order user. Will look into this later. I don't see terrain issues fixed which I reported to Unity :(. So probably more problems are just about the corner... But - "terrain is now native engine element (not C#) thus I expect better overall performance on CPU.

    Tom
     
  42. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    These changes are long overdue, but I'm still sad that we don't have real access to the shadow buffers/matrices so Sunshine wouldn't need an entirely separate shadow mapping system.

    The user in me is thrilled by many of the changes, but the dev in me is terrified by the potential compatibility issues.
     
    Last edited: Oct 28, 2014
  43. Phelan-Simpson

    Phelan-Simpson

    Joined:
    Jan 1, 2014
    Posts:
    31
    Hello PolyVector,

    Just a couple quick question about Sunshine. It probably has been asked before, but I could find it in this many posts.

    Do all of it's features work in unity 5?

    Does it work with enlighten for the real-time GI?

    Cheers and thanks,
     
  44. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    The Unity 5 beta was only released yesterday to pre-order customers, so I've only begun to investigate the many changes to ShaderLab. The current release is not compatible with Unity 5 at all, but I hope to get it fully functional and Enlighten-friendly as quickly as possible.
     
  45. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine 1.6.0 Available on the Unity Asset Store

    • Preliminary Unity 5.0 Beta support.
    • Occluder LayerMask Settings are now 'int' typed, you may need to configure these again.
    • Internally using 'surfIN' struct to get around ShaderLab packer changes.
    • Desktop/Mobile Scattering passes are now appropriately named.
    • Example scene materials should be set correctly now.
    • Removed accidental copy of Sunshine's project settings.
     
  46. p87

    p87

    Joined:
    Jun 6, 2013
    Posts:
    318
    mmm so what does "preliminary unity 5 beta support" mean?

    picked up Sunshine and I keep getting this error in the console:

    Sunshine 1.6.0: Occluder Shader Not Supported...
    UnityEngine.Debug:Log(Object)
    Sunshine:LogMessage(String, Boolean) (at Assets/Sunshine/Scripts/Sunshine.cs:17)
    Sunshine:Setup() (at Assets/Sunshine/Scripts/Sunshine.cs:718)
    Sunshine:Start() (at Assets/Sunshine/Scripts/Sunshine.cs:897)

    this is running the sample scene that is included with sunshine. I also got this error while testing in a different scene.


    could you please fill me in on what is working and what isnt with unity 5? thanks
     
  47. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Argh, looks like I forgot to commit my changes to the Occluder shader into the master branch.

    A temporary fix would be to open up the Occluder shader and remove (or comment out) any SubShader containing "RenderType" = "Tree...

    This preliminary support was meant to fix the major breaking changes like the new ShaderLab interpolator packing and issues with LayerMask serializing, etc. There are bound to be issues since Unity 5 introduces major rendering changes, not to mention it's beta software.

    I'll try to get a fix for the Occluder shader up tomorrow.
     
    p87 likes this.
  48. Almakos

    Almakos

    Joined:
    Dec 13, 2013
    Posts:
    179
    Hey PolyVector,
    Sunshine looks amazing, but does it work on iOS?
    As I can see only talks about android...but we are exclusively on iOS at the moment.

    Thanks.
     
  49. Project-Mysh

    Project-Mysh

    Joined:
    Nov 3, 2013
    Posts:
    223
    Hi PolyVector,

    A question about custom forward shaders:
    I have a custom shader that already have a vertex modifier for wind animation, how i have to configure the shader to work with sunshine? I have to add another pass? Here is the code:

    Code (CSharp):
    1. Shader "Sunshine/Mysh/Mysh_Hierba" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _Cutoff ("Alpha cutoff", Range(0,1)) = 0.3
    5.         _AmbColor1 ("AmbColor1", Color) = (0,0.006896496,1,1)
    6.         _AmbColor2 ("AmbColor2", Color) = (0.1586208,1,0,1)
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 200
    11.         Cull Off
    12.      
    13.         CGPROGRAM
    14.         #pragma surface surf SimpleLambert alphatest:_Cutoff vertex:CustomBendingGSFull nodirlightmap nolightmap halfasview
    15.         #pragma exclude_renderers flash
    16.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/Tree.cginc"
    17.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/CustomBending_GS.cginc"
    18.      
    19.         fixed4 LightingSimpleLambert (SurfaceOutput s, half3 lightDir, half atten) {
    20.               half NdotL = (dot (s.Normal, lightDir))*0.2+0.8;
    21.               fixed4 c;
    22.               c.rgb = s.Albedo * (_LightColor0.rgb*1.25) * (NdotL * atten * 2);
    23.               c.a = s.Alpha;
    24.               return c;
    25.         }
    26.                      
    27.         sampler2D _MainTex;
    28.         fixed4 _MainTex_ST;
    29.         fixed4 _AmbColor1;
    30.         fixed4 _AmbColor2;
    31.      
    32.         struct Input {
    33.             fixed2 myuv_MainTex;
    34.         };
    35.      
    36.         void CustomBendingGSFull (inout appdata_full v, out Input o)
    37.         {
    38.             UNITY_INITIALIZE_OUTPUT(Input,o);
    39.             o.myuv_MainTex.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    40.             v.vertex = MyAnimateVertex (v.vertex, v.normal, float4(v.color.xyzz));
    41.             v.normal = normalize(v.normal);
    42.             v.tangent.xyz = normalize(v.tangent.xyz);
    43.         }
    44.  
    45.         void surf (Input IN, inout SurfaceOutput o) {
    46.             fixed4 c = tex2D (_MainTex, IN.myuv_MainTex);
    47.             o.Albedo = c.rgb*lerp(_AmbColor2.rgb,_AmbColor1.rgb,IN.myuv_MainTex.y);
    48.             o.Alpha = c.a;
    49.         }
    50.         ENDCG
    51.      
    52.         // Pass to render object as a shadow caster
    53.     Pass {
    54.         Name "ShadowCaster"
    55.         Tags { "LightMode" = "ShadowCaster" }
    56.      
    57.         Fog {Mode Off}
    58.         ZWrite On ZTest LEqual Cull Off
    59.         Offset 1, 1
    60.  
    61.         CGPROGRAM
    62.         #pragma vertex vert_surf
    63.         #pragma fragment frag_surf
    64.         #pragma exclude_renderers noshadows flash
    65.         #pragma glsl_no_auto_normalization
    66.         #pragma fragmentoption ARB_precision_hint_fastest
    67.         #pragma multi_compile_shadowcaster
    68.         #include "HLSLSupport.cginc"
    69.         #include "UnityCG.cginc"
    70.         #include "Lighting.cginc"
    71.  
    72.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/Tree.cginc"
    73.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/CustomBending_GS.cginc"
    74.  
    75.         sampler2D _MainTex;
    76.  
    77.         struct Input {
    78.             fixed2 uv_MainTex;
    79.         };
    80.  
    81.         struct v2f_surf {
    82.             V2F_SHADOW_CASTER;
    83.             fixed2 hip_pack0 : TEXCOORD1;
    84.         };
    85.      
    86.         fixed4 _MainTex_ST;
    87.         v2f_surf vert_surf (appdata_full v) {
    88.             v2f_surf o;
    89.             CustomBending (v);
    90.             o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    91.             TRANSFER_SHADOW_CASTER(o)
    92.             return o;
    93.         }
    94.         fixed _Cutoff;
    95.         fixed4 frag_surf (v2f_surf IN) : COLOR {
    96.             half alpha = tex2D(_MainTex, IN.hip_pack0.xy).a;
    97.             clip (alpha - _Cutoff);
    98.             SHADOW_CASTER_FRAGMENT(IN)
    99.         }
    100.         ENDCG
    101.     }
    102.  
    103.     // Pass to render object as a shadow collector
    104.     Pass {
    105.         Name "ShadowCollector"
    106.         Tags { "LightMode" = "ShadowCollector" }
    107.      
    108.         Fog {Mode Off}
    109.         ZWrite On ZTest LEqual
    110.  
    111.         CGPROGRAM
    112.         #pragma vertex vert_surf
    113.         #pragma fragment frag_surf
    114.         #pragma exclude_renderers noshadows flash
    115.         #pragma fragmentoption ARB_precision_hint_fastest
    116.         #pragma multi_compile_shadowcollector
    117.         #pragma glsl_no_auto_normalization
    118.         #include "HLSLSupport.cginc"
    119.         #define SHADOW_COLLECTOR_PASS
    120.         #include "UnityCG.cginc"
    121.         #include "Lighting.cginc"
    122.  
    123.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/Tree.cginc"
    124.         #include "../../Advanced Foliage Shader v3/Shaders/Includes/CustomBending_GS.cginc"
    125.  
    126.  
    127.         sampler2D _MainTex;
    128.         //sampler2D _BumpTransSpecMap;
    129.         //float _ShadowOffsetScale;
    130.  
    131.         struct Input {
    132.             fixed2 uv_MainTex;
    133.         };
    134.  
    135.         struct v2f_surf {
    136.             V2F_SHADOW_COLLECTOR;
    137.             fixed2 hip_pack0 : TEXCOORD5;
    138.             //float3 normal : TEXCOORD6;
    139.         };
    140.      
    141.         fixed4 _MainTex_ST;
    142.      
    143.         v2f_surf vert_surf (appdata_full v) {
    144.             v2f_surf o;
    145.             CustomBending (v);
    146.             o.hip_pack0.xy = TRANSFORM_TEX(v.texcoord, _MainTex);
    147.          
    148.             //float3 worldN = mul((float3x3)_Object2World, SCALED_NORMAL);
    149.             //o.normal = mul(_World2Shadow, half4(worldN, 0)).xyz;
    150.          
    151.  
    152.             TRANSFER_SHADOW_COLLECTOR(o)
    153.             return o;
    154.         }
    155.      
    156.         fixed _Cutoff;
    157.      
    158.         half4 frag_surf (v2f_surf IN) : COLOR {
    159.             half alpha = tex2D(_MainTex, IN.hip_pack0.xy).a;
    160.  
    161.             //float3 shadowOffset = _ShadowOffsetScale * IN.normal * tex2D (_BumpTransSpecMap, IN.hip_pack0.xy).b;
    162.  
    163.             clip (alpha - _Cutoff);
    164.  
    165.             //IN._ShadowCoord0 += shadowOffset;
    166.             //IN._ShadowCoord1 += shadowOffset;
    167.             //IN._ShadowCoord2 += shadowOffset;
    168.             //IN._ShadowCoord3 += shadowOffset;
    169.  
    170.             SHADOW_COLLECTOR_FRAGMENT(IN)
    171.         }
    172.         ENDCG
    173.     }
    174. }
    175. }
    P.D: If im using Sunshine, CAnremove "Shadow collector" and "Shadow Caster" passes?
    P.D2: Yes, i have read the manual, but I dont really understand how i can piggyback my vertex modifier....
     
    Last edited: Oct 31, 2014
  50. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I believe some people have used Sunshine on iOS successfully, but I have no experience developing for iOS, so I wouldn't be of much help. Feel free to try it out, and if it doesn't work I'll throw you a refund. :)

    If you want to edit your existing vertex modifier, you could add this line in it:
    Code (csharp):
    1. SUNSHINE_WRITE_SURF_VERTEX(v, o);
    Alternatively, you could add this line after (and outside of) your vertex modifier function:
    Code (csharp):
    1. SUNSHINE_SURFACE_VERT_PIGGYBACK(Input, CustomBendingGSFull)
    You would then need to change your "#pragma surface" line to point to "vertex:sunshine_surf_vert" if you use the Piggyback method.

    Yes, you can remove your shadow collector if you plan on exclusively using Sunshine shadows. Shadow collectors are no longer needed in Unity 5 anyway.

    As for the Shadow Caster pass, this is where it gets a bit tricky. If you need the cast shadows to perfectly match the object, you'll need to use a custom RenderType in your shader, and include an equivalent SubShader in Sunshine's Occluder shader. This is the shader used for shadow casting.

    I like to place my vertex modifying code in a shared .cginc file, this way it can be accessed from the Occluder shader or the CameraDepth and CameraDepthNormals shaders (these shaders have the same annoying requirements if you need your shader to have correct depth for image effects).