Shader Modifier Tangent Space to View Space

I need to sample a custom normal map in a surface shader modifier, and I'm not sure how to convert my tangent space normal into a view space normal that I can assign to the _surface.normal property. My shader modifier looks like this:


#pragma arguments
texture2d myNormalMap; // tangent space normal map

#pragma body
constexpr sampler tileSampler(coord::normalized, address::clamp_to_edge, filter::linear);
float2 uv = /* calculate my uv coords */
float3 textureNormal = myNormalMap.sample(tileSampler, uv).xyz;
float3 tangentNormal = normalize(textureNormal * 2.0f - 1.0f);

_surface.normal = ??? * tangentNormal; /* how to convert to view space? */


I guess there must be a pre-computed matrix that does this conversion but I don't know what it's called.

Replies

If my 'view space' you mean 'world space', did you try multiplying by the inverse of the TBN.


And at the risk of enlisting semantics, I don't think you want to convert from/to...instead, you want to transform them out.