How can I make this custom shader support shadows?
Daniel Zeller wrote this brilliant low poly shader: https://github.com/danielzeller/Lowpoly-Water-Unity (a sample project can be downloaded from that link), and I have been trying to have this shader additionally support shadows but to no avail. I have so far tried adding:
Tags {"Queue"="Transparent" "LightMode" = "ForwardBase"}
#pragma multi_compile_fwdadd_fullshadows
#include "Lighting.cginc"
#include "AutoLight.cginc"
in struct v2f {}:
LIGHTING_COORDS(9,10)
in v2f vert() {}:
TRANSFER_VERTEX_TO_FRAGMENT(o);
and in half4 frag() {}:
float attenuation = LIGHT_ATTENUATION(i);
If anyone could please give me any help with this it would be much appreciated!
Thanks!
Answer by Namey5 · Oct 16, 2016 at 01:28 AM
Objects in the Transparent Queue (almost always) cannot receive shadows due to the way they are rendered. The only real way you could have a transparent object receive shadows would be to have it use a GrabPass, which is not guaranteed to work, be efficient or produce an outcome without problems of its own.
I have been trying to change this to be in a different Queue to transparent, and then add all of the shadow things, but it doesn't seem to work and I get strange results. How can I change the Queue and still have the shader function in the same way?
That's the thing, you really can't. Transparency will only work properly if rendered in a particular order, and due to the way Unity handles transparency and shadows you can't have faultless transparency and shadows without some trickery.
Right, I don't actually want the water to be transparent in any way, I'd prefer it to be opaque, so is there a way of doing this so that the water becomes opaque and it supports shadows?
Your answer
![](https://koobas.hobune.stream/wayback/20220612094711im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Geometry shader double sided leaf, shadows projected on both sides. 0 Answers
Vert/frag shader not receiving shadow despite all relevant code being present 1 Answer
Add hard shadows to a Toon Shader 0 Answers
Shadows on alpha clipping/vertex offset shaders misaligned when using screen space texture 0 Answers
Among Us Masking (RGB) Question 0 Answers