Home Unity

how to get custom shaders to recieve shadows?

polycounter lvl 11
Offline / Send Message
wenglish polycounter lvl 11
hello

I am having difficulty finding information on how to use realtime shadows with my shaders. I found that they will cast shadows as long as I include a fallback shader, but they will still not receive them. this also seems to be sparsely documented...

thoughts?

Replies

  • Farfarer
    Offline / Send Message
    Farfarer polycounter lvl 17
    It's well documented in the forums.

    Diffuse has a fallback of vertex lit, which contains within it two passes; Shadow Caster and Shadow Receiver. These are the two passes that allow the shader to cast and receive shadows.

    To receive shadows in your own custom shader, use the macros/helpers defined for you in AutoLight.cginc...
    // Inside CGPROGRAM block.
    #include "AutoLight.cginc"
    
    ...
    
    // Inside v2f struct.
    LIGHTING_COORDS(4,5); // Where 4 and 5 are the next two available texcoords.
    
    // Inside vertex shader, just before return.
    TRANSFER_VERTEX_TO_FRAGMENT(o); // Where o is the output variables name.
    
    // Inside fragment shader.
    fixed atten = LIGHT_ATTENUATION(i); // Where i is the input variables name.
    

    Here's a full example shader...

    http://forum.unity3d.com/threads/198141-Lighting-using-tangent-vector-and-also-using-surface-shaders?p=1344367&viewfull=1#post1344367
Sign In or Register to comment.