I know it's very seldom that I post in the artists forum, but when I do it, it's really urgent as you might guess
For a week or so I have been learning HLSL now and I'm really happy to do so
But yesterday I found something very interesting about offsetmapping at the forums and had a look on it...
http://www.ogre3d.org/phpBB2/viewtopic. ... setmap+zip
I recognised that the shader code of this example is completely written in ASM (which I really never used till yesterday), so with the help of M$DN's ASM command list, I started to convert the ASM code to HLSL.
Here's the whole code of the OpenGL example:
Code: Select all
!!ARBfp1.0
PARAM light0color = state.light[0].diffuse;
PARAM light1color = state.light[1].diffuse;
PARAM ambient = state.lightmodel.ambient;
TEMP eyevects;
TEMP rgb, height, temp, bump, total;
TEMP light0tsvec, light1tsvec;
TEMP newtexcoord;
# normalize tangent space eye vector
DP3 temp, fragment.texcoord[3], fragment.texcoord[3];
RSQ temp, temp.x;
MUL eyevects, fragment.texcoord[3], temp;
# calculate offset
TEX height, fragment.texcoord[0], texture[2], 2D;
MAD height, height, 0.03, -0.015; # scale and bias
MAD newtexcoord, height, eyevects, fragment.texcoord[0];
# get texture data
TEX rgb, newtexcoord, texture[0], 2D;
# normalize the light0 vector
DP3 temp, fragment.texcoord[1], fragment.texcoord[1];
RSQ temp, temp.x;
MUL light0tsvec, fragment.texcoord[1], temp;
# add light0 color
MUL_SAT total, light0tsvec.z, light0color;
# normalize the light1 vector
DP3 temp, fragment.texcoord[2], fragment.texcoord[2];
RSQ temp, temp.x;
MUL light1tsvec, fragment.texcoord[2], temp;
# add light1 color
MUL_SAT temp, light1tsvec.z, light1color;
ADD_SAT total, total, temp;
# add ambient lighting
ADD_SAT total, total, ambient;
MUL_SAT result.color, rgb, total;
END
VS:
Code: Select all
float4x4 matViewProjection;
float4 vViewPosition;
struct VS_INPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float2 Texcoord : TEXCOORD0;
float3 viewPosition : TEXCOORD1;
};
VS_OUTPUT vs_main( VS_INPUT Input )
{
VS_OUTPUT Output;
Output.Position = mul( matViewProjection, Input.Position );
Output.Texcoord = Input.Texcoord;
Output.viewPosition = normalize(vViewPosition - Input.Position);
return( Output );
}Code: Select all
sampler2D RGB_map;
sampler2D HEIGHT_map;
struct PS_INPUT
{
float2 Texcoord : TEXCOORD0;
float3 viewPosition : TEXCOORD1;
};
float4 ps_main( PS_INPUT Input ) : COLOR0
{
float2 height;
float2 new_TexCoords;
height = tex2D ( HEIGHT_map, Input.Texcoord) * 0.03 -0.015;
new_TexCoords = height * Input.viewPosition + Input.Texcoord;
return tex2D( RGB_map, new_TexCoords );
}[edit]: don't mention that I left the light part away
many thanks



