I’m writing a surface shader for the builtin RP that uses triplanar mapping to map a normal map. However, if I set o.Normal, my whole shader turns black with no errors. If I comment out the line o.Normal = normal; I see my texture as expected. I know my triplanar mapping code is correct as I’ve used it in other unlit shaders when manually calculating diffuse lighting
Surface shaders expect any value you set on o.Normal to be a tangent space normal. If your mesh doesn’t have tangents, setting the o.Normal will cause the mesh to go black like you’re seeing.
If you do have mesh tangents, that still won’t work properly as, again, its expecting tangent space normals and the triplanar function presumably outputs world space normals.
My triplanar article’s github repo has an example for how to approximately convert world space normals back to tangent space.
And on some geometry things can look wonky, as the above doesn’t use a true inverse matrix. This post has some example code for how to do it correctly, though it’s more expensive.
The best option would of course be if you could just make Surface Shaders not apply the tangent to world transform and use the o.Normal as a world normal, but that’s not something they support and considering they’re no longer going to make any new updates to Surface Shaders, and it’s a feature that was asked about for nearly a decade before that without them considering adding it, I would not expect this to be an option.