Well... I got sidetracked from my version and played aroudn with your code. The textures show, but I think all I am getting is regular Bumpmapping.
None the less, hope you can figure out what I am missing here
** I cannot answer any questions about this one because I cannot figure out how to get the offset working right, yet.
Code:
/**************************************************************
Attempting to get Parallax Bumpmapping to work.
10/16/04: I think right now only Bumpmapping
is actually happening
**************************************************************/
/*************************************************************
Make noFog == True, or add fog vertex code
to allow material to show on model.
For this testing I used a flat terrain.
**************************************************************/
function parabump_init{
mat_inverse(mtl.matrix, matworld);
bmap_to_mipmap(mtl.skin1);
bmap_to_mipmap(mtl.skin2);
bmap_to_mipmap(mtl.skin3);
}
bmap tex0 = <rockwall_CM.tga>; //RGB Colormap
bmap tex1 = <rockwall_NM.tga>; //RGB Normalmap
bmap tex2 = <rockwall_HM.tga>; //RGB Heightmap
material parabump_fx {
flags=tangent;
Skin1=tex0;
Skin2=tex1;
Skin3=tex2;
event = parabump_init;
effect="
// VertexShader ------------------
float4x4 matWorldViewProj;
float4x4 matWorld;
float4 vecSunDir;// light_position = (50, 500, 100, 0); // just used these settings for testing
float4 vecViewPos;
float4x4 matMtl;
texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
sampler base_map = sampler_state
{
texture = (mtlSkin1);
};
sampler bump_map = sampler_state
{
texture = (mtlSkin2);
};
sampler height_map = sampler_state
{
texture = (mtlSkin3);
};
struct VS_INPUT_STRUCT
{
float4 position : POSITION;
float3 normal : NORMAL;
float3 texcoord0 : TEXCOORD0;
float3 tangent : TEXCOORD2;
};
struct VS_OUTPUT_STRUCT
{
float4 position : POSITION;
float2 bump_map : TEXCOORD0;
float3 tangentlight : TEXCOORD1;
float3 half_angle : TEXCOORD2;
float3 tangenteye : TEXCOORD3;
};
VS_OUTPUT_STRUCT mainVS( VS_INPUT_STRUCT vsInStruct )
{
VS_OUTPUT_STRUCT vsOutStruct;
vsOutStruct.position = mul( vsInStruct.position, matWorldViewProj );
float3 position = mul( matWorld, vsInStruct.position );
vsOutStruct.bump_map = vsInStruct.texcoord0;
float3x3 tangentspace_matrix = float3x3( vsInStruct.tangent,cross( vsInStruct.tangent,vsInStruct.normal
),vsInStruct.normal);
float3 objectspace_light_vector = mul( matMtl, -vecSunDir ) - vsInStruct.position;
vsOutStruct.tangentlight = mul( tangentspace_matrix,objectspace_light_vector );
float3 objectspace_view_vector = mul( matMtl, vecViewPos ) - vsInStruct.position;
vsOutStruct.tangenteye = mul( tangentspace_matrix, objectspace_view_vector );
vsOutStruct.half_angle = vsOutStruct.tangentlight + vsOutStruct.tangenteye;
return vsOutStruct;
};
// PixelShader -------------------
float bumpiness = 0.5;
float parallax = 5.5;
float specular_power = 0.5;
float4 vecAmbient;
float4 vecDiffuse;
float4 vecSpecular;
float vecViewDir;
struct PS_INPUT_STRUCT
{
float2 bump_map : TEXCOORD0;
float3 tangentlight : TEXCOORD1;
float3 half_angle : TEXCOORD2;
float3 tangenteye : TEXCOORD3;
};
struct PS_OUTPUT_STRUCT
{
float4 color0 : COLOR0;
};
float2 ParallaxTexCoord( float2 oldcoord, sampler height_map, float3 eye_vec, float parallax_amount )
{
return (tex2D( height_map, oldcoord )
* parallax_amount + parallax_amount * 0.5)
* (0.0,0.0,0.0) + oldcoord
;
};
PS_OUTPUT_STRUCT mainPS( PS_INPUT_STRUCT psInStruct )
{
PS_OUTPUT_STRUCT psOutStruct;
float3 eye_vec = normalize( psInStruct.tangenteye );
float2 modified_texcoord = ParallaxTexCoord( psInStruct.bump_map, height_map, eye_vec, parallax );
float3 base = tex2D( base_map, modified_texcoord );
float3 bump = tex2D( bump_map, modified_texcoord );
float3 normalized_light_vector = normalize( psInStruct.tangentlight );
float3 normalized_half_angle = normalize( psInStruct.half_angle );
float3 smooth = float3( 0.5, 0.5, 1 );
bump = lerp( smooth, bump, bumpiness );
bump = normalize( ( bump * 2.0f ) - 1.0f );
float3 n_dot_l = dot( bump, normalized_light_vector );
float3 n_dot_h = dot( bump, normalized_half_angle );
psOutStruct.color0.rgb = (
vecAmbient +
vecDiffuse * max( 0, n_dot_l ) +
vecSpecular * pow( max ( 0, n_dot_h ), specular_power )
) * base;
psOutStruct.color0.a = 1.0f;
return psOutStruct;
};
technique Parallax
{
pass P0
{
VertexShader = compile vs_2_0 mainVS();
PixelShader = compile ps_2_0 mainPS();
}
}
";
}
action parabump{
my.material = parabump_fx;
}