Gamestudio Links
Zorro Links
Newest Posts
Free Live Data for Zorro with Paper Trading?
by AbrahamR. 05/18/24 13:28
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
4 registered members (AndrewAMD, ozgur, AbrahamR, wdlmaster), 849 guests, and 7 spiders.
Key: Admin, Global Mod, Mod
Newest Members
Hanky27, firatv, wandaluciaia, Mega_Rod, EternallyCurious
19051 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 1 of 2 1 2
Normalmap flip problem #167110
11/13/07 11:53
11/13/07 11:53
Joined: Dec 2005
Posts: 57
Brazil
P
pesseba Offline OP
Junior Member
pesseba  Offline OP
Junior Member
P

Joined: Dec 2005
Posts: 57
Brazil
Hii...
I'm problem with a normalmap code 1.0 from wiki page
My model is mapped both sides with the same part of texture (mirrored).
But the light inside it inverts the normalmap... why??

[image]http://www.cjb.net/images.html?b212e.jpg[/image]
[img]http://images.cjb.net/b212e.jpg[/img]

I already tried to edit the normals on my model, but the problem persists. Does somebody have another normalmap code for 1.0 shader?

Thanks...

Re: Normalmap flip problem [Re: pesseba] #167111
11/14/07 15:11
11/14/07 15:11
Joined: Dec 2005
Posts: 57
Brazil
P
pesseba Offline OP
Junior Member
pesseba  Offline OP
Junior Member
P

Joined: Dec 2005
Posts: 57
Brazil
Hello... I'm not a shader expert... but I was trying to change this code and I think the normal calculator is wrong... (I got it from wiki)

Code:
  /***********************************************************************************************
/ Global Variables:
/***********************************************************************************************/
// Tweakables:
static const float AmbientIntensity = 1.0f; // The intensity of the ambient light.
static const float DiffuseIntensity = 1.0f; // The intensity of the diffuse light.
static const float SpecularIntensity = 1.0f; // The intensity of the specular light.
static const float SpecularPower = 8.0f; // The specular power. Used as 'glossyness' factor.
static const float4 SunColor = {0.9f, 0.9f, 0.5f, 1.0f}; // Color vector of the sunlight.

// Application fed data:
const float4x4 matWorldViewProj; // World*view*projection matrix.
const float4x4 matWorld; // World matrix.
const float4 vecAmbient; // Ambient color.
const float4 vecSunDir; // The sun direction vector.
const float4 vecViewPos; // View position.

texture entSkin1; // Color map.
sampler ColorMapSampler = sampler_state // Color map sampler.
{
Texture = <entSkin1>;
AddressU = Clamp;
AddressV = Clamp;
};

texture entSkin2; // Normal map.
sampler NormalMapSampler = sampler_state // Normal map sampler.
{
Texture = <entSkin2>;
AddressU = Clamp;
AddressV = Clamp;
};


/***********************************************************************************************
/ Vertex Shader:
/***********************************************************************************************/
void NormalMapVS( in float4 InPos : POSITION,
in float3 InNormal : NORMAL,
in float2 InTex : TEXCOORD0,
in float3 InTangent : TEXCOORD1,

out float4 OutPos : POSITION,
out float2 OutTex : TEXCOORD0,
out float3 OutViewDir: TEXCOORD1,
out float3 OutSunDir: TEXCOORD2)
{
// Transform the vertex from object space to clip space:
OutPos = mul(InPos, matWorldViewProj);

// Pass the texture coordinate to the pixel shader:
OutTex = InTex;

// Compute 3x3 matrix to transform from world space to tangent space:
half3x3 worldToTangentSpace;
worldToTangentSpace[0] = mul(InTangent, matWorld);
worldToTangentSpace[1] = mul(cross(InTangent, InNormal), matWorld);
worldToTangentSpace[2] = mul(InNormal, matWorld);

// Calculate the view direction vector in tangent space:
OutViewDir = normalize(mul(worldToTangentSpace, vecViewPos - mul(InPos, matWorld)));

// Calculate the light direction vector in tangent space:
OutSunDir = normalize(mul(worldToTangentSpace, -vecSunDir));
}


/***********************************************************************************************
/ Pixel Shader:
/***********************************************************************************************/
float4 NormalMapPS( in float2 InTex : TEXCOORD0,
in float3 InViewDir : TEXCOORD1,
in float3 InSunDir : TEXCOORD2) : COLOR
{
// Read the normal from the normal map and convert from [0..1] to [-1..1] range
float3 BumpNormal = 2 * tex2D(NormalMapSampler, InTex) - 1;

// Calculate the ambient term:
float4 Ambient = AmbientIntensity * vecAmbient;

// Calculate the diffuse term:
float4 Diffuse = DiffuseIntensity * saturate(dot(InSunDir, BumpNormal));
Diffuse *= SunColor;

// Calculate the reflection vector:
float3 R = normalize(2 * dot(BumpNormal, InSunDir) * BumpNormal - InSunDir);

// Calculate the specular term:
InViewDir = normalize(InViewDir);
float Specular = pow(saturate(dot(R, InViewDir)), SpecularPower) * SpecularIntensity;

// Fetch the pixel color from the color map:
float4 Color = tex2D(ColorMapSampler, InTex);

// Calculate final color:
return (Ambient + Diffuse + Specular) * Color;
}

