HLSL Parallax Mapping

Posted By: M3PHiSTOPH3L3S

HLSL Parallax Mapping - 10/11/04 05:23

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 .
Posted By: Josh_Arldt

Re: HLSL Parallax Mapping - 10/11/04 06:11

Try changing Code:
float4x4 view_proj_matrix;  

to Code:
 matrix matWorldViewProj; 

and change Code:
float4x4 view_matrix;  

to Code:
 matrix matWorldView

.
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/11/04 06:23

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.
Posted By: Andreas_F

Re: HLSL Parallax Mapping - 10/11/04 06:25

could you perhaps post your code and graphics (as example) when it is working?
this would be very nice
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/11/04 06:31

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
Posted By: Josh_Arldt

Re: HLSL Parallax Mapping - 10/11/04 07:00

Quote:

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.




Seeing your code might help us figure out what is wrong easier.
Posted By: EX Citer

Re: HLSL Parallax Mapping - 10/11/04 15:43

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.
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/12/04 08:00

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
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/13/04 01:11

@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
Posted By: Rhuarc

Re: HLSL Parallax Mapping - 10/13/04 07:28

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 red
Code:


// 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();
}
}



Posted By: Josh_Arldt

Re: HLSL Parallax Mapping - 10/13/04 08:00

I have tried it and all I see are big black lines going across the camera. Kind of like the models mesh is skewed across the level. My card supports it too. So I wonder what the problem is?
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/13/04 09:56

I have not had time to play with your shader. I have an offset(parallax)bumpmapping effect that is working for the most part, but needs tweaks.

One thing, and the only thing, that jumps out at me is this:

In the Vertexshader inputs,
Quote:

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





We are given the tangent in TEXCOORD2 (consult the TXT file that comes with our updates). So I would probably start by making it compliant that way:

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

I know, I know... sometimes it does not seem to matter what FVF type of stuff we shove in. But, sometime's it does.

Then maybe look at lighting things and the direction, maybe negate something.

Hope something helps or produces other ideas!

Eric
Posted By: Andreas_F

Re: HLSL Parallax Mapping - 10/13/04 21:49

i've tried the corrected code + the changes from steempipe. No Errors but then i get the model that has this shader into view, the engine just crashes... No Errors nothing
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/14/04 00:56

Thank you all for trying to figure this out. When I get home I'll try messing with it some more. BTW, Steampipe, if you dont mind can you post your parallax shader? I'd be interested in seeing anything like this work, and also does it work on level geometry?

M3PHiSTO
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/14/04 05:40

I had put the effect on the back-burner, so it never did get ironed out. I am considering posting it, but I will not be able to answer questions and such.

This is where I left off, for vertex/pixelshader 1.1

Posted By: Drew

Re: HLSL Parallax Mapping - 10/14/04 06:07

yes please!
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/14/04 07:03

Not that I intend to hijack this thread... it just reminded me of a folder I had with my tribulations.

Now that it is not so dark, there is still one major gripe I have with it~ The colormap gets skewed in the "DOT" process and leaves an undesirable banding type effect that is very noticable when up close.






See if I can figure that out, and then post some code...
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/15/04 23:25

Well I've tried just about everything now and nothing seems to work. I thought of something that I probably did wrong though. I tried calculating the inverted world matrix by matWorld * -1 ... something tells me that might be whats wrong. I'm at work now so I cant really try fixing it now, but is this the wrong way to calculate the inverse world matrix? If so, can someone tell me how to do this right? Thank you in advance.

M3PHiSTO
Posted By: Matt_Aufderheide

Re: HLSL Parallax Mapping - 10/16/04 00:09

yes thats the wrong way.. the inverse of a matrix is not neccessarily it's negative.

instead simply use this :
mat_inverse(matMtl, matWorld);
this copies the inverse world matrix to the material matrix.
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/16/04 00:14

ty,ty,ty!!

i haven't been able to try it, but thats probably what it is! When i get home I'll try to set it up properly and release a demo (keeping fingers crossed).

M3PHiSTO
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/16/04 23:24

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
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/17/04 02:58

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;

}


Posted By: Red Ocktober

Re: HLSL Parallax Mapping - 10/17/04 02:59

hey Steem... got time to add a quick screenshot of the results your gettin...

thx

--Mike
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/17/04 03:23

If playing with the eye_vec variable and also the tweakables, I get super strange projections.... This shot is none of that, however.


Posted By: Red Ocktober

Re: HLSL Parallax Mapping - 10/17/04 03:31

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
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/17/04 03:40

It is working to a degree... thing is that I cannot figure out how to get more relief with the thing. When I try, I get some crazy results. I get a relief mapped texture, but not in the right places or scale.

I tried until nearly blowing a gasket, so I must decompress alittle
Posted By: Red Ocktober

Re: HLSL Parallax Mapping - 10/17/04 04:23

... 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
Posted By: Pappenheimer

Re: HLSL Parallax Mapping - 10/17/04 07:05

You seemed to be closer at this pic:



Can you post that version of code? So, that a comparison of both might give an idea how to proceed?
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/17/04 09:00

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...


Posted By: Rhuarc

Re: HLSL Parallax Mapping - 10/17/04 09:07

Hey Steempipe,

If you can just post your other code (or PM/email it to me (rhuarc@shadowforgeserver.net)) and let me know how you were trying to get it working with more parallax in this one (that was putting it in the wrong places) I'm sure I can figure it out from here. I've got a few good ideas as to what the problem is...

-Rhuarc
Posted By: Elfi

Re: HLSL Parallax Mapping - 10/17/04 10:06

Hi!

Ist es auch möglich diesen Shader auf meinen Leveltexturen anzuwenden? Ich hab leider nicht die geringste Ahnung wie man sowas macht geschweige umschreibt da meine Stärke nur im Levelaufbau und der Characteranimation besteht. Das normale Bumpmapping Script hab ich schon aber das ist mir nicht schön genug. Bitte seit so lieb.

Demon
Posted By: Pappenheimer

Re: HLSL Parallax Mapping - 10/17/04 18:07

Couldn't that be a problem of the pic you use?

That looks a bit like the old bump shader when I changed the diffspec.tga adding a waterlike texture.
Posted By: M3PHiSTOPH3L3S

Re: HLSL Parallax Mapping - 10/17/04 23:50

@Steempipe: wow your parallax shader looks cool. It seems to do the self-occlusion properly. What seems to be the problem? Is the texture being displayed incorrectly?

M3PHiSTO
Posted By: Elfi

Re: HLSL Parallax Mapping - 10/20/04 06:02

is it to be possibly applied this code also to my level?

MfG
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/20/04 09:15

Quote:

@Steempipe: wow your parallax shader looks cool. It seems to do the self-occlusion properly. What seems to be the problem? Is the texture being displayed incorrectly?

M3PHiSTO




The texture looks like it is soapy to me. I have not been able to get back to this code yet.
Posted By: Alexzx

Re: HLSL Parallax Mapping - 10/23/04 19:38

on geforce4 it's work?
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/23/04 20:11

The version that I am working on, anything the suppors pixelshader1.1 will run the effect. So yes.

Had some time to fiddle last night, making some small progress:

Posted By: Josh_Arldt

Re: HLSL Parallax Mapping - 10/30/04 03:13

any updates on this yet?
Posted By: Steempipe

Re: HLSL Parallax Mapping - 10/31/04 11:05

It's on my back-burner right now.
Posted By: Steempipe

Re: HLSL Parallax Mapping - 11/03/04 08:45


And yet, this thing is really testing my patience!


Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 11/13/04 12:32

Finally!

And CBabe is admiring it, herself.

PS.2.0, for now...


Posted By: Rhuarc

Re: Check This Out - Parallax Mapping - 11/13/04 13:29

Woohoo!

Can't wait to see the source and see if I can convert it to 1.4 or less .

-Rhuarc
Posted By: Drew

Re: Check This Out - Parallax Mapping - 11/13/04 13:47

VERY impressive.
Posted By: Josh_Arldt

Re: Check This Out - Parallax Mapping - 11/13/04 14:46

SWEET!!! Awsome!!!
It looks soooo good.
When do you plan on releasing the code?
And how's your fps?
Posted By: M3PHiSTOPH3L3S

Re: Check This Out - Parallax Mapping - 11/14/04 00:23

Cool! I still haven't been able to make progress on my conversion yet, but its good to see yours up and running. Good job Steempipe. Looking forward to see the source.

M3PHiSTO
Posted By: William

Re: Check This Out - Parallax Mapping - 11/14/04 05:19

Whoa! That looks awsome!
Posted By: TheExpert

Re: Check This Out - Parallax Mapping - 11/14/04 06:23

Impressive !

you're the shader king steempipe !
and it looks like the G3D engine example demo parallax mapping !

in term of performance ? is it a big hit if you put a level with it ?
beacause parallax usefull for stone wall levels !
for charecters i think noral mapping is sufficient no ? or parallax
is better for characters ?

i've played Halo 2 : and characters with normal bump map are already great !
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 11/14/04 10:14

