Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

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

Discussion in 'Shaders' started by DaveHoskins, Apr 17, 2014.

  1. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    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.
     
  2. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Which fallback shader are you using for your shadows? The cutout one will require UVs.
     
  3. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    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.
     
  4. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    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.
     
  5. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    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.
     
    Last edited: Apr 17, 2014
  6. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    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/10...er-(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/10...er-(vert-frag)?p=724147&viewfull=1#post724147
     
  7. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    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.
     
  8. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    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.
     
    Last edited: Apr 17, 2014
  9. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    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?
    :confused:
     
  10. WhiskyJoe

    WhiskyJoe

    Joined:
    Aug 21, 2012
    Posts:
    143
    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. :)
     
  11. Farfarer

    Farfarer

    Joined:
    Aug 17, 2010
    Posts:
    2,249
    Well, your Diffuse fallback shader will need UVs.

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

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    No, it still complains if I comment out the line or put 'Fallback off'
     
  13. CodeMonke234

    CodeMonke234

    Joined:
    Oct 13, 2010
    Posts:
    181
    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
     
  14. DaveHoskins

    DaveHoskins

    Joined:
    Sep 9, 2013
    Posts:
    190
    I've put in a dummy set of common UVs and stopped the error messages for now.
    Ho-hum.