Search Unity

Need help with custom shader and receive shadow

Discussion in 'Shaders' started by ensiferum888, Aug 22, 2013.

  1. ensiferum888

    ensiferum888

    Joined:
    May 11, 2013
    Posts:
    317
    Hi everyone,

    It's been a while since I needed help, I guess I'm getting better but I'm facing an issue I just can't fix. I find shader language to be very hard to read and understand. I managed to mix an outline shader with the ATS Snow Suite snow bumped shader. So now I have dynamic snow on my buildings and if I select them I can toggle an outline around them.

    The issue I have is that the shader does not receive shadow. the object casts shadows and it looks great but if there's a tree nearby the shadow of the tree just cuts on the ground and does not appear on my building. I looked online for possible solutions, changing the fallback, using other pragma directives, nothing works. It either doesn't change anything or turns everything to pink.

    Can anyone take a look at my shader code and tell me if it's possible and what to add in order to receive shadows? http://pastebin.com/PfKCGvZR

    Bonus Question When I select a building I call a function on it that does:

    Code (csharp):
    1. highlight.a = 1f;
    2. MeshRenderer.material.SetColor("_OutlineColor", highLight);
    Doing this creates a new instance of the material which is fine. When I deselect, is there any way I can revert the material to the original and keep batching intact instead of keeping an (instance) of the same material?

    Let me know if it's not clear.

    Thank you!