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

MTOON shader is not receiving shadows #110

Open
alacamda opened this issue Oct 6, 2024 · 6 comments
Open

MTOON shader is not receiving shadows #110

alacamda opened this issue Oct 6, 2024 · 6 comments
Labels
enhancement New feature or request

Comments

@alacamda
Copy link

alacamda commented Oct 6, 2024

MTOON shader is not receiving shadows from other objects blocking light

@fire fire added the bug Something isn't working label Oct 6, 2024
@lyuma
Copy link
Member

lyuma commented Oct 6, 2024

Hi @alacamda, thanks for opening an issue. Could you please provide some screenshots and reproduction steps and/or test scenes that reproduce this?

note that MToon is not a physically accurate rendering model, so the shadows will not function the same as with a conventional PBR shader.

also make sure you have a shade color assigned and a shade texture (can be set to the same texture if you use a shade color)

@alacamda
Copy link
Author

alacamda commented Oct 7, 2024

Here you can see a very simple test scene. In the first image, VRM character with Mtoon is not receiving any shadows from the wall. As you can see the shadows affect the car next to the character

image

In the second image, the character is out of the zone of influence of the shadow projected by the wall, but it looks the same as it looks in the first picture.

image

It is easy to reproduce, just create a simple scene with a directional light and a big cube projecting a shadow. The Shadow projected by the cube darkens areas of 3d meshes like the car, but not the VRM character that does not look darker

Hope this helps!

@lyuma
Copy link
Member

lyuma commented Oct 7, 2024

Would it be possible to show the inspector with the material opened, or perhaps share the VRM model you are using, if the license permits.

My guess is your model's Shade Color is very close to white, which will cause shadowing to have almost no effect. Note that for physically accurate shadowing, Shade Color should be black.

The other cause could be due to indirect lighting, or if the lighting is baked but does not have realtime shadowing enabled.

Here is a visual example of how shading works in VRM:

  1. The first screenshot is the material on the Alicia sample model
  2. The second screenshot shows what happens when Alicia's light attenuation is made physically accurate (using Shade Color = black). You will notice alicia's shadow is not black in this case.
  3. Finally, just to show the indirect lighting contribution, in the third screenshot, I set sky contribution to 0 on the WorldEnvironment.

vrm_shading_example

@alacamda
Copy link
Author

alacamda commented Oct 8, 2024

Thank you @lyuma for the quick reply!

I just tested with the Alicia model and I am getting the same effect. As you can see both Alicia's models look the same. I was expecting the Alicia model in the shadow (the one next to the car) to look darker (as you can see, the front part of the looks very dark as it is receiving shadow the cube wall). However, both Alicias look the same, they are not receiving any shadow from the cube wall.
image
This is with only one directional light in the scene.

Just to be clear, if I adjust the directional light to be darker (by reducing the energy) then of course the whole scene looks darker, including Alicia model (as you can see in the screenshot below), but still it's not receiving any shadow coming from the cube.

image

I tried also changing the shade color of Alicia to black, but then it appears always black. What I am looking for is for Alicia to appear darker only when affected by the shadow projected by another mesh (in this case, the wall cube)

Hope I explained this in a clear way, sorry but English is not my native language!

Thank you again for your support!

@lyuma
Copy link
Member

lyuma commented Oct 9, 2024

Okay I think I have a better idea of what you're looking for.

There are two things to try playing with. One is what is called the "Shadow Receive" rate. I realize that this slider defaults to 0.5, but maybe relatively ineffectual by default due to the sRGB curve (it will be effectively squared, so it really is closer to 0.25 rate). I would try moving this to 1.0 on your materials.

The other change you could try is to modify the shader as shown in the screenshot. Change the diffuse_output = line in the LIGHT_IS_DIRECTIONAL case to add a multiplication with lightAttentuation - This will allow it to go all the way down to black as in the PBR case, but just for shadows (since ATTENUATION in directional lights is only affected by shadowing).

godette_shadowing

I believe this is mostly what you want, but beware of self-shadowing as it may look odd. You can disable self-shadowing by setting your meshes to have "Cast Shadows" off, and then you may be able to play some layering tricks to still allow the VRM meshes to cast shadows on the ground, but I'm not so sure if this is actually possible. Anyway, here's how it could look with cast shadows off:
godette_disable_self_shadowing

Note that to accentuate the effect, I modified the WorldEnvironment to adjust sky contribution to 0. If you have sky contribution set higher or other GI, the shadows won't be pitch black but should include the ambient light, even with the above shader change. This is correct and should match PBR materials.

Hope this helps.

I don't currently plan to include the extra multiplication as a feature in MToon since it doesn't conform with the MToon spec, but if there is interest by more people, I could consider adding this feature.

@alacamda
Copy link
Author

alacamda commented Oct 9, 2024

Yes! That's exactly what I was looking for! Sorry to log it as a bug, I checked the shader code before opening the bug but couldn't find the solution! Thank you so much!

@lyuma lyuma added enhancement New feature or request and removed bug Something isn't working labels Oct 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants