- Home /
ShadeSH9 always zero
I'm trying to write a per-pixel cel shader that uses ambient light. In my ForwardBase pass fragment shader I do
final.rgb += ShadeSH9(half4(UnityObjectToWorldNormal(f.normal), 1));
but whenever I disable all light except ambient in the scene, everything is drawn black. Everything in my scene uses my shader, and the lighting setup is a skybox with a sun directional light, and nothing else. I also tried to multiply instead of add in the line above and the result was black, so the ShadeSH9 call returns zero. The ambient intensity varies in script but is never zero. Any ideas what I could be doing wrong here?
I recommend you fly through the first few chapter of this
https://en.wikibooks.org/wiki/Cg_Program$$anonymous$$g/Unity
it wont take long. By the time you've done that you'll understand how to diagnose your blackness.
Given changes in shaders recently it wouldn't surprise me if you've simple omitted something you needed or not omitted something that was required to go. This is usually within the first few lines of shader setup.
I have the same issue. ShadeSH9 function returns zero if a skybox is selected as ambient source but it works with gradient and solid color as ambience.
did you solve it fafnir?
There is defenetly something fishy about the ShadeSH9, the documentation on it is sparse.
Answer by mptp · Jun 26, 2019 at 12:33 AM
Something I just found out as well: if you haven't got Tags { "LightMode" = "ForwardBase" }
at the beginning of your pass (before CGPROGRAM
), ShadeSH9 will return zero.
Answer by StrogaBeef · May 19, 2017 at 02:00 PM
I think I know! the ShadeSH9 can only sample a skybox is it is baked! try baking the scene and see if the ShadeSH9 picks up something
Your answer
Follow this Question
Related Questions
Toon shader for a cube - outline problem 2 Answers
How to Get Nice Thick Toon-Like Outlines On Non-Smooth Geometry? 1 Answer
Shader Assitance: Sprite Outline Color, Hidden Object -1 Answers
Exclude outline only, from fog, in custom toon shader. 1 Answer
Shader to use for background images in a 3D scene with variable lighting 0 Answers