2 registered members (AbrahamR, AndrewAMD),
1,278
guests, and 2
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: HLSL Parallax Mapping
[Re: M3PHiSTOPH3L3S]
#34771
10/16/04 23:24
10/16/04 23:24
|
Joined: Oct 2003
Posts: 151 Watseka, Illinois
M3PHiSTOPH3L3S
OP
Member
|
OP
Member
Joined: Oct 2003
Posts: 151
Watseka, Illinois
|
well when i got home last night I tried to use matWorldInv and it still didn't work. If I set it to vs and ps version 2.0 it compiles but shows nothing. If it is compiled under 3.0 it shows the model but no effect. I don't know. Anyone have any other suggestions? I'm starting to have doubt about getting this to work...
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]
#34772
10/17/04 02:58
10/17/04 02:58
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
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;
}
|
|
|
Re: HLSL Parallax Mapping
[Re: Steempipe]
#34775
10/17/04 03:31
10/17/04 03:31
|
Joined: Oct 2002
Posts: 815 NY USA
Red Ocktober
Developer
|
Developer
Joined: Oct 2002
Posts: 815
NY USA
|
i may be wrong, and just seeing the tricks the texture is playing on me, but from that shot, it looks as if you raise the bumps a lil that you might have something...
... the reflection on the edge of the bricks seem to me that it may be working,
or i might be missing the whole thing entirely...
--Mike
|
|
|
Re: HLSL Parallax Mapping
[Re: Steempipe]
#34777
10/17/04 04:23
10/17/04 04:23
|
Joined: Oct 2002
Posts: 815 NY USA
Red Ocktober
Developer
|
Developer
Joined: Oct 2002
Posts: 815
NY USA
|
... yeah, i'm sure this stuff can get a lil aggravating (frustrating) at times. yeah, take a break man. this stuff IS rocket science hey, i appreciate you posting the stuff and showing the rest of us (me) what you've accomplished. --Mike
|
|
|
Re: HLSL Parallax Mapping
[Re: Red Ocktober]
#34779
10/17/04 09:00
10/17/04 09:00
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
Serious User
|
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
Quote:
... yeah, i'm sure this stuff can get a lil aggravating (frustrating) at times.
yeah, take a break man.
this stuff IS rocket science
hey, i appreciate you posting the stuff and showing the rest of us (me) what you've accomplished.
--Mike
Thanks!
Pappenheimer: It my come down to that (posting the other code), but I have a few more ideas to try first before I take the "garbage" that litters my FX file out. Right now it may be more confusing than anything. Good suggestion, however.
Here is what I am fighting on this one (my version). If you look at the texture it is looking like this...
|
|
|
|