Search Unity

[RELEASED] Super Fast Soft Shadows

Discussion in 'Works In Progress - Archive' started by Andy-Korth, Jun 5, 2015.

  1. _eternal

    _eternal

    Joined:
    Nov 25, 2014
    Posts:
    304
    Ah, you're right, I meant the former - mixed up my terminology. Got it working now. Thanks!
     
  2. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    No, lights in SFSS are arbitrary image masks provided by the user.

    Assuming that you did just have a simple radial light, you could use Physics2D.OverlapCircleAll or something similar to get the same functionality though.
     
  3. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Is the new version of SFSS(4.0) only available for Unity 5.5? I was eager to try the perspective mode but it seems my SFSS stays at version 3.12 after importing/downloading SFSS(also tried importing to a new project but the same result). My unity is version5.4.2.
     
  4. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Asset looks great, one of the best for 2D lighting. Just curious, I see that light can illuminate the edges of the objects a bit.. is this based on bumpmapping? Could you support normal mapped sprites so that the edges can be properly illuminated this way?

    Also I am wondering about how close you can push this to a kind of global illumination. You already have light and shadow. Is there maybe a way to get some radiosity going? Like, color bleed from nearby surfaces? Or to get light to actually 'reflect' off surfaces and hit other surfaces indirectly?
     
  5. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @noanoa SFSS 4.0 should work fine with Unity 5.4, but you'll have to import the package by hand. To do that, you'll need to have Unity 5.5 to download it. -_- Unity makes this even more hairy on our end. Every single minor version of Unity 5.x has required workarounds because they keep changing how shaders and the rendering works in subtle ways. Normally we develop with an older version of Unity, and test on the latest. It also means that every time we open the project we have to revert all of the updates that Unity automatically applies. We figured a major release of SFSS was good time to update to the latest Unity. Though since we only did it a week or so before release, it should still work just fine with the exception of the demo scenes being unusable in 5.4. Sorry for the bother. :-\

    @imaginaryhuman

    That's a feature of SFSS called light penetration. It's implemented by smoothing the near edge of the shadow mask. Unfortunately SFSS does not support normal mapping. To do that, we would need to rewrite SFSS to hook into Unity's multi-pass forward lighting, which is not currently possible anyway.

    However, it's possible to mix SFSS and Unity lighting in the same scene, but you cannot mix them on the same sprite/mesh. For instance, you could use normal maps and Unity lights on your foreground sprites while having them cast SFSS shadows onto the background sprites.
     
    noanoa likes this.
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,834
    Normal mapping is just a shader thing, all it means is you displace the texture coordinates in the fragment shader to read from the light buffer or whatever. Shouldn't be hard to add that.
     
  7. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    Hmm... It certainly wouldn't hurt to try a simple displacement. That's how they used to do it for old demo effects:


    Though those used a LUT for a single light that didn't have shadows in it. Since the displacement amount would have to be quite high, it's going to cause the shadows to distort a lot, and that might look quite bad in general.

    To calculate per pixel lighting accurately, you need the direction of the light to compare with the surface normal. After all of the lights are combined into a lightmap, it's no longer possible to determine individual light contributions or directions.
     
  8. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    Simple displacement from the unshadowed lightmap does sort of work.


    When shadows are added, it definitely breaks down (those dark creases are the distorted shadows). So not very useful in that case.


    Without having access to a scene normals buffer when generating the lightmap, we simply can't calculate the proper lighting. I'd still have to recommend people to mix and match the two.
     
  9. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    SFSS is almost working on X-Z plane on version4.0. Only the positions of shadows don't seem to follow lights. I'm no expert at all but with the perspective camera feature implemented now did it get easier to handle X-Z plane or is it a totally different thing?
     
  10. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    I've got my own 'normal' mapping going but obviously since I only want to sample normals once, I just lerp the direction toward the most important light. I fade out using lightmap luminosity. It's ok, it works for us but I'm set to see if I want to keep it. The shader source is so simple for the actual sprites (the easy part) or meshes, so anyone can sort of experiment.
     
  11. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @noanoa Sort of. In order to get perspective support working I had to solve some of the same problems as supporting non-XY planes. I thought it might be easy to get a nice generic solution for it before releasing 4.0, but it turned out to be harder than expected. I didn't want to delay the rest of the changes because of it. It's still on the TODO list though.
     
  12. noanoa

    noanoa

    Joined:
    Apr 17, 2014
    Posts:
    225
    Thanks for the reply! I always feel weird using XY plane on topdown2.5d games.
     
  13. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
    @slembcke2 Thanks for your response. I will keep using linear blending!

    Normal mapping would still be a very nice feature! I wonder if there could be some workaround that actually works... :rolleyes:
     
  14. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    Hi, I want do with my friends one game with the shadows very particular. In specific the shadows must be clean and hard. For example look this image in below (DeChirico) for understand the problem.




    The game is top-down like Zelda.
    Is it operable with this plugin? How? Thanks for answer!!!

    In addition is there a light like global directional light (all the scene is illuminated for a specific directional light)?
     
    Last edited: Feb 12, 2017
  15. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    Not quite the right sort of effect for SFSS where the shadows are cast strictly in 2D. The shadows would only be calculated along the ground plane only, and that is a *very* 3D scene. SFSS also doesn't do directional lights.

    However, what you've described is the exactly the ideal circumstances for Unity's built in 3D shadows. I would just go with those honestly.
     
  16. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    Instead, the shadows in this manner (see picture), can they be created with this toool?

     
    Last edited: Feb 14, 2017
  17. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    No, those are still shadows of 3D objects. SFSS's support for 3D scenes is very limited. Unity already provides pretty good shadows for doing 3D. SFSS was created since Unity doesn't support shadows for 2D scenes.
     
  18. FeboGamedeveloper

    FeboGamedeveloper

    Joined:
    Feb 2, 2014
    Posts:
    47
    The problem is that these objects are sprites!!! How can I do?
     
  19. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    You either need less detailed shadows, or you need to draw them by hand. In the screenshots you shared above, there is no way to extract the 3D shape of those objects in order cast a shadow with a different shape, and onto other objects in 3D space.

    Your best bet if you want to do something automatic, is to have all of your objects be 2D cutouts and use the alpha mask to skew a shadow onto the ground. Something like this:



    Even though it's faked, the shadow is still effectively 3D in nature, and SFSS only handles shadows that are strictly 2D.
     
  20. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    You need to have 3d models of the "things" casting shadows. Sprites will not do unless you're wanting to create the shadows by hand also. You need 3d models and textures.
     
  21. Ennacrima

    Ennacrima

    Joined:
    Feb 15, 2017
    Posts:
    1
    Hello, I'm the artist of the screenshot posted above. I'm not sure if I've understood how the plugin works, so I would show you a raw idea, to know if that's how it's supposed to work.

    My idea with that graphic is to create a simple sprite, a square, underneat the complex rock sprite.
    The shadow would apply on the square, and the casted shadow would result into a simple geometric shadow, but that would be enough for us. We will probably not need complex and precise shadows for our project.

    If you look at this sample, can you confirm me that this way it would work?
    If not, what knowledge of this plugin am I missing?





    Thank you for your time. ^ ^
     
  22. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    That you might be able to do yes. Check out this demo for a faked 3D example: http://files.slembcke.net/temp/SFSS_Forest/

    Basically the light/shadows are only calculated for the ground, and the shadows are cast from polygons of just the bottom of the object where they meet the ground. Objects that stand upright can receive shadows, but the light is based on the ground below it, and the height is ignored.
     
  23. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
    Hi, i came up an iuuse with multiple camera.
    when i use pro camera plug-in to achieve parallax effect with SFSS's light suport
    http://www.procamera2d.com/user-guide/extension-parallax/

    i need to attach SFRenderer to each parallax camera. but that will cause each light render multiple time.

    any idea on how to fix it?

    thanks.
     
  24. OldKing_Wang

    OldKing_Wang

    Joined:
    Jan 25, 2015
    Posts:
    46
  25. kosukito

    kosukito

    Joined:
    Sep 6, 2014
    Posts:
    8
    Hi i just bought the asset and works great, just wondering tough if there is a way to get the lenght of the shadows shorter. i want to try to make a sun, not a sunset son... a 1pm sun, and kinda want a hard shadow of the polygon.
    kinda get it with the radious or the penetration light parameters but, it tooks too much cpu and it is so diffuse.
    thank you
     
  26. _Jens

    _Jens

    Joined:
    Apr 26, 2015
    Posts:
    5
    Hi, do you have any plans to release this faked 3D demo project with the package?
     
  27. vovo801

    vovo801

    Joined:
    Feb 3, 2015
    Posts:
    18
    Hi! Very nice asset!
    I wanted to ask this newbie question: I want to have a game object in the foreground that does not receive lights or some of the lights. The use case scenario is: My player shoots projectiles that have SFLight component on them. There are some objects in the foreground. When the projectile with the light passes behind this foreground object, the light still shines through and gets rendered on top of the object. But at the same time I`d like this game object to receive the same Ambient light color from the SFRenderer. Is it possible to make something like this? A game object that is affected by the ambient light and not affected by all the other light? Am I missing something? Thank you!
     
  28. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @Assfur Rendering using multiple cameras like that will likely never work with SFSS. Sorry. :-\ The camera callbacks in Unity are camera specific, and on top of that SFSS needs to know matrices used by the camera in order to reproject the shadows. It's also pretty easy to to parallax scrolling without needing multiple cameras at all.

    @kosukito Not really unfortunately. We've experimented with directional lights like that with finite shadows, but there isn't really a good way to deal with blending the shadows together without completely disabling the penumbras.

    @_Jens The only thing that's really different about it compared to the included forest example is the art, and I don't have the rights to redistribute that.

    @vovo801 Yup. Check the sliders on your material. There is one that controls the strength of the shadows, and one that controls the strength of the lighting/ambient mix.
     
  29. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    I have a project that uses baked lighting but I want to generate shadows for the moving objects. As such I do not want any lighting (our scene is all unlit with baked lighting) can I generate shadows without illuminating objects? I'd like to add 3 light sources which would match our baked light positions etc and then generate just the shadows - can this asset do that?

    I'm wanting a fast solution for mobile and this looks like it could work.
     
  30. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
    For some reason this seems to be broken on Unity 5.6. Shadows no more work.

    Could you please fix this as soon as possible? Thank you!
     
    Shodan0101 likes this.
  31. XxPleYxX

    XxPleYxX

    Joined:
    Jul 26, 2011
    Posts:
    41
    Is this plugin compatible with PS4 and Xbox One?
     
  32. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @larku I don't know how that could work, sorry. Once your lights are blended together there isn't any way to separate them to apply shadows to just one of them without being able to re-render the lightmap on the fly. So if you are using baked lighting to get nice occlusion effects or multiple bounces, then there isn't much SSFS can do to help. Sorry. :-\

    @Haapavuo Yup. Backwards compatibility is broken with nearly every minor version of Unity. :( Fixes are incoming.

    @XxPleYxX I would be surprised if it didn't. Both of those platforms are similar to the DX11 renderer, and that works fine.
     
  33. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    Ok! Actually the last thing I needed to do was to test it on the DX9/11 renderers. Seems to work with no more specific fixes required. We are submitting a new version for the asset store, but in the mean time here are the relevant fixes.

    NOTE: These changes will *NOT* work on Unity 5.5.2 due to different Unity bugs. Writing shaders that work in Unity is a careful dance. Only apply these changes if you have upgraded to 5.6

    (Edit: These changes are for SFShadowMask.shader)

    The first change is a workaround for a new bug in the Metal shader output. We need to trick it into thinking we computed something or the opacity for each vertex will get filled with garbage. We ran into this bug a few versions back in the OpenGL output too. Without it you'll get nasty flickering shadows on Mac/iOS.
    Code (Cg):
    1. // Find this:
    2.           OUT.opacity = IN.properties[2];
    3. // Replace with this:
    4.           OUT.opacity = 1.00001*IN.properties[2];
    Next up, they changed the way rendering matrices are passed to shaders, and removed some of them. Basically, you have to write shaders that support instancing even if there is no benefit. Oh well. The Unity shader compiler will helpfully update the code to something that doesn't actually work.

    Code (Cg):
    1. // The original code looked like this:
    2.           float4 clipPosition = mul(UNITY_MATRIX_MVP, projected);
    3. // Unity 5.6 will have replaced it with something like this:
    4.           float4 clipPosition = unityObjectToClip(projected);
    5. // Replace whatever you have with this:
    6.           float4 clipPosition = mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, projected));
    Again, don't make this fix for earlier versions of Unity as there was a bug where UNITY_MATRIX_VP will be wrong if you set a custom projection matrix for a DrawMeshNow() call, which we do.
     
    Last edited: Apr 5, 2017
    gopejavi likes this.
  34. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    I don't think I explained myself well - my scene's lighting is baked, but I want to add shadows for moving objects that are not baked into the scene. I don't want to alter the current baked light/shadows, that will stay the same always (static parts of scene) but I want to cast shadows from some moving objects (all on a flat plane).
     
  35. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
  36. gopejavi

    gopejavi

    Joined:
    Apr 5, 2015
    Posts:
    2
    Hi! First, thank you for your great 2d lighting asset. I am very happy with it.

    I'm having also problems with Unity 5.6 final, shadows don't work (they used to work in 5.6 beta).
    Like: (empty project with just this asset imported)
    upload_2017-4-5_13-54-10.png

    I guess this is the same case @Haapavuo mentioned above? So should we just wait for a fix? If that's all it would be nice to know when wil be available, more or less (this week, next month...) so we can plan if continuing working in 5.6f or switching back to previous version of Unity (in order to publish new game updates).

    I thought the code substitution a couple of posts ago was a temporary solution but any file is specified (I think) so I got lost U^^ I could not find the lines in the SFSoftShadows\*.cs" files.

    Thanks in advance :)
     
  37. hippocoder

    hippocoder

    Digital Ape

    Joined:
    Apr 11, 2010
    Posts:
    29,723
    The shader code is in SFShadowMask.shader

    Would appreciate a final asset store version when it's done though as there's so many little edits now... from cookies to compatibility (we are on 5.6).

    Really need a proper update that's been verified your end with your own examples, it's becoming a little lost what ground truth is :)
     
    gopejavi likes this.
  38. gopejavi

    gopejavi

    Joined:
    Apr 5, 2015
    Posts:
    2
    @hippocoder Thanks man. I just missed that, maybe "inspired" by the "Code (CSharp):" title above the code lines to change. Also a search including files content, performed by Windows, didn't find the lines -maybe didn't check subfolders-, but they were there.

    After changing those lines the shadows are working again as expected. I made a day/night cycle with DOTween and this asset (changing positions, colors, of the SFlight...) with 2 lights, one representing the sun and other de moon. Just "orbiting" the camera, far away. Everything ok now.

    So I can continue with 5.6f. Thanks!

    PD These are also my first posts in the Unity forum, happy to be here ^^
     
    hippocoder likes this.
  39. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @larku Maybe I don't quite understand, but the only way you can have shadows is because a light gets blocked. If that lighting from multiple sources is baked, then it's not really possible to separate the different lights to figure out how much of each of them to block. I suppose with a few small edits, you could make SFSS output negative light values in the shadows instead of 0, but I don't think it's going to look that good. Unless it perfectly matches how your baked lighting was generated, it's going to look wrong. For sure it won't be able to apply any global illumination if that's one of the reasons you are using baked lighting.

    @hippocoder Whoops, thank you yes. It goes in SFShadowMask.shader.

    @kikwasar Sorry for the confusion. Glad you got it working.
     
    hippocoder likes this.
  40. larku

    larku

    Joined:
    Mar 14, 2013
    Posts:
    1,422
    Perhaps I'm just confused how this works.

    So I have a scene which is mostly comprised of static objects (a room with a table in the middle) the lighting for the room is baked and is 100% unlit - we don't use any lights in Unity.

    Now I have objects on the table that do move, I want these objects to cast shadows in realtime on to the plane of the table - we can 100% ignore any other lighting in the scene since it's baked and doesn't ever need to change.

    So I don't want any lighting or illumination at all, I only want to cast shadows from the moving items on the table onto the table plane.

    I have a working solution but it doesn't look great and is not performant. Currently I have some circle shadows that I attach to the objects and I scale them as they move around to imitate shadows.

    I want to just replace these circle shadows with something that looks more realistic and is more performant (if I have 3 shadows per object and 10 object I have over 30 drawcalls due to my shadows alone).

    Am I making any sense? (I'm a bit ignorant here sorry).
     
  41. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    We just submitted a new version of SFSS that supports Unity 5.6! It should be live in the store soon. If you've purchased SFSS and you need the update sooner, please let us know!
     
  42. Epsilon2

    Epsilon2

    Joined:
    Apr 24, 2016
    Posts:
    7
    Hello, I would like to get SFSS version for 5.6, please, since 4.0.0 does not make shadows at all :(

    I also put you a private message. Thank you!
     
  43. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Thanks Epsilon2, I have replied to your PM :)
     
  44. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Also new in version 4.0.1 is support for colored light cookies. If you have custom cookies that are set up as a single channel alpha texture, you may need to change it to an normal RGB texture. (default type). The cookies included with the project have been updated.
     
  45. Lechuza

    Lechuza

    Joined:
    Oct 3, 2014
    Posts:
    23
    Hi everyone!

    I already bought the asset, great work btw! I was just wondering if adding a normal map to SFSoftShadow.shader would be easy to do? Not to interact with SFLights but with regular unity 3d lights instead, trying to do a Toon shader with ramp texture. Ive been trying, but being new to surface shaders and shaders in general is taking me way to long.

    Not getting the same results when rewriting the SFSoftShadow.shader vertex and fragment shaders into a surface shader that I have with toon shading already set. And when I add the normal maps to SFSoftShadow.shader vertex and pixel shaders not sure how to get the light position information there.

    Any help or pointers would be greatly appreciated! Thanks in advance!

    Shader "Sprites/SFSoftSahdowToon"
    {
    Properties
    {
    //TOONY COLORS
    _Color ("Color", Color) = (0.5,0.5,0.5,1.0)
    _HColor ("Highlight Color", Color) = (0.6,0.6,0.6,1.0)
    _SColor ("Shadow Color", Color) = (0.3,0.3,0.3,1.0)

    //DIFFUSE
    _MainTex ("Main Texture (RGB)", 2D) = "white" {}

    //TOONY COLORS RAMP
    _RampThreshold ("Ramp Threshold", Range(0,1)) = 0.5
    _RampSmooth ("Ramp Smoothing", Range(0.001,1)) = 0.1

    //BUMP
    _BumpMap ("Normal map (RGB)", 2D) = "bump" {}
    _BumpScale ("Scale", Float) = 1.0

    //Alpha Testing
    _Cutoff ("Alpha cutoff", Range(0,1)) = 0.5

    _Tint ("Tint and Transparency", Color) = (1.0, 1.0, 1.0, 1.0)
    _SoftHardMix ("Unshadowed/Shadowed Mix", Range(0.0, 1.0)) = 0.0
    _AmbientOnlyMix ("Lit/Ambient Mix", Range(0.0, 1.0)) = 0.0
    _Glow ("Self Illumination", Color) = (0.0, 0.0, 0.0, 0.0)
    //Avoid compile error if the properties are ending with a drawer
    [HideInInspector] __dummy__ ("unused", Float) = 0
    }

    SubShader
    {
    Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"}
    Cull Off

    CGPROGRAM

    #pragma surface surf ToonyColorsCustom vertex:vert
    #pragma target 3.0

    //================================================================
    // SFSHADOWS VARIABLES
    float4x4 _SFProjection;
    float4 _SFAmbientLight;
    sampler2D _SFLightMap;
    sampler2D _SFLightMapWithShadows;
    float _SFExposure;
    float2 _SamplePosition;

    float _SoftHardMix;
    float _AmbientOnlyMix;
    float4 _Glow;
    float4 _Tint;

    //================================================================
    // VARIABLES
    fixed4 _Color;
    sampler2D _MainTex;
    sampler2D _BumpMap;
    half _BumpScale;
    fixed _Cutoff;

    struct Input
    {
    half2 uv_MainTex;
    half2 uv_BumpMap;
    float4 lightmapCoord;
    };

    //================================================================
    // CUSTOM LIGHTING
    //Lighting-related variables
    fixed4 _HColor;
    fixed4 _SColor;
    float _RampThreshold;
    float _RampSmooth;

    //Custom SurfaceOutput
    struct SurfaceOutputCustom
    {
    fixed3 Albedo;
    fixed3 Normal;
    fixed3 Emission;
    half Specular;
    fixed Gloss;
    fixed Alpha;
    float4 lightmapCoord : TEXCOORD1;
    };

    inline half4 LightingToonyColorsCustom (inout SurfaceOutputCustom s, half3 lightDir, half3 viewDir, half atten)
    {
    // lightCoords adjusted for perspective effects
    fixed3 l0 = tex2Dproj(_SFLightMap, UNITY_PROJ_COORD(s.lightmapCoord)).rgb;
    fixed3 l1 = tex2Dproj(_SFLightMapWithShadows, UNITY_PROJ_COORD(s.lightmapCoord)).rgb;
    fixed3 light = lerp(l0, l1, _SoftHardMix);

    s.Normal = normalize(s.Normal);
    fixed ndl = max(0, dot(s.Normal, lightDir));
    fixed3 ramp = smoothstep(_RampThreshold-_RampSmooth*0.5, _RampThreshold+_RampSmooth*0.5, ndl);
    #if !(POINT) && !(SPOT)
    ramp *= atten;
    #endif
    _SColor = lerp(_HColor, _SColor, _SColor.a); //Shadows intensity through alpha
    ramp = lerp(_SColor.rgb, _HColor.rgb, ramp);
    fixed4 c;
    c.rgb = s.Albedo * _LightColor0.rgb * ramp;
    c.a = s.Alpha;
    #if (POINT || SPOT)
    c.rgb *= atten;
    #endif
    // "light" already has ambient applied, _SFAmbientLight is only the ambient color.
    c.rgb *= (lerp(light, _SFAmbientLight, _AmbientOnlyMix) + _Glow) *_SFExposure * c.a;
    return c * _Tint;
    }

    void vert (inout appdata_full v, out Input o) {
    UNITY_INITIALIZE_OUTPUT(Input,o);

    float3 samplePosition = v.vertex.xyz;
    float4 lightmapCoord = mul(_SFProjection, mul(UNITY_MATRIX_MV, float4(samplePosition, 1.0)));
    o.lightmapCoord = lightmapCoord;
    }

    void surf(Input IN, inout SurfaceOutputCustom o)
    {
    fixed4 mainTex = tex2D(_MainTex, IN.uv_MainTex);

    o.Albedo = mainTex.rgb * _Color.rgb;
    o.Alpha = mainTex.a * _Color.a;

    //Cutout (Alpha Testing)
    clip (o.Alpha - _Cutoff);

    //Normal map
    half4 normalMap = tex2D(_BumpMap, IN.uv_BumpMap.xy);
    o.Normal = UnpackScaleNormal(normalMap, _BumpScale);
    o.lightmapCoord = IN.lightmapCoord;
    }

    ENDCG
    }

    Fallback "Diffuse"
    CustomEditor "TCP2_MaterialInspector_SG"
    }
     
    Last edited: Apr 12, 2017
  46. slembcke2

    slembcke2

    Joined:
    Jun 26, 2013
    Posts:
    270
    @Lechuza You don't have to do projection math exactly like SFSS does it. Unity provides a variable in surface shaders (i.screenPos I think?) that you can use to do projective texturing too. You need to divide by the w-coord or use tex2Dproj, but either will work. As for using the lighting value from SFSS, you can assign it to o.Emission. Then your lighting will be a mix of Unity and SFSS. I think that's what you are trying to do?
     
  47. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    SFSS 4.0.1 is in the asset store now! If you're on Unity 5.6, be sure to grab it right away.
     
  48. Lechuza

    Lechuza

    Joined:
    Oct 3, 2014
    Posts:
    23
    Thank you for the reply! It's working now, thanks again for the pointers!
     
  49. Haapavuo

    Haapavuo

    Joined:
    Sep 19, 2015
    Posts:
    97
    Thanks for the update!

    There seems to be a regression with some cookie textures though... I have previously used "ParticleCloudWhite" texture from "SFSoftShadows/SFSofShadowDemos/CaveScene/ParticleSystems/Textures" as a light cookie. However, since the lastest update, the cookie shows up all white. Previously it worked flawlessly.

    What do I have to do in order to get it working again? Thanks!
     
  50. Andy-Korth

    Andy-Korth

    Joined:
    Jun 7, 2013
    Posts:
    144
    Yep, tat's correct Haapavuo- you'll need to change your light cookies to RGBA instead of just being an alpha texture. A little more details here. It got a little buried.

    The cookies in the project should have updated themselves.. although I don't think ParticleCloudWhite was particularly intended to be a cookie. So you might want to duplicate it and make a cookie version that's RGBA.