Gamestudio Links
Zorro Links
Newest Posts
Lapsa's very own thread
by Lapsa. 06/08/26 22:41
Stooq now requires an API key
by VHX. 06/08/26 20:14
ZorroGPT
by TipmyPip. 06/06/26 12:36
Zorro 3.01 recoded MMI function issue
by TipmyPip. 06/04/26 05:44
SGT_FW
by Aku_Aku. 05/31/26 11:05
Issues resuming trades on Demo account
by Martin_HH. 05/22/26 13:31
XTB
by pr0logic. 05/18/26 12:27
AUM Magazine
Latest Screens
Dorifto samurai
Shadow 2
Rocker`s Revenge
Stug 3 Stormartillery
Who's Online Now
3 registered members (TipmyPip, Grant, 1 invisible), 3,415 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Seraphinang, Koti, curry, DeepxKalsi, Samed
19219 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
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 Offline OP
Serious User
txesmi  Offline 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
Code:
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 wheel

I tryed doing the inverse tangent space conversion into a shader in order to get a correctly compensated UVmap in tangent space but no luck frown.

Do someone want to try to convert the object space normal map to a correctly compensated tangent space normalmap? I would be happy laugh

Salud!

Last edited by txesmi; 05/17/13 21:22. Reason: resources added
Re: backing normals in 3dsmax [Re: txesmi] #422844
05/18/13 10:25
05/18/13 10:25
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
I got it!



Its time to solve the seams in an automatic process

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 Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
The normals transformation process

Code:
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();
	}
}


Re: backing normals in 3dsmax [Re: txesmi] #422926
05/20/13 15:17
05/20/13 15:17
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Although I'm no normalmapping guy thanks for sharing and the nice post/ presentation!


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: backing normals in 3dsmax [Re: Superku] #422937
05/21/13 07:46
05/21/13 07:46
Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
txesmi Offline OP
Serious User
txesmi  Offline OP
Serious User

Joined: Jun 2007
Posts: 1,337
Hiporope and its pain
Thanks! You are welcome :-D


Moderated by  aztec, Blink, HeelX 

Gamestudio download | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1