normal mapping issues (NOOB)

Odog87

06-09-2007 18:59:06

I did the tutorial on the ofusion site for making a basic normal map shader. Every thing looks fine until I rotate the object. It looks like the light rotates with the object, for example:

A tire will always have the specular highlights on the same vertices's no matter what the rotation is, so it looks like a white spot is rotating around the wheel when it moves.

What needs to be done to fix this?

Please keep in mind I am a modeler, and not much of a programmer (simple explanations preferred)

Thanks :D

Lioric

08-09-2007 18:56:12

Have you enabled the "Tangent Generation" in the Object properties panel?

Odog87

10-09-2007 14:13:37

Yes I did, but that still doesn't change any thing.

Odog87

10-09-2007 14:26:58

Just so you understand what I mean by my problem...

the correct lighting...


the incorrect lighting (all that I have done is rotate the switch)


Again I did not move the light (the battery and bulb are still lit correctly). It looks like the lighting information is static. If I were to use "reset x-form" tool, I would get correct lighting for this angle.

Odog87

10-09-2007 14:31:35

Here is the Pixle shader that I used (should be like the tutorial)


struct PS_INPUT_STRUCT
{
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

struct PS_OUTPUT_STRUCT
{
float4 color0: COLOR0;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: PS_INPUT_STRUCT, derived from the output of
//** the associated vertex shader
//** Returns: PS_OUTPUT_STRUCT
//**---------------------------------------------------------
PS_OUTPUT_STRUCT main( PS_INPUT_STRUCT psInStruct,
uniform float4 specular,
uniform float Ka,
uniform float Kd,
uniform float Ks,
uniform float specular_power,
uniform float bumpiness,
uniform float4 ambient,
uniform float4 diffuse,
uniform sampler base_map,
uniform sampler bump_map)
{
PS_OUTPUT_STRUCT psOutStruct; //** Declare the output struct

//**------------------------------------------------------
//** Retreive the base color and bump components from the
//** respective textures, based on the passed bump coords.
//**------------------------------------------------------
float3 base = tex2D( base_map, psInStruct.bump_map );
float3 bump = tex2D( bump_map, psInStruct.bump_map );

//**----------------------------------------------------
//** Normalize the passed vectors from the vertex shader
//**----------------------------------------------------
float3 normalized_light_vector = normalize( psInStruct.light_vector );
float3 normalized_half_angle = normalize( psInStruct.half_angle );

//**--------------------------------------------------------
//** "Smooth out" the bump based on the bumpiness parameter.
//** This is simply a linear interpolation between a "flat"
//** normal and a "bumped" normal. Note that this "flat"
//** normal is based on the texture space coordinate basis.
//**--------------------------------------------------------
float3 smooth = { 0.5f, 0.5f, 1.0f };
bump = lerp( smooth, bump, bumpiness );
bump = normalize( ( bump * 2.0f ) - 1.0f );

//**---------------------------------------------------------
//** These dot products are used for the lighting model
//** equations. The surface normal dotted with the light
//** vector is denoted by n_dot_l. The normal vector
//** dotted with the half angle vector is denoted by n_dot_h.
//**---------------------------------------------------------
float4 n_dot_l = dot( bump, normalized_light_vector );
float4 n_dot_h = dot( bump, normalized_half_angle );

//**--------------------------------------
//** Calculate the resulting pixel color,
//** based on our lighting model.
//** Ambient + Diffuse + Specular
//**--------------------------------------
psOutStruct.color0.rgb =
( base * ambient * Ka ) +
( base * diffuse * Kd * max( 0.0f, n_dot_l ) ) +
( specular * Ks * pow( max( 0.0f, n_dot_h ), specular_power ) );
psOutStruct.color0.a = 1.0f; //** Set the alpha component manually

return psOutStruct; //** Return the resulting output struct
}


Here is my Vertex shader (again should be like the tutorial)

struct VS_INPUT_STRUCT
{
float4 position: POSITION;
float3 normal: NORMAL;
float2 texcoord0: TEXCOORD0;
float3 tangent: TEXCOORD1;
};

struct VS_OUTPUT_STRUCT
{
float4 position: POSITION;
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};

//**---------------------------------------------------------
//** Function: main
//** Description: Declare the main entry point for the shader
//** Input: VS_INPUT_STRUCT, derived from the stream
//** mapping parameters defined in the workspace
//** Returns: VS_OUTPUT_STRUCT
//**---------------------------------------------------------
VS_OUTPUT_STRUCT main( VS_INPUT_STRUCT vsInStruct,
uniform float4x4 view_proj_matrix,
uniform float4 light_position,
uniform float4 eye_position,
uniform float4x4 inv_view_matrix )
{
VS_OUTPUT_STRUCT vsOutStruct; //** Declare the output struct

//**-----------------------------------------------------------
//** Calculate the pixel position using the perspective matrix.
//**-----------------------------------------------------------
vsOutStruct.position = mul( view_proj_matrix, vsInStruct.position );

//**----------------------------------------------
//** Pass the bump and base texture coords through
//**----------------------------------------------
vsOutStruct.bump_map = vsInStruct.texcoord0;

//**----------------------------------------------
//** Calculate the Binormal vector
//**----------------------------------------------
float3 binormal = cross(vsInStruct.tangent, vsInStruct.normal);

//**--------------------------------------------
//** Calculate the light vector in object space,
//** and then transform it into texture space.
//**--------------------------------------------
float3 temp_light_position = mul( inv_view_matrix, light_position );
float3 temp_light_vector = temp_light_position - vsInStruct.position;
vsOutStruct.light_vector.x = dot( temp_light_vector, vsInStruct.tangent );
vsOutStruct.light_vector.y = dot( temp_light_vector, binormal );
vsOutStruct.light_vector.z = dot( temp_light_vector, vsInStruct.normal );

//**-------------------------------------------
//** Calculate the view vector in object space,
//** and then transform it into texture space.
//**-------------------------------------------
float3 temp_eye_position = mul( inv_view_matrix, eye_position );
float3 temp_view_vector = temp_eye_position - vsInStruct.position;
float3 temp_view_vector2;
temp_view_vector2.x = dot( temp_view_vector, vsInStruct.tangent );
temp_view_vector2.y = dot( temp_view_vector, binormal );
temp_view_vector2.z = dot( temp_view_vector, vsInStruct.normal );

//**-------------------------
//** Calculate the half angle
//**-------------------------
vsOutStruct.half_angle = vsOutStruct.light_vector + temp_view_vector2;

return vsOutStruct; //** Return the resulting output struct
}

Odog87

12-09-2007 17:04:27

Does any one have any idea on this?

Note: I have upgraded to oFusion 1.8.96 and used the specular bump shader that comes with it. The problem still exists like in the pictures above

Lioric

13-09-2007 16:31:55

Make sure the tangent coords are generated in the texture channel 1 (not 0)

Are you using multiple textures on the objects?

Is the correct light position parameter selected in the shader (light position in object space)?

Odog87

13-09-2007 21:47:35

I have all the settings matched to what is in the tutorial on the ofusion website.

How do I check the tangent texture channel. Is that in the shader code, or is that in Max?

Odog87

18-09-2007 19:11:14

Again How do I check where the tangent coordinates are being generated? All I have in the ofusion is a single check box that says generate texture vectors.

Evak

18-09-2007 19:25:59

In the shader source above, these are the streams in your shader code:

struct VS_INPUT_STRUCT
{
float4 position: POSITION;
float3 normal: NORMAL;
float2 texcoord0: TEXCOORD0;
float3 tangent: TEXCOORD1;
};

struct VS_OUTPUT_STRUCT
{
float4 position: POSITION;
float2 bump_map: TEXCOORD0;
float3 light_vector: TEXCOORD1;
float3 half_angle: TEXCOORD2;
};


so you have your tangents in texcoord1 and your texture coordinates streaming in texcoord0 which in 3dsmax would be UV channel 1.

I'm not really very good at shaders at all though, so I can't help you but it does look to me like its doing what Lioric asked. I'm looking forward for when the shaderFX support in ofusion is released till I really get into shaders seriously.

Odog87

18-09-2007 20:13:59

Here is the file I am working with. (I'm hoping some one will see a problem and point it out)
It was made with max 9, and ofusion version 1.8.96 (just in case that makes a difference)

http://www.shadedviews.com/scrap/components.zip

If you rotate the switch or battery 180 degrees on the x, or y axis, you will see my problem

I used the specular bump shader that comes with ofusion.

If I was creating static objects I don't think I would have this problem, but these items have to be rotated in any angle

Lioric

19-09-2007 02:45:41

I will review your scene asap

dganesh

24-10-2007 01:59:20

Lioric / Odog87,

Was there a resolution? I think we're hitting a similar problem.

It feels like somehow the tangents (handedness) are not right. It might have some relation to how the model was original designed in Max. But I can't pin it on exactly anything yet.

Odog87

24-10-2007 02:15:34

It feels like somehow the tangents (handedness) are not right. It might have some relation to how the model was original designed in Max. But I can't pin it on exactly anything yet.

Have you turned on "generate tangent vectors" in ofusion?

If yes, then try reseting the transform and collapsing the stack to a mesh or poly.

One final thought would be to go over your shader parameters and insure that they are correct.

I never really got an answer, but then again I switch to a different shader made by EVAK Search for his stuff he has good shaders

dganesh

24-10-2007 03:07:16

Have you turned on "generate tangent vectors" in ofusion?
Our artist (PDX) created the files. I know he chose the generate tangents option, and I can see the tangent information in the mesh (when I convert to XML).

If yes, then try reseting the transform and collapsing the stack to a mesh or poly.
I will ask him to try ths trick, and see what happens.

One final thought would be to go over your shader parameters and insure that they are correct.
The shader params seem alright. I believe PDX also tried using some of Evak's shaders, but that didn't solve the problem.

BTW, hereis the original problem thread started by PDX.