Shadow and distance attenuation do not work in URP Unlit Graph (771097)

Hi!
I’m using Unity 2019.3.0f3 and URP 7.1.7
I’m trying to follow this tutorial:
https://blogs.unity3d.com/pt/2019/0…n-shader-graph-expanding-your-graphs-in-2019/

But the “mainLight.shadowAttenuation” and “mainLight.distanceAttenuation” always return white if using a “Unlit Shader” as Base. It works with a “PBR” shader but this is not what i need (since i need a fully controllable light model.

Is it a bug or there’s something new that is not documented about it?

2 Likes

The unlit master node was never really meant to support shadows. However I’m almost certain that you only need to add the following lines to support it:

#pragma multi_compile _ _MAIN_LIGHT_SHADOWS
#pragma multi_compile _ _MAIN_LIGHT_SHADOWS_CASCADE
2 Likes

So your tutorial is just wrong and there’s no way to use custom light model anyway?
I’ve added this to the mainlight.hlsl (the custom function file) but it’s not working too. Any other solution?

2 Likes

I don’t know yours but somehow my unlit shaders cast shadows in 2019.3.0f3 URP 7.1.6

Did you tested with 7.1.7?

no there is no package update in package manager.

You need to add multi_compile to .shader files. However seems like ShaderGraph now supports declaring keywords. So you can declare those by using the keyword mechanism instead: https://docs.unity3d.com/Packages/com.unity.shadergraph@7.1/manual/Keywords.html

Ideally you should not need to worry about declaring keywords for this. We can improve this quite a bit.

Hi. This is my shader graph and the mainlight.hlsl file. It’s yet not working and i’m getting this error:

Shader error in 'Shader Graphs/Base': invalid subscript 'shadowCoord' at /Vitor/Trabalho/Cogumelo/Projetos/Game2020/Game2020/Library/PackageCache/com.unity.render-pipelines.universal@7.1.7/Editor/ShaderGraph/Includes/Varyings.hlsl(118) (on d3d11)

What i’m doing wrong?

1 Like

use the lit graph instead and bypass the built in lighting function by muting its output.
then plug in your custom lighting into emissive:
https://medium.com/@larsbertram1/lwrp-and-custom-lighting-in-shader-graph-6a7c48008a1d

1 Like

That is exactly what I’m doing and what I want to avoid. This is terrible hackish. No way this must be the designed way to do it in a “professional” engine.

1 Like

That solution still only half works, as even when you set all the PRB parameters to 0 (URP 2019.3.0f3) you still don’t remove all of what PBR seems to do. So that trick which worked in LWRP doesn’t work in URP.

i justed had a quick look into the complied shader code: only one light loop survives the shader compiler which is the custom one. tested with urp 7.1.7.

Is that in specular or metallic mode? In metallic mode I can clearly see that the metallic lighting is surviving, but not in specular mode, can’t say anything about the compilers.

Also, this
https://www.youtube.com/watch?v=DOLE4nrK97g
presentation references the article at the top of this thread, but it’s more recent and shadows are quite clearly working on an unlit node so that might be worth looking into.

1 Like

you have to use specular mode.
metallic does not really exist. it is just an intermediate step which converts metallic to specular. and this step will never set spec to 0,0,0 rather than to a fixed spec value. so in this case some lighting code actually survives…

@phil_lira please dont leave us in the dark here.

I watched the video above to learn how to do custom lighting.

The resources for the video above are found here:
https://github.com/Unity-Technologies/ShaderGraph-Custom-Lighting

These steps do not work anymore. As @CogumeloSoft pointed out, you get an error. It seems you need to declare another keyword to make it work - REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR. If you do not define this keyword, then the Varyings struct does not contain shadowcoord interpolator. But there is no way to define keywords in the shadergraph?

The shader graph lets you add a ‘predefined’ keyword… For example, I enter this:
5615980--581908--upload_2020-3-22_20-20-7.png

But it still doesn’t seem to work.

How do we just get main light information, including shadows?

I still get the same error as him:

1 Like

I was able to get main light information + shadows using this code.

Works for me in 7.2.0 URP

5 Likes

you can wipe out all:
#if SHADOWS_SCREEN
7.2. does not support screen space shadows any more.

1 Like

Cool thank you for the tip!

That gives you shadows, but they’re low Rez and seem to disagree with the shadow Cascades

This worked for me, including part underneath about removing shadow screen etc