The FPS did not take a bad hit... Still, I did a brief test on level geometry and it went sour there in the framerate. I'll need to fiddle with it.

After getting a little more done to it, and attempting ps14 support, then I'll make code available.

So far, I would guess that characters still may look better with just normalmapping. But it all depends on who implements an effect and how they do it.

This is just strange..... How it does this .


Posted By: Red Ocktober

Re: Check This Out - Parallax Mapping - 11/14/04 10:53

oh my god!!!

absolutely fantastic...

another round of applause gnetlemen...

and a standing ovation too...

--Mike
Posted By: William

Re: Check This Out - Parallax Mapping - 11/14/04 16:23

WhoA! Now that makes it look even more impressive!
Posted By: M3PHiSTOPH3L3S

Re: Check This Out - Parallax Mapping - 11/15/04 04:16

Quote:

So far, I would guess that characters still may look better with just normalmapping. But it all depends on who implements an effect and how they do it.





If the parallax source of yours is similar to mine, it should use a heightmap and dot3 map. I'm sure you could get good effects for characters by only using the heightmap on areas with lotsa variation to the geometries depth (i.e. grooves in armor and such) and just leave the rest to normal mapping. Hope you understand...I cant think of how to say it more clearly.

M3PHiSTO
Posted By: Pappenheimer

Re: Check This Out - Parallax Mapping - 11/15/04 05:53

It looks so impressive! I've got tears in my eyes! Wo- how!
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 11/27/04 19:45

In the process of making it more applicable with Matt A's Ultimate Light Shader.

I would like to achieve some consistancy and ease of integration between the 2 shaders.

The lights and level suck, but it is easier to see what is happeneing when things are exaggerated. I am also working out some texcoord things.

There are (2) dynamic lights, kind of red and yellowish. Matt's PP lighting is the wood, the parallax is the stone. They grab lighting from the same sources.





Posted By: William

Re: Check This Out - Parallax Mapping - 11/28/04 09:26

I'd love to see this in a demo! Looks very good.
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 11/28/04 09:28

Working on getting it to that point, thanks!
Posted By: Josh_Arldt

Re: Check This Out - Parallax Mapping - 11/28/04 10:09

OMG!!!
It's looking very nice Steempipe.
Very nice.
I can't wait for a demo or some code.
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 11/28/04 16:49

I think the code still isn´t published? Wether the soapy nor the sharp
Posted By: M3PHiSTOPH3L3S

Re: Check This Out - Parallax Mapping - 12/05/04 06:28

@Steempipe: When you get this implemented all the way you might also try converting it from parallax to relief mapping since parallax mapping only offsets coordinates by an approximation(the reason why deformations happen at strange view angles) while relief mapping offsets coordinates properly. This would yield much more accurate results. I'll do a search for the whitepaper for relief mapping and post it incase you or anyone else is interested.

[EDiT] There is an implementation for OGL at cgshaders.org, but it comes with a PDF that explaines the formulas used which could be useful for porting to DirectX 9c. Unfortunatley you'll have to download the source and all to get the PDF. Anyways its here: http://cgshaders.org/contest/#reliefmapping


M3PHiSTO
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 12/05/04 06:56

M3PHiSTOPH3L3S: Good info.. thanks! BTW: Are you still working this stuff out??
Posted By: M3PHiSTOPH3L3S

Re: Check This Out - Parallax Mapping - 12/05/04 07:04

Since I tried getting it to work the first time, I have reinstalled windows and have been moving recently, but I did start messing with it again. I'm thinking of scrapping my code and starting from scratch again. Maybe even try the relief mapping instead. LOL converting hlsl has been a pain compared to converting asm, but I finally bit the bullet and started reading some tutorials on writing shaders. Still seems greek to me though.

M3PHiSTO
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 12/11/04 18:37

Hi,
The screenshots look like the code is finished. I would need it for one model. I think the shader runs very slow on leveltextures (in a complete level). On which ps and vs version is the shader running? I hope it´s not using any entity skills.

EX Citer
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 12/12/04 07:41

The last screenshot is using pixelshader 2.0.

There are no entity skills in the code.

It is pretty much done. However... I have not worked with it since the screenshot, and I am also waiting for some results from a user who is testing it.
Posted By: TheExpert

Re: Check This Out - Parallax Mapping - 12/13/04 06:09

it would be cool to make it less specular , we have a lot of reflection like
effect on the last picture for the wood material.
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 12/27/04 07:37

Does it really exists? Or is it a mythos?

What about the last versions? I couldn´t see any bugs.
Posted By: PHeMoX

