Shadow receivers don't need UVs, but it complains anyway.

Hi, I’ve been playing around with shadows, and have them cast onto a mesh that doesn’t have any UVs in it’s mesh data.
It complains that my shader doesn’t have UVs, and yet it renders the shadows perfectly.
It’s the ‘LIGHTING_COORDS(3,4)’ that forces the need, which is strange as the shadows render when all the UVs of the mesh are set to NULL!
Is there a way around this, because I would like to save memory and discard all the UV information in this instance.

Thanks,
Dave.

Which fallback shader are you using for your shadows? The cutout one will require UVs.

I’m fallback to Diffuse. It’s the macro LIGHT_ATTENUATION that wants ‘_ShadowCoord’ even though it clearly isn’t using it.
I have set ‘RealtimeOnly’ in the light inspector, so I don’t understand.

In your vertex shader, do you have
TRANSFER_VERTEX_TO_FRAG (o);
? Where o is the name of your v2f struct.

_ShadowCoord isn’t a lightmap UV, btw.

Thanks, for the quick response, yes I do have that.
What exactly is ‘_ShadowCoord’ ?

And ‘o’ is:
struct fragmentInput
{
float4 pos : SV_POSITION;
float3 location :TEXCOORD5;
LIGHTING_COORDS(3,4)
};
I need the ‘location’ value to be passed from the VERT to the FRAG.
I have read on these forums a few times that shadows need two UVs, but I have them here rendering without.

They’re not UVs, as such - just values that fill the texcoord semantics. But yes, it requires those to perform lookups into texture for lighting values (shadows and attentuation).

LIGHTING_COORDS specifies those two for you. It’s put in a macro because each light type requires different values.

Here’s kind of a quick précis;
http://forum.unity3d.com/threads/108612-Adding-shadows-to-custom-shader-(vert-frag)?p=719200&viewfull=1#post719200

And a full shader with base and add passes using that same thing;
http://forum.unity3d.com/threads/108612-Adding-shadows-to-custom-shader-(vert-frag)?p=724147&viewfull=1#post724147

OK thanks for the link. My original posts asks why I need UVs in the mesh, because when I set them to NULL I STILL get shadows on the mesh.
It complains I don’t have them by shoving warnings to the console, but it renders them fine. I wondered if there was a way around this, other than making a dummy set of UVs that can be shared, which seems silly.

LIGHTING_COORDS(x, x) defines the parameters you need to sample shadow/light maps and TRANSFER_VERTEX_TO_FRAGMENT(o) basically fills up those parameters with values that make sense for your situation (light type, cookies, etc).

When you call LIGHT_ATTENUATION(o) it samples the shadow and light maps with the previously defined parameters, of which _ShadowCoord is one.

Check out the AutoLight.cging file to see all the possibilities and what those macros exactly do in what situation.

*Farfarer beat me to it.

I have been looking at it, it will take a while to sort it out.

Why does it say I need UVs, when the mesh clearly doesn’t need UVs?
:face_with_spiral_eyes:

Perhaps you’re having something defined in your shader that relies on UVs but you don’t actually use it?

It’s hard to say, perhaps if you post the shader more can be said about it. :slight_smile:

Well, your Diffuse fallback shader will need UVs.

Does the error go away if you comment out that line?

No, it still complains if I comment out the line or put ‘Fallback off’

Shadow mapping clearly requires uv - maybe it is generating default uvs for you?

In the end, I do not think leaving them results in any savings

I’ve put in a dummy set of common UVs and stopped the error messages for now.
Ho-hum.