Search Unity

Sunshine! - Official Thread

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

  1. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    I'm getting an error at sampler2D _MainTex; line 10. I changed to _Color and Unity crashed!
     
  2. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Oops, the linebreak didn't copy correctly into the forum post (and that line wasn't needed in the first place). Just delete the "sampler2D _MainTex" part, I've edited my last post to reflect this.

    It's working for me on Unity 5.3.2 on OS X, so hopefully that little typo is the only issue.
     
  3. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    Hmm this is the same script I had originally written when I posted here! xD Using this shader gives me this error:

    Much thanks for the quick support, 5 star regardless. Working with shaders makes me feel stupid.



    Code (CSharp):
    1. Shader "Sunshine/Custom/VertexColorBasicSunshine" {
    2.     Properties{
    3.         _Color("Color Tint (RGB)", COLOR) = (1, 1, 1, 1)
    4.         _Strength("Vertex Color Strength", Range(0, 1)) = 1
    5.     }
    6.         SubShader{
    7.         Tags{ "RenderType" = "Opaque" }
    8.         LOD 200
    9.  
    10.         CGPROGRAM
    11.  
    12.     #include "Assets/Sunshine/Shaders/Sunshine.cginc"
    13.     #pragma multi_compile SUNSHINE_DISABLED SUNSHINE_FILTER_PCF_4x4 SUNSHINE_FILTER_PCF_3x3 SUNSHINE_FILTER_PCF_2x2 SUNSHINE_FILTER_HARD
    14.     #pragma target 3.0
    15.     #pragma surface surf Lambert vertex:vert exclude_path:prepass
    16.  
    17.     float _Strength;
    18.     float3 _Color;
    19.  
    20.     struct Input {
    21.         float3 vertColors;
    22.         SUNSHINE_INPUT_PARAMS;
    23.     };
    24.  
    25.     void vert(inout appdata_full v, out Input o) {
    26.         UNITY_INITIALIZE_OUTPUT(Input, o);
    27.         o.vertColors = v.color.rgb;
    28.         SUNSHINE_WRITE_SURF_VERTEX(v, o);
    29.     }
    30.  
    31.     void surf(Input IN, inout SurfaceOutput o) {
    32.         float3 c = IN.vertColors.rgb * _Strength;
    33.         o.Albedo = c.rgb * _Color;
    34.     }
    35.     ENDCG
    36.     }
    37.         FallBack "Diffuse"
    38. }
     
  4. Selzier

    Selzier

    Joined:
    Sep 23, 2014
    Posts:
    652
    This may be a 5.4 Bug. I'll test on 5.3 ASAP. Thanks again.
     
  5. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    We're not supporting the 5.4 beta just yet, too many changes to keep up with. We'll try to push out a compatibility update when 5.4 goes final.

    Thanks for the kind words, and don't worry, shaders give everyone a headache. :)

    Cheers,
    Oren
     
  6. electricseed

    electricseed

    Joined:
    Sep 23, 2012
    Posts:
    17
    Hi Polyvector,

    I'm experiencing the inverted shadow on my android device too. I'm using unity 5.3.4 and an android lg g3 - shadow is done with forward rendering (and your sunshine shaders). Did you get any further with this issue since it still seems to be in the current version?

    Thanks
    Manfred
     
    Last edited: Apr 21, 2016
  7. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I haven't seen this myself, if you could send me a small project that reproduces the problem that would help me track down the issue.
     
  8. electricseed

    electricseed

    Joined:
    Sep 23, 2012
    Posts:
    17
    Hi Oren,

    I sent you an email with a download link to a project.
    Just for info: i changed the sunshine shader code to invert the shadow and it now works on my android phone, while beeing broken on pc ;) But this gives me time for a proper fix, since i can show the app to my clients.
     
  9. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Glad you have a temporary work-around. I've emailed you a test project with some experiments. Hopefully this will give me some clues as to what's going on so we can get you a proper fix.

    Cheers,
    Oren
     
  10. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    How many keywords used for sunshine?
     
  11. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine uses about 15 of of the 128 available (or 64 available in Unity 4.x)
     
    ksam2 likes this.
  12. ksam2

    ksam2

    Joined:
    Apr 28, 2012
    Posts:
    1,079
    Is there a way to use less keywords? as you know 128 keywords limitation is a real big limitation to let sunshine use 15 of it.
     
  13. pixxelbob

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    This may have been asked before.
    Is there any possibility of a mobile "trial" version?

    I'm keen to test this against unity's shadows in our mobile game. Our game consists of multiple simulated actors pathing and interacting. If Sunshine! Performs better than unity shadows that will greatly improve the overall quality of our game and certainly worth the 95$ price tag.

    Thanks for your time.
     
  14. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hello,
    We don't offer trial versions I'm sorry to say, but you can feel free to buy it on a trial basis and I will issue a return if it doesn't work out for your purposes.

    As a heads up, we are preparing an update that should fix an issue with performance so you may want to hold off for this release (1.8.2).

    Cheers,
    Oren
     
  15. pixxelbob

    pixxelbob

    Joined:
    Aug 26, 2014
    Posts:
    111
    Hey Oren, Thanks for the quick reply.
    I appreciate the offer. In that case I will hang fire for 1.8.2.

    Thanks
     
  16. Skunkie

    Skunkie

    Joined:
    Jul 2, 2012
    Posts:
    75
    Sunshine 1.8.2 is Now Available in the Asset Store
    • Improved suppression of Built-In shadows
    • Removed legacy "step" code
     
  17. Pomettini

    Pomettini

    Joined:
    Aug 29, 2013
    Posts:
    26
    Hi,

    We have a problem with the last version of Sunshine on our game running on Unity 5.3.3,

    On iOS everything looks fine, but on every Android device we have in our studio it renders shadow artifacts (screenshots below),

    So far we tested it on Nexus 7 2013, Zenfone 2 Deluxe, Samsung S4 and Oneplus 2 and the shadows looks the same,

    Can I kindly ask you how can we fix this issue?

    Thanks,

    G.
     

    Attached Files:

    grayfox9020 likes this.
  18. Gametyme

    Gametyme

    Joined:
    May 7, 2014
    Posts:
    618
    Did you ever get around to trying this?
     
  19. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi G,

    If your game doesn't need the terrain to cast a shadow on itself, I would recommend placing it on a Layer that's not in Sunshine's "Occluders" list. This may give you a decent performance boost from reduced fill, and should eliminate self shadowing artifacts like this.

    If you need the terrain to self-shadow, then you can try adjusting the Bias and Normal Bias on the light. You might also try reduce the camera's FarClip and see if that helps.

    Cheers,
    Oren
     
  20. Pomettini

    Pomettini

    Joined:
    Aug 29, 2013
    Posts:
    26
    It worked! Thanks a lot for the quick answer Oren! :)
     
  21. God-at-play

    God-at-play

    Joined:
    Nov 3, 2006
    Posts:
    330
    Any ETA on a compatibility update for 5.4b? That would really come in handy :)

    BTW I don't know if you were aware, but we used Sunshine for That Dragon, Cancer to support limited shadows on OUYA, and then used it generally for PC as well. Thanks for your work!
     
    Pomettini likes this.
  22. Pomettini

    Pomettini

    Joined:
    Aug 29, 2013
    Posts:
    26
    Sorry to bother you again Oren, but after further testing we still found shadow artifacts on some objects, even if we removed the terrain layer from the occluder list,

    We also tried tweaking the light bias and the camera far clip as you suggested, but we don't see any difference,

    Do you have any suggestion for us? Thanks again
     

    Attached Files:

  23. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I don't think we're going to support 5.4 until it goes final. It's just such a moving target right now. Nice to see Sunshine being put to good use, for some reason I assumed it didn't make it into the final game. :)

    Edit: I've sent you a PM

    That's an odd shadow artifact now that I'm looking closer. It almost appears that the depth buffer on the device is insufficient (16bit?). I'm fairly certain Unity removed the option to force a 24bit depth buffer on Android, maybe you can increase the NearClip to get better resolution close up.

    Feel free to send me a small test scene that reproduces the issue, in case there's some combination of settings that's causing it. I'll also see if I can get it to happen on one of my test devices. Unfortunately my Nexus 7 2013 bit the dust, hopefully I can reproduce it on something.

    Cheers,
    Oren
     
  24. Pomettini

    Pomettini

    Joined:
    Aug 29, 2013
    Posts:
    26
    Thank you for your answer Oren. I asked my bosses but unfortunately we cannot share the project, even a test scene. I tried increasing the NearClip of the camera, but we have tall objects that would be culled (currently the camera settings are: 10 near and 300 far, with a FOV of 30).

    I also tried enabling 32-bit display buffer from the Android build settings, without luck.

    Can we try something else to fix the problem? Thank you again,

    G.
     
  25. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Hello there!

    Is it possible to exclude objects from Sunshine, or to fade it out over distance or something?
    We are currently working on a project where we want some light to shine through the windows, but we don't want the faraway buildings to become paler and lighter because of the light. (I understand that it's realistic, but it just doesn't work with our scene.)
    We tried to exclude the buildings layer from Sunshine, but, well, it didn't work.

    Capture.PNG
    ^ Exaggerated example [sorry for the image quality]

    Best Regards,
    Kristina Waldt
     
  26. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I'm sorry that didn't work out, I'll continue to run my own tests to look for a cause/solution. About the test project, A blank project with the minimum setup to reproduce the problem is fine (it doesn't need anything from your game in it) but it's okay if that isn't possible. If I think of other changes you could try I'll let you know.

    There's no official way to accomplish this, but it is something I am looking into for a future release (no ETA).

    What I would try is editing the Sunshine Post Scatter shader to use a masking RenderTexture you create in another pass. Alternatively you could use the scene's alpha channel in the same way if you customize your shaders to output a masking value.

    Another option would be to set the "Sky Intensity" value you 0, then modify the distant buildings' shader to either A) not write to the Z-Buffer, or B) output a depth of 99.9% FarClip. This will treat the buildings as "Sky" and not apply Scatter.

    I hope this helps.
     
  27. KWaldt

    KWaldt

    Joined:
    Nov 1, 2013
    Posts:
    127
    Sounds reasonable, thank you!
    I'll ask you if I have any specific question considering the implementation, but your explanation sounds logical!
     
  28. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Good news, I was able to reproduce the issue on my devices (and I also understand now why I wasn't able to before). Now that I can properly investigate this, I'll update you as soon as I know more.

    Edit: It does appear to be a precision issue, but I don't think it's the buffer itself. For the time being I would recommend reducing the "Z Padding" setting in Sunshine to 0, or as low as possible. This should reduce the artifacts.

    Cheers,
    Oren
     
    Last edited: May 17, 2016
    Pomettini likes this.
  29. Pomettini

    Pomettini

    Joined:
    Aug 29, 2013
    Posts:
    26
    Thanks a lot Oren, reducing the Z Padding to 0 removed almost all the artifacts. However, we still have some artifacts that are barely visible (see the screenshots) mostly on big surfaces. Do you know if it's possible to remove them? We have to submit the app this evening, if you could please give us some advices before the release would be really helpful for us.

    Thanks a lot again,

    G.
     

    Attached Files:

  30. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sorry, but I'm still trying to work out a solution. Other than increasing the Light Bias, the only other way I can think of (which I haven't tested) is to specify the Custom Bounds property, possibly attaching it to your player. This would limit the range the lightmap has to work with to a minimum.
     
  31. benthroop

    benthroop

    Joined:
    Jan 5, 2007
    Posts:
    262
    Hi just a few questions about Sunshine...

    - Does it support spotlight shadows?
    - Any idea if it works on PS4? If so any idea about performance?
    - Does it replace the Standard shader?

    Thanks!
     
  32. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    - No, Sunshine only supports a single Directional light, usually the Sun or Moon.
    - I have no experience with the PS4, but Slender: The Arrival managed to get it working. I'm unaware if it required modification though.
    - It depends.
    a) If you plan on using the Scatter effect without "Custom Shadows", you won't need to alter any shaders. a single-cascade shadowmap is generated behind-the-scenes and used for postprocessing. This is the easiest way to integrate Sunshine, but depending on your bottleneck can impact performance.
    b) If you plan on using the "Custom Shadows" feature, you will need to swap out shaders for ones that support Sunshine. We include a replacement set of most built-in shaders, including the Standard shader.

    Performance can be faster in some games, slower in others, it all depends on your bottleneck.

    I hope this helps.

    Cheers,
    Oren
     
  33. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Hi G,

    Pretty sure I've solved your bug! I'd like you to test the change before we release an update.

    Turns out Unity's GLES cross-compiler was using temporary variables that were lower precision than required by the Depth Decoding method. After some digging, it appears this can be fixed by declaring the shadowmap as a Float Sampler, even though it is not.

    Here's the Fix:
    1)
    Edit the following line in Sunshine.cginc to use a sampler2D_float instead of the usual sampler2D:
    Code (csharp):
    1.  sampler2D_float sunshine_Lightmap;
    2) Right-click on the Sunshine/Shaders/ folder and select "Reimport" to force your shaders to update.

    I hope this helps.

    Cheers,
    Oren
     
  34. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    579
    @PolyVector Can Sunshine cast shadows on Tessellated surfaces?
     
  35. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I actually haven't worked with tessellation, maybe another user here has some experience in this area?
     
  36. Issam

    Issam

    Joined:
    Dec 18, 2012
    Posts:
    37
    Hi,

    I am trying to use occlusion with sunshine but a lot of shadow stop rendering when I enable it in the advanced setting. I confirmed that the sunshine cameras are in the occlusion area that I baked, but it seems to just not work correctly with occlusion. Is there anything that need to be done for it to work? Occlusion work fine for the main camera, I would love to have it working for the shadows camera as well.

    To be clear the problem we are noticing is that when occlusion is turned on for the sunshine cameras, a lot of objects are not rendered into the shadow map. When I move the main camera shadow start popping in/out. I am not really sure how the unity occlusion system work (and if it works for orthogonal cameras?), so any advice would be really useful.
     
  37. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    I've noticed this happening in some scenes with baked Occlusion data, and to the best of my knowledge the issue is caused by the orthographic sunshine cascade cameras going outside the occlusion bounds.

    The quickest fix is to reduce the Z Padding setting a little bit and see if that helps.

    A better solution I've used before is to place a few tiny static cubes (or quads) some distance outside the level (especially towards the sun's position) to force the Occlusion bounds to be larger. You can set the "Static" setting to just be "Occlusion Static" to avoid the mesh being baked into the scene. To prevent rendering the unwanted cubes, you can disable their renderers at runtime or place them on a non-rendered layer.

    I hope this helps.

    Cheers,
    Oren
     
  38. Ascensi

    Ascensi

    Joined:
    Sep 7, 2013
    Posts:
    579
  39. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Unfortunately I'm on a Mac which doesn't support these features to my knowlege, and if I virtualize Windows it only goes up to DX9 support. I could use Boot Camp to get DX11, but I've had trouble getting it to work with my Fusion drive. So I really can't say if this will work with Sunshine.

    It would probably require a modification to Sunshine's Occluder shader so that it can cast shadows properly, but beyond that I'm unsure.

    Cheers,
    Oren
     
  40. Issam

    Issam

    Joined:
    Dec 18, 2012
    Posts:
    37
    Thanks, this helped me start looking more at orthogonal camera and the occlusion system more. I am not sure why but at least in our game (did not test it elsewhere), the occlusion system does not work well with orthogonal camera, but by giving it a good amount of negative values for the near plane it activate the occlusion cells behind the camera and it works correctly then (maybe internally it thinks the camera is closer then it should be?)

    in our case because the shadow camera are above the scene and there's nothing behind them, giving them a negative near plane values works, and for some reason it does not affect the shadow map quality. (I was assuming it would because of the depth value stored?)

    This is the code I changed in SetupShadowCamera(...) in case someone else has that problem:

    Code (CSharp):
    1.         lightCamera.farClipPlane = (totalShadowBounds.radius + paddingZ + eyeCamera.nearClipPlane) * 2f;
    2.  
    3.         if (Sunshine.Instance.UseOcclusionCulling)
    4.         {
    5.             lightCamera.nearClipPlane = Mathf.Max(-lightCamera.farClipPlane / 2.0f, -200.0f);
    6.         }
    7.         else
    8.         {
    9.             lightCamera.nearClipPlane = eyeCamera.nearClipPlane;
    10.         }
    And on the last line:

    Code (CSharp):
    1. lightCameraTransform.position += lightCameraTransform.forward * (shadowCenterInLight.z - (totalShadowBounds.radius + eyeCamera.nearClipPlane + paddingZ));
    I also made a much bigger occlusion area to cover the shadow camera, but I don't need to put objects outside to make the occlusion bounds bigger. (doing that did not work for us)
     
  41. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Issam,

    That's clever! I hadn't considered the possibility of using a negative NearClip value (didn't even know it was allowed in Unity). You're right that this shouldn't really affect the shadowmap because the values are stored manually from a shader that ignores the NearClip.

    I'll run some tests and maybe the fix can make it in an update. Thanks for figuring this out, it seems like an elegant solution. :)

    Edit: I couldn't get this to reproduce in Unity 5.3.4 with the latest Sunshine, although I've definitely seen it in the past. I wonder if the issue is actually related to needing an increased Padding Z value (which moves the camera backwards, effectively similar to your negative NearClip), and also to make sure the shadow cameras do not wind up "inside" a culling occluder.

    It's just a thought, I'll run more tests.


    Cheers,
    Oren
     
    Last edited: May 27, 2016
  42. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Tips for image effects order when using Sunshine? Also, Sunshine is not accepting the OVRCameraRig CenterEyeAnchor as a stereoscopic master camera in the Inspector (Unity 5.3.4f1, OVR 1.3.2). Is something happening under the hood?
     
    Last edited: Jun 22, 2016
  43. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    My best suggestion would be to think about each effect if it's happening in the world, or the camera. Anything that's a "camera" effect, like lens flare or color effects should apply after Scatter. Anything that's happening in the world on solid objects, like SSAO, should apply before. In some particular situations, it can help to add the [ImageEffectOpaque] attribute to SunshinePostprocess.OnRenderImage, but not usually.

    I've had success with Sunshine+Oculus in the past, but I admittedly don't have much experience with VR. I believe the "Master Camera" option is no longer needed since Unity added native support for stereoscopic cameras. The latest version of Sunshine should "just work" when used on a Stereoscopic camera. If OVR is really using 2 separate cameras, make sure SunshineCamera is attached to each of them before setting up the "Master Camera".
     
  44. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Thanks for your quick response. To be sure, I am NOT having any issues with Sunshine using the aforementioned Unity / Oculus versions. My only confusion was regarding the Sunshine optimization for shared lightmaps. Also, if it helps, OVR assets now use a single center eye camera, not two left-right cameras as before. You're right, however, that Unity provides native support for VR on Unity cameras, but in many cases it is desirable to use the native Oculus, Vive, Google, etc., assets in order to access back-end functionality.
     
  45. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    How to correct?:

    This custom render path shader needs to have at least 2 passes.

    Sunshine Camera Script on Main Cam will activate, cannot activate Sunshine Postprocess script(?)
     
  46. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Sunshine will automatically enable/disable the Postprocess component as needed. Make sure to enable the "Scatter" option in the Sunshine Settings if you want the Postprocess enabled.

    I hope this helps,
    Oren
     
  47. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    I'm afraid not. The scattering option is, in fact, activated in the inspector. As mentioned above, the shader error is related to the number of passes required.
     
  48. PolyVector

    PolyVector

    Joined:
    Dec 24, 2011
    Posts:
    765
    Strange, I haven't seen that happenbefore. If you could PM me a small project that reproduces the problem, I'll try and work out a solution for you.

    Cheers,
    Oren
     
  49. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Thanks for the offer Oren, I suspect this is something to do with our machine (Windows 7 / 5.3.4 / 980ti), rather than your asset; the asset runs perfectly fine on my home PC (Windows 10 / 5.3.4f1 / 970). This is not a gamebreaking problem for us at the moment, but I will consult you again if it does not work after testing on a fresh project.

    EDIT: It definitely was something to do with our project because I started running into the issue on my home PC and now Sunshine is "working", but I'm getting horrible banding artifacts (see attached) in the scene and game view.

    EDIT2: light bias, my mistake
     
    Last edited: Jul 3, 2016
  50. soxroxr

    soxroxr

    Joined:
    Jul 17, 2012
    Posts:
    60
    I would like to bring up again the asset "Time of Day" that JesseAlexander asked about in 2014.

    What I'm personally fighting with is volumetric scattering. You can set it up for day, or you can set it up for night, but there's a great chance those settings aren't gonna match, unless you want night to be super illuminated (from a distance) and you wish to use colorless light. I was aiming to use a slightly golden and slightly blue hue, but the color isn't as big a concern as the intensity.

    Edit:
    On section thought, it's highly possible that the volumetric scattering doesn't play well with eye adaptation at night, since everything is so dark, eye adaptation boosts light levels. Perhaps the issue isn't "Time of Day" at all. It's just very noticeable in conjunction with the day/night cycle.