Re: Check This Out - Parallax Mapping - 12/27/04 08:28

Yeah, is this thing still in development? I'm curious for the code, though I can't try it out where I am right now, so *don't* hurry hehehehe..

Cheers
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 12/27/04 08:31

Quote:

Does it really exists? Or is it a mythos?

What about the last versions? I couldn´t see any bugs.




Just for you... Merry Xmas (belated)

Code:

// -------------------------------------------------------------
// Parallax (offset) Mapping Shader for 3DGS Model Entities
//
// By: Eric Hendrickson-Lambert (Steempipe)
//
// Requires: A6.31+, DX9.00c, and pixelshader.2.0
//
//
// Note: As always, this is a work in progress....
// To be free for use; credit appreciated.
//

// 11/17/04: -Cleaned up code for release
// 11/27/04: -Modified the code to follow suit
// with Matt A's Ultimate Lighting Shader.
// For easier integration and modification.
// 11/28/04 -(2) dynamic lights added.
//
//
// ToDo: -Add more light passes
// -Iron out the view vectors in the effect
// -Add another texture for use as gloss/spec mask
-Spit out gloss/spec UV with seperate coords for individual scaling
//
// Collaborators: -Drew Medina (Testing, bug reporting, and demo work)
//
// -------------------------------------------------------------


material mat_parallax {

flags=tangent;

effect="

float4x4 matWorldViewProj;
float4x4 matWorld;
float4x4 matViewInv;

float3x3 WldToTan;

float4 vecViewPos;
float4 vecViewDir;

float4 vecLight;
float4 vecLightPos[8];
float4 vecLightColor[8];

texture entSkin1;
texture entSkin2;
texture entSkin3;

sampler sColorMap = sampler_state
{
Texture = <entSkin1>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};


sampler sBumpMap = sampler_state
{
Texture = <entSkin2>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};


sampler sHeightMap = sampler_state
{
Texture = <entSkin3>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = Wrap;
AddressV = Wrap;
};



struct VS_OUTPUT
{
float4 oPosition : POSITION;
float2 Tex : TEXCOORD0;
float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;

float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;
};


VS_OUTPUT main_vs(float4 inPosition : POSITION, float2 inTex : TEXCOORD0, float3 inNormal : NORMAL, float3 inTangent : TEXCOORD2 )
{
VS_OUTPUT Out ;

Out.oPosition = mul(inPosition, matWorldViewProj);

WldToTan[0] = mul(inTangent, matWorld);
WldToTan[1] = mul(cross(inTangent, inNormal), matWorld);
WldToTan[2] = mul(inNormal, matWorld);

Out.Tex = inTex.xy * 1.5; //Scale the texture UV's


float4 Pos_World = mul( inPosition, matWorld);

float LightRange1 = 0.003;
float LightRange2 = 0.005;

//light 1
float3 Light1 = Pos_World - vecLightPos[1];
Out.Light1.xyz = mul(WldToTan, -Light1);

float3 Viewer1 = Pos_World - vecViewDir;
Out.View1.xzy = mul(WldToTan, -Viewer1);

Out.Att1 = Light1 * LightRange1;
//light 2
float3 Light2 = Pos_World - vecLightPos[2];
Out.Light2.xyz = mul(WldToTan, -Light2);

float3 Viewer2 = Pos_World - vecViewDir;
Out.View2.xzy = mul(WldToTan, -Viewer2);

Out.Att2 = Light2 * LightRange2;

return Out;
}

struct PS_INPUT0
{
float2 Tex : TEXCOORD0;
float3 Light1 : TEXCOORD2;
float3 View1 : TEXCOORD3;
float3 Att1 : TEXCOORD4;
float3 Light2 : TEXCOORD5;
float3 View2 : TEXCOORD6;
float3 Att2 : TEXCOORD7;

};

float4 main_ps(PS_INPUT0 IN): COLOR
{
const float HeightScale = {0.030000f};
const float BiasFilter = {0.025000f};



float3 ViewDir = normalize(IN.View1);
float4 color;
float3 bumpNormal;

float Height = HeightScale * tex2D(sHeightMap, IN.Tex) - BiasFilter;
float2 OffsetTex = Height * ViewDir + IN.Tex;
color = tex2D(sColorMap, OffsetTex);
bumpNormal =(2 * (tex2D(sBumpMap, OffsetTex )))- 1.0;
float4 gloss = tex2D( sBumpMap, OffsetTex);

//light1
float3 LightDir1 = normalize(IN.Light1);
float3 ViewDir1 = normalize(IN.View1);
float4 diff1 = saturate(dot(bumpNormal, LightDir1));
float shadow1 = saturate(2 * diff1);
float3 Reflect1 = normalize(2 * diff1 * bumpNormal - LightDir1);
float4 spec1 = pow(saturate(dot(Reflect1, ViewDir1)), 8);
float4 Attenuation1 = saturate(dot(IN.Att1, IN.Att1));

//light2
float3 LightDir2 = normalize(IN.Light2);
float3 ViewDir2 = normalize(IN.View2);
float4 diff2 = saturate(dot(bumpNormal, LightDir2));
float shadow2 = saturate(2 * diff2);
float3 Reflect2 = normalize(2 * diff2 * bumpNormal - LightDir2);
float4 spec2 = pow(saturate(dot(Reflect2,ViewDir2)), 8);
float4 Attenuation2 = saturate(dot(IN.Att2, IN.Att2));

return (
(0.2 * color) + //ambient
((shadow1 * (color * diff1 + (spec1)) * (1 -Attenuation1))*vecLightColor[1])+
((shadow2 * (color * diff2 + (spec2)) * (1 -Attenuation2))*vecLightColor[2])
);

//return (0.2 * color + color* diff1 * vecLightColor[1]+diff2 * vecLightColor[2]);

}



technique Parallax
{
pass P0
{

VertexShader = compile vs_2_0 main_vs();
PixelShader = compile ps_2_0 main_ps();
}
}


";
}

