Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No shadows #4

Open
sssembler opened this issue Nov 25, 2021 · 7 comments
Open

No shadows #4

sssembler opened this issue Nov 25, 2021 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@sssembler
Copy link

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

@jiaozi158
Copy link
Contributor

jiaozi158 commented Nov 30, 2021

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.

@sssembler
Copy link
Author

amazing thank you - looks great

@hecomi
Copy link
Owner

hecomi commented Nov 30, 2021

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.

@sssembler
Copy link
Author

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

@hecomi
Copy link
Owner

hecomi commented Nov 30, 2021

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 hecomi self-assigned this Nov 30, 2021
@hecomi hecomi added the bug Something isn't working label Nov 30, 2021
@jiaozi158
Copy link
Contributor

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)

@Sunnhild
Copy link

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 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants