UnityFurURP icon indicating copy to clipboard operation
UnityFurURP copied to clipboard

No shadows

Open sssembler opened this issue 2 years ago • 7 comments

Is there a way to get shadows showing on this please? specifically I am using the shell method.

sssembler avatar Nov 25 '21 14:11 sssembler

Edited: Incorrect fix, see "Sunnhild" 's reply for correct fix:

Fur-URP12-ShadowIssue

I found a solution for directional light shadow:

in shell's Lit.hlsl

From Line 120 to Line 123 (the author's file)

```( this is line 119 )
float4 color = UniversalFragmentPBR(inputData, surfaceData);

ApplyRimLight(color.rgb, input.positionWS, viewDirWS, normalWS);
color.rgb += _AmbientColor;
```( this is line 124 )

Change it to:

```( this is line 119 )
Light mainLight = GetMainLight(TransformWorldToShadowCoord(input.positionWS));
float shadow = mainLight.distanceAttenuation * mainLight.shadowAttenuation;
float4 color = UniversalFragmentPBR(inputData, surfaceData);

color.rgb *= shadow;
ApplyRimLight(color.rgb, input.positionWS, viewDirWS, normalWS);
color.rgb += _AmbientColor;
```( this is line 127 )

Don't know if it is correct, but it works. ( I cannot write shader code ) Please feel free to correct me!

After adding the code, you will have this result:

Terrible self-shadow ( can be fixed ) image_003_0001

You can adjust the Shadow Extra Bias to avoid some self-shadow

image

No terrible self-shadow ( for this model, Shadow Extra Bias = -0.5) image_002_0001

The point light shadow works as expected ( no change needed) image_001_0001

By the way, this is the best shell fur shader I've ever seen.

jiaozi158 avatar Nov 30 '21 15:11 jiaozi158

amazing thank you - looks great

sssembler avatar Nov 30 '21 15:11 sssembler

Thank you for your comment!

If possible, could you let me know which shader and which version of Unity (and URP) you are using? This is because the shadow is handled in UniversalFragmentPBR() and you don't need to multiply it to color by yourself. I've got the result with shadows like the one in the README without changing the code.

hecomi avatar Nov 30 '21 15:11 hecomi

oh so I am on 2021.1.26f1 URP and I never had any shadows appear on the fur (using shell)

sssembler avatar Nov 30 '21 15:11 sssembler

Thank you! Something may have changed since 2021.x. I'll update the project at hand and look into it when I have time.

hecomi avatar Nov 30 '21 15:11 hecomi

Thank you! Something may have changed since 2021.x. I'll update the project at hand and look into it when I have time.

I found a similar issue on Unity Forum and they provide a solution. Link to the Thread (Unity Forum)

jiaozi158 avatar Nov 30 '21 20:11 jiaozi158

Thank you! Something may have changed since 2021.x. I'll update the project at hand and look into it when I have time.

I found a similar issue on Unity Forum and they provide a solution. Link to the Thread (Unity Forum)

This is the solution from your link, it works great!

replace #if defined(_MAIN_LIGHT_SHADOWS) && !defined(_RECEIVE_SHADOWS_OFF) by #if defined(_MAIN_LIGHT_SHADOWS) || defined(_MAIN_LIGHT_SHADOWS_CASCADE) || defined(_MAIN_LIGHT_SHADOWS_SCREEN) in all Lit hlsl files and it works 👍

Sunnhild avatar Apr 24 '22 05:04 Sunnhild