/***********************************************************************************************
/ Technique:
/***********************************************************************************************/
technique SpecularTechnique
{
pass P0
{
VertexShader = compile vs_2_0 NormalMapVS();
PixelShader = compile ps_2_0 NormalMapPS();
}
}



The normals addition of vertex and pixel doesn't work on mirroed faces...

Somebody... HELP!

Re: Normalmap flip problem [Re: pesseba] #167112
11/14/07 15:45
11/14/07 15:45
Joined: Dec 2005
Posts: 57
Brazil
P
pesseba Offline OP
Junior Member
pesseba  Offline OP
Junior Member
P

Joined: Dec 2005
Posts: 57
Brazil
I was talking to a friend "shaderman".... He explained me what is happing..
The problem is the Tangent value from 3DGS isn't a float4 but a float3 ....

So... this

Code:
 
void CreateTangents(float3 inNormal,float3 inTangent)
{
matTangent[0] = DoPos(inTangent);
matTangent[1] = DoPos(cross(inTangent,inNormal)); // binormal
matTangent[2] = DoPos(inNormal);
}



Should be something like this

Code:
 
void CreateTangents(float3 inNormal,float3 inTangent)
{
matTangent[0] = DoPos(inTangent);
matTangent[1] = DoPos(cross(inTangent.xyz,inNormal)) * inTangent.w; //binormal
matTangent[2] = DoPos(inNormal);
}



Is this possible to correct the previous posted code?
Thanks....

Re: Normalmap flip problem [Re: pesseba] #167113
11/14/07 19:56
11/14/07 19:56
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
I'm not sure what your friend "shaderman" is talking about.. tangents and normals are always float3 (they are direction vectors)..what would the fourth component be? Usually only position vectors are float4.

As far as the mirrored problem goes, this is common problem...you may want to adjust your mesh a bit to make sure that the vertices are welded at the seams, and try breaking the model and rewelding.

Also try searching the web for info on mirrored normal maps...there can be a number of issues causing this.

If this doesn't work, there may actually be something wrong with the tangents that A6 calculates--I'm pretty sure there is as I get better results when I calculate them myself using a dll. However I thought this was fixed in the latest versions..


Sphere Engine--the premier A6 graphics plugin.
Re: Normalmap flip problem [Re: Matt_Aufderheide] #167114
11/14/07 21:43
11/14/07 21:43
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
doesn't the fourth component contain the length of the vector?

Re: Normalmap flip problem [Re: Joey] #167115
11/15/07 02:42
11/15/07 02:42
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

doesn't the fourth component contain the length of the vector?




No: Tangents and normals are normalized vectors (length of one). Anyway the length of a direction vector can be calculated from the xyz component..the length calculation is trivial so there is no reason in most cases to precalculate it.


Sphere Engine--the premier A6 graphics plugin.
Re: Normalmap flip problem [Re: Matt_Aufderheide] #167116
11/15/07 03:08
11/15/07 03:08
Joined: May 2002
Posts: 7,441
ventilator Offline
Senior Expert
ventilator  Offline
Senior Expert

Joined: May 2002
Posts: 7,441
in a7 the fourth component of the tangent contains the handedness of the bitangent. previously this information wasn't available and so mirrored uvs were problematic.

Re: Normalmap flip problem [Re: ventilator] #167117
11/15/07 03:13
11/15/07 03:13
Joined: Dec 2003
Posts: 1,097
Maryland, USA
Steempipe Offline
Serious User
Steempipe  Offline
Serious User

Joined: Dec 2003
Posts: 1,097
Maryland, USA
Quote:

in a7 the fourth component of the tangent contains the handedness of the binormal. previously this information wasn't available and so mirrored uvs were problematic.




I have used the <cross(t, n) * t.w> and it has solved a couple of ongoing headaches I have had.

Re: Normalmap flip problem [Re: ventilator] #167118
11/15/07 07:03
11/15/07 07:03
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Quote:

in a7 the fourth component of the tangent contains the handedness of the bitangent. previously this information wasn't available and so mirrored uvs were problematic.




Oh, this is interesting.. I stand corrected


Sphere Engine--the premier A6 graphics plugin.
Re: Normalmap flip problem [Re: Matt_Aufderheide] #167119
11/15/07 19:59
11/15/07 19:59
Joined: Dec 2005
Posts: 57
Brazil
P
pesseba Offline OP
Junior Member
pesseba  Offline OP
Junior Member
P

Joined: Dec 2005
Posts: 57
Brazil
Yes Steempipe... it was I would like to listen. But could you explain better your instruction for acknex parameters? I'm not a shader expert...

Quote:

<cross(t, n) * t.w>




And Matt_Aufderheide, Could you post the dll that you talk about, please? I'm working with A6 yet...

Thanks everybody!

Page 1 of 2 1 2

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | 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