action parallax_fx{

my.material = mat_parallax;
//my.frame+=1; //If engine tangent bug is not rectified yet


}


}





Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 12/27/04 08:43

Oh yah..... here are what the (3) skins look like.


Posted By: PHeMoX

Re: Check This Out - Parallax Mapping - 12/27/04 09:14

LOL!! Damn and now I have to wait quite some time before I can try this shader.... Aaaaarrrrrgghh!! BUT very much appreciated anyways hehehe, you're playing your role as santa very good (belated) ..

Cheerrs!
Posted By: Josh_Arldt

Re: Check This Out - Parallax Mapping - 12/27/04 09:29

This is freakin' awsome!!!

Quote:

you're playing your role as santa very good




You should change your name to Santapipe or something.j/k.

This sort of thing is done in the AMP II Engine,
but doesn't require a good video card to see the fx.
Are the AMP II shaders FFP shaders or something?
Posted By: Drew

Re: Check This Out - Parallax Mapping - 12/27/04 13:27

Steempipie-
Just tried again, the warping was because i wasnt putting my heightmap in skin3, it was in my alpha chsannel.
That gave me alpha problems, so i tried without...looked good but warped, then added the skin3, LOOKS FANTASTIC.

Thanks
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 12/28/04 02:18

HWOOOAAAA!!!! Fantastic! Now I just have to test it Thank you!

EX CIter
Posted By: Drew

Re: Check This Out - Parallax Mapping - 12/28/04 14:30

i take it back, still get warping... still testing
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 12/28/04 21:03

I don´t get it working too. But I think my grafic card doesn´t support it (geforce FX 5600). The model is completly white.


EDIT: I tried now the normal mapping shader, and I have exactly the same problem. The model is white (very light grey).
Posted By: TheExpert

Re: Check This Out - Parallax Mapping - 12/28/04 23:00

The code is very short , and if short means more fast to executre no ?
Posted By: Steempipe

Re: Check This Out - Parallax Mapping - 12/29/04 05:04

Quote:

i take it back, still get warping... still testing




This shader requires a fair amount of tweaking depending upon the variables involved. I found no short answer to this... but managed to understand much of what is involded. I may get around to testing it some more when it becomes necessary for the use of the effect.

Quote:

I don´t get it working too. But I think my grafic card doesn´t support it (geforce FX 5600). The model is completly white.


EDIT: I tried now the normal mapping shader, and I have exactly the same problem. The model is white (very light grey).






Try making nofog equal to on, and see what happens.



Quote:

The code is very short , and if short means more fast to executre no ?






Short won't always mean fast. It could be a short code but heavy on the mathes and such. The best thing to do with this shader would be to convert to ASM and look for optimizations and determining if anything can be moved to alpha to utilize a parallel pipe.
Posted By: EX Citer

Re: Check This Out - Parallax Mapping - 12/29/04 18:35

Hello,

Thanks for the help. That was realy the problem. Now the next problem is visible.
1. The texture gets wrapped (if I create a level part out of a model the skin has several textures)
2. the model looks like cola (almost black)

EX Citer
© 2024 lite-C Forums