|
|
|
|
|
|
|
|
SGT_FW
by Aku_Aku. 05/31/26 11:05
|
|
|
|
|
XTB
by pr0logic. 05/18/26 12:27
|
|
|
4 registered members (TipmyPip, Grant, 2 invisible),
3,454
guests, and 3
spiders. |
|
Key:
Admin,
Global Mod,
Mod
|
|
|
backing normals in 3dsmax
#422838
05/17/13 20:02
05/17/13 20:02
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
OP
Serious User
|
OP
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
hi, I have been fighting with backed normals for years and I finally found the way. I always got little errors on conplex meshes that never satisfy my spects any way. I think those problems came from the tangent space computation and the vertex normals ponderation differences between 3dsmax and 3dgs and I have never been able to solve, until now! Screen shots in 3dgs  The normals are backed in object space instead of tangent space, and they are converted to view/world space into the pixel shader. I guess it is a bit expensive and it only works for static meshes with any overlapped polygon in the UVmap.  3dsmax projection settings  the shader
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecViewDir;
float4 vecSunPos;
float4 vecSunDir;
float4 vecAmbient;
texture entSkin1;
texture entSkin2;
sampler Tex1Sampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
sampler Normal1Sampler = sampler_state { Texture = <entSkin2>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
void VS (
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float4 inTex: TEXCOORD0,
out float4 outPos: POSITION,
out float3 outWorld: TEXCOORD0,
out float2 outTex: TEXCOORD1 )
{
outPos = mul( inPos, matWorldViewProj );
outWorld = mul( inPos, matWorld ).xyz;
outTex = inTex.xy;
}
float4 PS (
in float4 inPos: POSITION,
in float3 inWorld: TEXCOORD0,
in float2 inTex: TEXCOORD1 ) : COLOR0
{
float4 ObjNormalTex = tex2D ( Normal1Sampler, inTex.xy );
float3 worldNormal = mul ( ( ObjNormalTex.rgb * 2.0f ) - 1.0f, (float3x3)matWorld );
float3 inDir1 = inWorld.xyz - vecSunPos.xyz;
float3 fReflect1 = normalize ( ( 2.0f * dot ( worldNormal, inDir1 ) * worldNormal ) - inDir1 );
float fSpecular1 = saturate ( dot ( fReflect1, vecViewDir.xyz ) ) * ObjNormalTex.a;
float fDiffuse1 = 0.5f + saturate ( dot ( normalize ( -inDir1 ), worldNormal.xyz ) ) * 0.5f;
float4 FinalColor = tex2D ( Tex1Sampler, inTex.xy );
FinalColor.rgb *= pow ( fDiffuse1, 1.4f );
FinalColor.rgb += pow(fSpecular1,8) * 0.3f;
return FinalColor;
}
technique BackedObjectSpaceNormal
{
pass p0
{
VertexShader = compile vs_2_0 VS();
PixelShader = compile ps_2_0 PS();
}
}
the wheelI tryed doing the inverse tangent space conversion into a shader in order to get a correctly compensated UVmap in tangent space but no luck  . Do someone want to try to convert the object space normal map to a correctly compensated tangent space normalmap? I would be happy  Salud!
Last edited by txesmi; 05/17/13 21:22. Reason: resources added
|
|
|
Re: backing normals in 3dsmax
[Re: txesmi]
#422924
05/20/13 14:15
05/20/13 14:15
|
Joined: Jun 2007
Posts: 1,337 Hiporope and its pain
txesmi
OP
Serious User
|
OP
Serious User
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
|
The normals transformation process
float3x3 matTangent;
float4x4 matWorldViewProj;
float4x4 matWorld;
texture entSkin1;
sampler TexSampler = sampler_state { Texture = <entSkin1>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
texture entSkin2;
sampler ObjNSampler = sampler_state { Texture = <entSkin2>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
texture mtlSkin1;
sampler SpecSampler = sampler_state { Texture = <mtlSkin1>; Mipfilter = Linear; Minfilter = Linear; Magfilter = Linear; };
void VS (
in float4 inPos: POSITION,
in float3 inNormal: NORMAL,
in float4 inTex: TEXCOORD0,
in float3 inTangent: TEXCOORD2,
out float4 outPos: POSITION,
out float3 outNormal: TEXCOORD0,
out float3 outWorld: TEXCOORD1,
out float2 outTex: TEXCOORD2,
out float3 outTangent: TEXCOORD3,
out float3 outBinormal: TEXCOORD4 )
{
outPos = float4 ( 2.0f * float2 ( inTex.x, 1.0f - inTex.y ) - 1, 0, 1.0f );
outNormal = mul( inNormal, (float3x3)matWorld );
outWorld = mul( inPos, matWorld ).xyz;
outTex = inTex.xy;
outTangent = mul( inTangent.xyz, (float3x3)matWorld );
outBinormal = cross ( outNormal, outTangent );
}
float4 PS (
in float4 inPos: POSITION,
in float3 inNormal: TEXCOORD0,
in float3 inWorld: TEXCOORD1,
in float2 inTex: TEXCOORD2,
in float3 inTangent: TEXCOORD3,
in float3 inBinormal : TEXCOORD4 ) : COLOR0
{
float specTex = tex2D ( SpecSampler, inTex.xy ).r;
// object to tangent space
float4 ObjNormalTex = tex2D ( ObjNSampler, inTex.xy );
float3 worldNormal = normalize ( mul ( ( ObjNormalTex.rgb * -2.0f ) + 1.0f, (float3x3)matWorld ) );
matTangent = transpose ( float3x3 ( normalize(inTangent), normalize(inBinormal), normalize(inNormal) ) );
float3 vNormalTangent = mul ( worldNormal, matTangent );
float4 FinalColor = tex2D ( TexSampler, inTex.xy );
FinalColor.rgb = 0.5f + ( vNormalTangent.xyz * 0.5f );
FinalColor.a = specTex;
return FinalColor;
}
technique BackedObjectSpaceNormal
{
pass p0
{
AlphaBlendEnable = False;
VertexShader = compile vs_3_0 VS();
PixelShader = compile ps_3_0 PS();
}
}
|
|
|
|