1 registered members (degenerate_762),
1,098
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: How to recalculate normals after a shader moves vertices
[Re: Superku]
#474219
09/30/18 23:03
09/30/18 23:03
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
How do you approximate normals after moving them in the XYZ directions? (btw how are you rotating vertices?! ) Here is a small version of what Im doing now:
-----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));
Last edited by jumpman; 09/30/18 23:08.
|
|
|
Re: How to recalculate normals after a shader moves vertices
[Re: Superku]
#474264
10/02/18 16:21
10/02/18 16:21
|
Joined: Apr 2002
Posts: 1,246 ny
jumpman
OP
Serious User
|
OP
Serious User
Joined: Apr 2002
Posts: 1,246
ny
|
Hey superku, I forgot to add the vertex movement part based on texture. This uses tex2dlod, which is a texture fetch within the vertex shader. Wherever there is color information, these areas vertices will be moved:
////---- 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));
As you can see, vertices are moved in the cardinal directions
|
|
|
|