2 registered members (AndrewAMD, Nymphodora),
1,592
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
HLSL Parallax Mapping
#34751
10/11/04 05:23
10/11/04 05:23
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
I've been trying to convert this HLSL shader for a while now and have not yet been able to succeed as of yet so I decided to show the URL where I got the source here in case someone else wanted to give it a shot. What a parallax map does is warp a 2d texture to simulate self-occlusion based on a heightmap. This creates a very cool bump map style effect as seen below: The HLSL source code and more information can be found on this page .
"you give me the reason, you give me control, i gave you my purity, my purity you stole, did you think i wouldn't recognize this compromise? am i just too stupid to realize?" - Trent Reznor (NiN)
Yahoo Messager ID: SHATT3R3DFA1TH
|
|
|
Re: HLSL Parallax Mapping
[Re: M3PHiSTOPH3L3S]
#34752
10/11/04 06:11
10/11/04 06:11
|
Joined: Sep 2004
Posts: 1,214 Austin, Texas
Josh_Arldt
Senior Developer
|
Senior Developer
Joined: Sep 2004
Posts: 1,214
Austin, Texas
|
Try changing Code:
float4x4 view_proj_matrix;
to Code:
matrix matWorldViewProj;
and change Code:
float4x4 view_matrix;
to Code:
matrix matWorldView
.
|
|
|
Re: HLSL Parallax Mapping
[Re: Josh_Arldt]
#34753
10/11/04 06:23
10/11/04 06:23
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
I have already changed those and made other obvious changes, but even after that it gives me errors about converting vectors. I'm at work right now so I don't have my source right off hand, but its something like "can not implicitly convert float4 to float3X3", if I remember right, along with a similar error. I double checked my code for syntax and it appears clean to me. Maybe tomorrow I can post what I have done so far.
"you give me the reason, you give me control, i gave you my purity, my purity you stole, did you think i wouldn't recognize this compromise? am i just too stupid to realize?" - Trent Reznor (NiN)
Yahoo Messager ID: SHATT3R3DFA1TH
|
|
|
Re: HLSL Parallax Mapping
[Re: Andreas_F]
#34755
10/11/04 06:31
10/11/04 06:31
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
If and when I get this running, I most certainly will release an example and source. Also I believe this shader should work well on level geometry.
M3PHiSTO
"you give me the reason, you give me control, i gave you my purity, my purity you stole, did you think i wouldn't recognize this compromise? am i just too stupid to realize?" - Trent Reznor (NiN)
Yahoo Messager ID: SHATT3R3DFA1TH
|
|
|
Re: HLSL Parallax Mapping
[Re: Josh_Arldt]
#34757
10/11/04 15:43
10/11/04 15:43
|
Joined: May 2002
Posts: 2,541 Berlin
EX Citer
Expert
|
Expert
Joined: May 2002
Posts: 2,541
Berlin
|
Making somethinng 3D with a height map sounds like the fur shader. And the furshader was looking simple. In anyway I hope you will get it working, looks fantastic.
:L
|
|
|
Re: HLSL Parallax Mapping
[Re: EX Citer]
#34758
10/12/04 08:00
10/12/04 08:00
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
Alright here is the source I have so far. This is the first HLSL source I have tried to convert so it may be a little sloppy. You can compile it and see the errors that I got:
// start
// // HLSL Parallax Shader //
Material mat_parallax {
effect = "
// VertexShader ------------------
float4x4 matWorldViewProj; float4x4 matWorld; float4 light_position = ( 100, 100, 100, 0); // just used these settings for testing float4 vecViewPos;
texture entSkin1; texture entSkin2; texture entSkin3;
sampler base_map = sampler_state { texture = (entSkin1); };
sampler bump_map = sampler_state { texture = (entSkin2); };
sampler height_map = sampler_state { texture = (entSkin3); };
struct VS_INPUT_STRUCT { float4 position : POSITION; float3 tangent : TANGENT; float3 normal : NORMAL; float3 texcoord0 : TEXCOORD0; };
struct VS_OUTPUT_STRUCT { float4 position : POSITION; float2 bump_map : TEXCOORD0; float3 tangentlight : TEXCOORD1; float3 half_angle : TEXCOORD2; float3 tangenteye : TEXCOORD3; };
VS_OUTPUT_STRUCT main( VS_INPUT_STRUCT vsInStruct ) { VS_OUTPUT_STRUCT vsOutStruct; vsOutStruct.position = mul( matWorldViewProj, vsInStruct.position ); float3 position = mul( matWorld, vsInStruct.position ); vsOutStruct.bump_map = vsInStruct.texcoord0; float3x3 tangentspace_matrix = float3x3( vsInStruct.tangent, cross( vsInStruct.tangent, vsInStruct.normal ), vsInStruct.normal ); float3x3 objectspace_light_vector = mul( ( matWorld * -1 ), light_position ) - vsInStruct.position; vsOutStruct.tangentlight = mul( tangentspace_matrix, objectspace_light_vector ); float3 objectspace_view_vector = mul( ( matWorld * -1 ), vecViewPos ) - vsInStruct.position; vsOutStruct.tangenteye = mul( tangentspace_matrix, objectspace_view_vector ); vsOutStruct.half_angle = vsOutStruct.tangentlight + vsOutStruct.tangenteye; return vsOutStruct; };
// PixelShader -------------------
float bumpiness; float parallax; float specular_power; float4 ambient; float4 diffuse; float4 specular;
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 vecViewPos, float parallax_amount ) { return( tex2D( height_map, oldcoord ) * parallax_amount - parallax_amount * 0.5 ) * vecViewPos + oldcoord; };
PS_OUTPUT_STRUCT main( PS_INPUT_STRUCT psInStruct ) { PS_OUTPUT_STRUCT psOutStruct; float3 vecViewPos = normalize( psInStruct.tangenteye ); float2 modified_texcoord = ParallaxTexCoord( psInStruct.bump_map, height_map, vecViewPos, 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 = ( ambient + diffuse * max( 0, n_dot_l ) + specular * 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 vsOutStruct(); PixelShader = compile ps_2_0 psOutStruct(); } }
";
}
action hlsl_parallax {
my.material = mat_parallax;
}
// finish
I hope that this can help someone because I haven't found out what is wrong yet.
M3PHiSTO
"you give me the reason, you give me control, i gave you my purity, my purity you stole, did you think i wouldn't recognize this compromise? am i just too stupid to realize?" - Trent Reznor (NiN)
Yahoo Messager ID: SHATT3R3DFA1TH
|
|
|
Re: HLSL Parallax Mapping
[Re: M3PHiSTOPH3L3S]
#34759
10/13/04 01:11
10/13/04 01:11
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
@EX Citer: This shader is alot different than the fur shader because that used shells to make the fur stick out. This computes the displacement on the textures surface so that it remains flat.
If you are interested in seeing what this shader can do you should checkout the Doom3 parallax mod.
M3PHiSTO
"you give me the reason, you give me control, i gave you my purity, my purity you stole, did you think i wouldn't recognize this compromise? am i just too stupid to realize?" - Trent Reznor (NiN)
Yahoo Messager ID: SHATT3R3DFA1TH
|
|
|
Re: HLSL Parallax Mapping
[Re: M3PHiSTOPH3L3S]
#34760
10/13/04 07:28
10/13/04 07:28
|
Joined: Mar 2001
Posts: 3,298 Beverly, Massachusetts
Rhuarc
Expert
|
Expert
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
|
Here is a version that doesn't give errors, I don't think my video card supports the shader though (Radeon 9200). Changes are highlighted in redCode:
// VertexShader ------------------
float4x4 matWorldViewProj; float4x4 matWorld; float4 light_position = ( 100, 100, 100, 0); // just used these settings for testing float4 vecViewPos;
texture entSkin1; texture entSkin2; texture entSkin3;
sampler base_map = sampler_state { texture = (entSkin1); };
sampler bump_map = sampler_state { texture = (entSkin2); };
sampler height_map = sampler_state { texture = (entSkin3); };
struct VS_INPUT_STRUCT { float4 position : POSITION; float3 tangent : TANGENT; float3 normal : NORMAL; float3 texcoord0 : TEXCOORD0; };
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( matWorldViewProj, vsInStruct.position );
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( ( matWorld * -1 ), light_position ) - vsInStruct.position;
vsOutStruct.tangentlight = mul( tangentspace_matrix, objectspace_light_vector );
float3 objectspace_view_vector = mul( ( matWorld * -1 ), vecViewPos ) - vsInStruct.position;
vsOutStruct.tangenteye = mul( tangentspace_matrix, objectspace_view_vector ); vsOutStruct.half_angle = vsOutStruct.tangentlight + vsOutStruct.tangenteye;
return vsOutStruct; };
// PixelShader -------------------
float bumpiness; float parallax; float specular_power; float4 ambient; float4 diffuse; float4 specular;
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 vecViewPos, float parallax_amount ) { return( tex2D( height_map, oldcoord ) * parallax_amount - parallax_amount * 0.5 ) * vecViewPos + oldcoord; };
PS_OUTPUT_STRUCT mainPS( PS_INPUT_STRUCT psInStruct ) { PS_OUTPUT_STRUCT psOutStruct; float3 vecViewPos = normalize( psInStruct.tangenteye ); float2 modified_texcoord = ParallaxTexCoord( psInStruct.bump_map, height_map, vecViewPos, 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 = ( ambient + diffuse * max( 0, n_dot_l ) + specular * 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(); } }
|
|
|
|