Harald написалYou need to understand what the
Lighting Occlusion Shader
shader does to combine it with the Spine shader, not only concatenate both.The
Lighting Occlusion Shader
relies on the Stencil buffer being setup beforehand withlit
andoccluded
pixels, encoded by the stencil value4
when occluded. The shader basically just needs to do the following:if (stencil == occludedStencilValue) // occludedStencilValue == 4 renderOccluded else renderNormal
Unfortunately you cannot query the stencil value in a shader function, so you need two render passes with the corresponding stencil tests
stencil == 4
andstencil != 4
.
If you look at the shader code, it renders in two passes and uses a different stencil test to draw the first normal pass in the condition stencil not equal to 4:Pass { Stencil { Ref 4 Comp NotEqual } // code to draw the geometry normally follows below
and a second pass for drawing the same mesh in the occluded color:
Pass { Stencil { Ref 4 Comp Equal } // code to draw the geometry with occlusion color overlaid follows below
So what you need to do is:
1) Remove the existing Spine stencil code, as your asset works differently:Stencil { Ref[_StencilRef] Comp[_StencilComp] Pass Keep }
2) You just need a duplicated "Normal" pass of the Spine shader:
Pass { Name "Normal"
one with stencil test for "lit" and one for "occluded", as described above:
Pass { Name "Normal" Stencil { Ref 4 Comp NotEqual } // add Spine shader code to draw the geometry normally here, copy from Spine shader } Pass { Name "Normal Occluded" Stencil { Ref 4 Comp Equal } // add Spine shader code to draw the geometry with occlusion color overlaid here }
Harald... you are a god. EXCELLENT explanation and guidance. I floundered around a bit and eventually got it working. One thing I missed was adding a second _Color as it was being applied when rendering normally AND occluded.
Thanks so much again. If I knew you in person, and there wasn't a major epidemic going on, I'd buy you a beer.
Cheers!