+1
À l'étude

Write to tangents

Benoit Alain il y a 9 ans mis à jour par Freya Holmér (Developer) il y a 9 ans 1

Hi !


We have a giant collection of meshes for our terrain, with uv1, uv2 and normals, and we managed to save some memory by estimating the tangents inside our shader.


We've been translating all our shaders from hand-written to Shader Forge, and it has been going very well in almost all cases, except the one that calculates the tangents manually.


In our code we have this:



#pragma surface surf BlinnPhong vertex:vert


struct Input { float2 tex1; };


void vert(inout appdata_full v, out Input o)

{

float3 p = step(0.1, v.normal), n = step(v.normal, -0.1);

v.tangent = float4( lerp(n.z-p.z, 1, p.y+n.y), 0, p.x-n.x, -1);

// other unrelated stuff

}

void surf (Input IN, inout SurfaceOutput o)

{

o.Normal = UnpackNormal(IN.tex1);

// other unrelated stuff

}


Would it be possible to have a "Tangents" input for the Normal Map Texture2D property box ?

Solution

Solution
À l'étude

There's currently no way of doing that, though there possibly should be a tangent input. It's rarely used, but it would indeed be useful. Right now you'd have to use a custom lighting shader if you want to use a custom tangent, which is possible, but a bit trickier to work with!

Solution
À l'étude

There's currently no way of doing that, though there possibly should be a tangent input. It's rarely used, but it would indeed be useful. Right now you'd have to use a custom lighting shader if you want to use a custom tangent, which is possible, but a bit trickier to work with!