Posted By: jumpman
How to recalculate normals after a shader moves vertices - 09/13/18 17:45
Hello, how do I recalculate a model's normals after I move the vertices within the vertex shader? Is that possible?
-----VERTEX SHADER----- InPos += mul(offset14,matWorldInv ); // move vertex // Transform the vertex from object space to clip space: OutPos = mul(InPos, matWorldViewProj); // OutPos = mul(InPos, matWorldViewProj); // Transform the normal from object space to world space: OutNormal = normalize(mul(InNormal, matWorld));
////---- TOP LEFT -- CLOTH 0 RED float4 cloth1 = tex2Dlod(clothSampler5, float4(InTex.x*0.5f,InTex.y*0.5f,0,0) ); float3 offset1 = float3(cloth1.r*vertMove0.r,cloth1.r*vertMove0.g,cloth1.r*vertMove0.b); InPos += mul(offset1,matWorldInv ); // Transform the vertex from object space to clip space: OutPos = mul(InPos, matWorldViewProj); // OutPos = mul(InPos, matWorldViewProj); // Transform the normal from object space to world space: OutNormal = normalize(mul(InNormal, matWorld));