FFP / VertexShader Water Code

Posted By: Steempipe

FFP / VertexShader Water Code - 05/15/04 07:36

Hopefully someone can get this to work on all cards. And hopefully they will post it!
After getting the EMBM to appear on all cards the envirmonment map still needs to be projected like "CameraSpaceRelflexionVector". I think that the NVidia SDK/Effects browser has a vertexshader that is an implementation of "CameraSpaceRelflexionVector". Something to keep in mind. Also, ventilators vertexshader for mapping the thing to a plane may be of help.
There is also something that is not working right with the texcoord of "envmap"??

This is essentially the minimal code that runs on my ATI Radeon 9200

Code:
 ////////////////////////////////////////////////////////
// Environment Mapping Bump Mapping Water
//
// This is the bare minimum that runs on my ATI Radeon 9200
//
////////////////////////////////////////////////////////


bmap waterbump = <waterbump.bmp>; // Some B&W bumpmap texture 24bpp
bmap baseskin = <water1.bmp>; // Just a colormap

function mtl_ffpwater_init()
{

bmap_to_mipmap(mtl.skin1);
bmap_to_mipmap(mtl.skin2);

bmap_to_normals(mtl.skin1,1);//0.2
//bmap_to_uv(mtl.Skin1);
mtl.enable_view = on;

}


material mtl_ffpwater
{
skin1=waterbump;
skin2=baseskin;

event = mtl_ffpwater_init;

effect = "


matrix matWorldViewProj;
matrix matViewInv;

vector vecSkill41;

texture mtlSkin1;
texture mtlSkin2;

technique makewater
{

pass p0
{
zwriteenable=true;
zenable=true;

AlphaBlendEnable = false;


/////////////////////////////////////////
// stage 0 /
/////////////////////////////////////////
Texture[0] = <mtlSkin1>;

magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;

AddressU[0]=wrap;
AddressV[0]=wrap;

ColorArg1[0] = Texture;
ColorOp[0] = BUMPENVMAP;//LUMINANCE;

ColorArg2[0] = current;

BUMPENVLSCALE[0]=0.5;
BUMPENVLOFFSET[0]=0.5;

TextureTransformFlags[0]=count2;
TexCoordIndex[0]=0;

///////////////////////////////////////
// stage 1
///////////////////////////////////////
Texture[1] = <mtlSkin2>;

magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;

ColorArg1[1] = Texture;
ColorOp[1] =selectarg1;

TextureTransformFlags[1]=count2;
TexCoordIndex[1]=1;


colorop[2] = disable;
alphaop[2] = disable;


vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matViewInv>;


// scroll speed
VertexShaderConstant[11]={0.09f, 0.04f, 0.0f, 0.0f};
VertexShaderConstant[12]={-0.5f, 0.2f, 0.0f, 0.0f};

// scale
VertexShaderConstant[14]={0.4f, 0.6f, 0.0f, 0.0f};
VertexShaderConstant[15]={1.5f, 1f, 0.0f, 0.0f};

// time
VertexShaderConstant[41]=<vecSkill41>;


vertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //uv
}

asm
{

vs.1.1

m4x4 oPos,v0,c0


//dp3 r0.x, v3, c4
//dp3 r0.y, v3, c5
//dp3 r0.z, v3, c6

//dp3 r0.w, r0, r0
//rsq r0.w, r0.w
//mul r0, r0, r0.w

mov r0, c41.x
mul r1, r0, c12
frc r1.xy, r1
mad oT1.xy, v7.xy, c15.xy, r1.xy


mul r1, r0, c11
frc r1.xy, r1
mad oT0.xy, v7.xy, c14.xy, r1.xy




};





}

}

technique fallback { pass p0 { } }

";
}



var count;

action ffp_water {
my.metal=on;
my.material = mtl_ffpwater;

while(1)
{
my.skill41=float(Count);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);
Count += 0.0015;
wait(1);
}


}


Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/15/04 07:38

And here is the Water_Test_5 that may work on some of the geforce cards:

Read the fine print!!!

Code:
 ////////////////////////////////////////////////////////
// Environment Mapping Bump Mapping Water
//
// This is the code that may have worked on some geforce cards
//
////////////////////////////////////////////////////////

/*
Test 1,2,3,& 4 evidentally showed as black on geforce.

Note: for the troubleshooter's among us: How I got to test 5 was this way:
I took my waterbump.bmp and used ATI's "DUDVMapGenerator" and "NormalMapGenerator".
spit out each version of the waterbump map.
=========================================
Test #1:
=========================================
bmap waterbump = <waterbumpDOT3.tga>; //<<<<< note the texture formats
bmap baseskin = <water1.bmp>;

function mtl_ffpwater_init()
{

//bmap_to_normals(mtl.skin1,1);//0.2
//bmap_to_uv(mtl.Skin1);
mtl.enable_view = on;

}
=========================================
Test #2:
=========================================
bmap waterbump = <waterbumpDUDV.tga>;
bmap baseskin = <water1.bmp>;

function mtl_ffpwater_init()
{

//bmap_to_normals(mtl.skin1,1);//0.2
//bmap_to_uv(mtl.Skin1);
mtl.enable_view = on;

}

=========================================
Test #3:
=========================================
bmap waterbump = <waterbumpDUDV.tga>;
bmap baseskin = <water1.bmp>;

function mtl_ffpwater_init()
{

bmap_to_normals(mtl.skin1,1);//0.2
//bmap_to_uv(mtl.Skin1);
mtl.enable_view = on;

}


=========================================
Test #4:
=========================================
bmap waterbump = <waterbumpDOT3.tga>;
bmap baseskin = <water1.bmp>;

function mtl_ffpwater_init()
{

bmap_to_normals(mtl.skin1,1);//0.2
//bmap_to_uv(mtl.Skin1);
mtl.enable_view = on;

}



=========================================
Test #5:
=========================================

*/

bmap waterbump = <waterbumpDOT3.tga>;
bmap baseskin = <water1.bmp>;

function mtl_ffpwater_init()
{

bmap_to_mipmap(mtl.skin1);
bmap_to_mipmap(mtl.skin2);

//bmap_to_normals(mtl.skin1,1);//0.2

bmap_to_uv(mtl.Skin1);

mtl.enable_view = on;

}


material mtl_ffpwater
{
skin1=waterbump;
skin2=baseskin;

event = mtl_ffpwater_init;

effect = "


matrix matWorldViewProj;
matrix matViewInv;

vector vecDiffuse;
vector vecSkill41;
vector vecSunDir;
vector vecLight;
vector vecSpecular;

texture mtlSkin1;
texture mtlSkin2;

technique makewater
{

pass p0
{
zwriteenable=true;
zenable=true;
zfunc=less;
zbias=0.0;

ditherenable=false;
specularenable=true;
lighting=false;
specularmaterialsource=color2;
diffusematerialsource=Color1;
NormalizeNormals=false;
LocalViewer=True;

alphafunc=less;
AlphaBlendEnable = false;
alphatestenable=false;
alpharef=0x0;

SrcBlend = one;
DestBlend = zero;
blendop=add;

fillmode=solid;

fogenable=false;

cullmode=ccw;
clipping=true;

/////////////////////////////////////////
// stage 0 /
/////////////////////////////////////////
Texture[0] = <mtlSkin1>;

magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;

AddressU[0]=wrap;
AddressV[0]=wrap;

ColorArg1[0] = Texture;
ColorOp[0] = BUMPENVMAPLUMINANCE;
//colorop[0]=bumpenvmap;
ColorArg2[0] = current;
BUMPENVLSCALE[0]=0.8;
BUMPENVLOFFSET[0]=0.0;
TextureTransformFlags[0]=count2;
TexCoordIndex[0]=0;
///////////////////////////////////////
// stage 1
///////////////////////////////////////
Texture[1] = <mtlSkin2>;

magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;

ColorArg1[1] = Texture;
ColorOp[1] =selectarg1;

TextureTransformFlags[1]=count2;
TexCoordIndex[1]=1;


colorop[2] = disable;
alphaop[2] = disable;


vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matViewInv>;


// scroll speed
VertexShaderConstant[11]={0.09f, 0.04f, 0.0f, 0.0f};
VertexShaderConstant[12]={-0.5f, 0.2f, 0.0f, 0.0f};

// scale
VertexShaderConstant[14]={0.4f, 0.6f, 0.0f, 0.0f};
VertexShaderConstant[15]={1.5f, 1f, 0.0f, 0.0f};
vertexShaderConstant[16]=<vecSunDir>;
vertexShaderConstant[17]=<vecDiffuse>;
vertexShaderConstant[19]=<vecLight>;
vertexShaderConstant[18]=<vecSpecular>;
// Diffuse



// time
VertexShaderConstant[41]=<vecSkill41>;


vertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //uv
}

asm
{

vs.1.1

m4x4 oPos,v0,c0



dp3 r0.x, v3, c4
dp3 r0.y, v3, c5
dp3 r0.z, v3, c6

dp3 r0.w, r0, r0
rsq r0.w, r0.w
mul r0, r0, r0.w

dp3 r0,r0,-c16 // normal.light -> lighting constant
mul r0.xyz,r0,c17 // modulate against material diffuse color
add oD0.xyz,r0,c19 // Spit out Diffuse color register

mov oD1, c18 // Spit out Specular Color Register

mov r0, c41.x
mul r1, r0, c12
frc r1.xy, r1
mad oT1.xy, v7.xy, c15.xy, r1.xy


mul r1, r0, c11
frc r1.xy, r1
mad oT0.xy, v7.xy, c14.xy, r1.xy




};





}

}

technique fallback { pass p0 { } }

";
}



var count;

action ffp_water {
my.metal=on;
my.material = mtl_ffpwater;

while(1)
{
my.skill41=float(Count);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);
Count += 0.0015;
wait(1);
}

return;
}



Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/15/04 07:49

And if you recall..... this was the FFP only version that worked on I think all the ATI Radeons(?)

Code:
 ////////////////////////////////////////////////////////
// FFP Environment Mapping Bump Mapping Water
//
// Version 2
//
// Eric Hendrickson-Lambert (Steempipe)
//
////////////////////////////////////////////////////////

////////////////////////////////////////////////////////
// Since at this time I cannot get a cubic Env Map
// to work. I have taken out most references to it
// and used a basic sky texture because it needs
// the cloud noise for the specular
///////////////////////////////////////////////////////

bmap waterbump2 = <waterbump.bmp>;
bmap envspec2 = <sky.tga>; // <skycube+6.tga>;
bmap base2 = <gradient.bmp>;

function mtl_ffpwater2_1()
{

///////////////////////////////////////////////
// Lets make it scroll in some direction
//

mtl.skill1 += time;
mtl.matrix41 = floatd(mtl.skill1,4000);


}

function mtl_ffpwater2_init()
{

mtl.matrix11 = float(1.6);
mtl.matrix22 = float(0.8);

bmap_to_mipmap(mtl.skin1);
bmap_to_mipmap(mtl.skin2);
bmap_to_mipmap(mtl.skin3);

bmap_to_normals(mtl.skin1,0.5);

//bmap_to_cubemap(mtl.Skin2);

mtl.event = mtl_ffpwater2_1;

mtl.enable_view = on;

}


material mtl_ffpwater2
{
skin1=waterbump2;
skin2=envspec2;
skin3=base2;

event = mtl_ffpwater2_init;

effect = "

matrix matMtl;

texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;

technique makewater2
{

pass p0
{

Texture[0] = <mtlSkin3>;

magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;

AddressU[0]=Clamp;
AddressV[0]=Clamp;

ColorArg1[0] = Texture;
ColorOp[0] = modulate;
ColorArg2[0] = diffuse;

alphaop[0]=selectarg1;
alphaarg1[0]=texture;

texcoordindex[0]=1;


Texture[1] = <mtlSkin1>;

magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;

ColorArg1[1] = Texture;
ColorOp[1] = bumpenvmap;
ColorArg2[1] = current;

TextureTransformFlags[1] = Count2;
TextureTransform[1] = <matMtl>;
Texcoordindex[1]=1;


Texture[2] = <mtlSkin2>;

magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;

AddressU[2]=Clamp;
AddressV[2]=Clamp;

ColorArg1[2] = Texture;
ColorOp[2] = Add;
ColorArg2[2] = Current;


TextureTransformFlags[2] =count3 | projected;

texcoordindex[2]= cameraspaceposition | 1; // For cubemap use: cameraspacereflectionvector

}

}

technique fallback { pass p0 { } }

";
}



action ffp_water2 {

my.material = mtl_ffpwater2;

}



Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/15/04 07:59

And last of all... there is the TexBemL shader version that worked on ATI's only, I believe.

Code:
// *************************************************
// * TexBeml Water
// *************************************************

bmap basemap = <water1.bmp>;
bmap bumpmap = <waterbump1.bmp>;


MATERIAL mat_texbeml_water
{
Flags = tangent;

Skin1 = basemap;
Skin2 = bumpmap;


effect=
"

texture mtlSkin1;
texture mtlSkin2;



matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

vector vecSunDir;
vector vecDiffuse;
vector vecAmbient;

vector vecFog;
vector vecSkill41;
vector vecLight;
vector vecViewPos;

Technique bump_spec
{


Pass p0
{

alphablendenable=true;
srcblend=one;
destblend=zero;

texture[0]=<mtlSkin2>;
texture[1]=<mtlSkin1>;


MagFilter[1]=Linear;
MinFilter[1]=Linear;
MipFilter[1]=Linear;
texcoordindex[1]=1;
texturetransformflags[1]=count2;
//BumpEnvMat00[1] = 0.5f;
//BumpEnvMat01[1] = 0.0f;
//BumpEnvMat10[1] = 0.0f;
//BumpEnvMat11[1] = 0.5f;



MagFilter[0]=linear;
MinFilter[0]=linear;
MipFilter[0]=linear;

BUMPENVLSCALE[1]=1.8;
BUMPENVLOFFSET[1]=2.8;

texcoordindex[0]=0;
texturetransformflags[0]=count2;

vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;

VertexShaderConstant[41]=<vecSkill41>;

VertexShaderConstant[11]={0.0f, 0.6f, 0.0f, 0.0f};//0.2
VertexShaderConstant[12]={0.0f, -0.8f, 0.0f, 0.0f};


// scale - change according to model scaleing
VertexShaderConstant[14]={0.8f, 1.5f, 0.0f, 0.0f};//1.5 and 1.2
VertexShaderConstant[15]={1.0f, 1.0f, 0.0f, 0.0f};

vertexShaderConstant[17]=<vecSunDir>;
vertexShaderConstant[18]=<vecDiffuse>;
vertexShaderConstant[19]=<vecAmbient>;
//vertexShaderConstant[20]=<vecLight>;
vertexShaderConstant[21]=<vecFog>;
vertexShaderConstant[95]=(0.0f,0.0f,0.0f,0.0f);

vertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //Tex
float v8[3]; //uv
}



asm
{

vs.1.1


// Transform position
m4x4 oPos, v0, c0

m3x3 r0,v3,c4 // transform normal to world space
dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w

//dp3 r0,r0,-c17 // normal.light -> lighting constant
//mul r0.xyz,r0,c18 // modulate against material diffuse color
//add oD0.xyz,r0,c19 // add environment light

// Time
mov r0, c41.x


// Compute texture coordinates for 1st noise texture
mul r1, r0, c11
frc r1.xy, r1
mad oT0, v7, c14.xyxy, r1.xyxy



// Compute texture coordinates for 2nd noise texture
mul r1, r0, c12
frc r1.xy, r1
mad oT1, v7, c15.xyxy, r1.xyxy


mov r1.w,c21.w // r1.w=1
dp4 r0,v0,c10 // distance to camera position
add r0,r0,-c21.x // distance-fog_start
mad r0.x,-r0.x,c21.z,r1.w // 1-(distance-fog_start)*(1/(fog_end-fog_start))
max oFog.x,r0.x,c95.w // clamp with custom max value


};



pixelShader=
asm
{


ps.1.1

tex t0

texbeml t1, t0
mov r0, t1


}; //end of PS

} //end of pass

} //end of technique

"; //end of effect

} //end of material


starter mat_terrain_multitexture_init

{
//bmap_to_uv(mat_texbeml_water.Skin2);
bmap_to_normals(mat_texbeml_water.Skin2,2);//0.2
bmap_to_mipmap(mat_texbeml_water.skin1);
bmap_to_mipmap(mat_texbeml_water.skin2);

}




var ShaderCount;

ACTION texbeml_water
{
my.material = mat_texbeml_water;

my.transparent=off;



while(1)
{


my.skill41=float(ShaderCount);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);

ShaderCount += 0.0015;
wait(1);}

}


Posted By: Drew

Re: FFP / VertexShader Water Code - 05/15/04 08:22

too cool. THANK YOU!!
Posted By: William

Re: FFP / VertexShader Water Code - 05/15/04 09:12

If only I could rate you 100 stars. Hopefully, you have the Geforce problem figured out(wish I had a Geforce card to help you test).
Posted By: Drew

Re: FFP / VertexShader Water Code - 05/17/04 04:37

loving these shaders...
How would I add transparancy effects to test #5?
Either a full 50% transparancy or even better throgh alpha channel on 32 bit textures? would love to be able to see through the water! thanks
Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/17/04 08:55

That's a good question. Sounds like attempting to figure that out would be a nice project for this week!
Posted By: VoodooFactory

Re: FFP / VertexShader Water Code - 05/18/04 00:35

Probably a dumb question, but which shaders work with the commercial version. I don't believe the the camera_vectorspace thing works with commercial.
Posted By: Guido_Richter

Re: FFP / VertexShader Water Code - 05/18/04 03:13

Thats exactly what I also wanted to ask.
Would be really cool to have transparency.
I also have a new idea, just let my think of it and maybe you will see the result in the future.
Posted By: qwerty823

Re: FFP / VertexShader Water Code - 05/18/04 03:27

While I could be wrong, but I dont think that there a commercial/pro differences with respect to shaders. The differences as to which shaders work and dont is strictly due to graphics cards/drivers.
Posted By: VoodooFactory

Re: FFP / VertexShader Water Code - 05/18/04 04:06

Yeah, but I believe some of these shaders use "CameraSpaceRelflexionVector", which I thin is a Pro only feature. As I uderstand, this feature makes realtime reflection possible.
Posted By: Alkai

Re: FFP / VertexShader Water Code - 05/18/04 05:50

I agree with Qwerty, as in I don't think that there are any differences in shader support between the commercial and pro versions. Nothing in the manual would seem to indicate so.
Posted By: Aaron_H

Re: FFP / VertexShader Water Code - 05/18/04 05:55

Quote:

Yeah, but I believe some of these shaders use "CameraSpaceRelflexionVector", which I thin is a Pro only feature. As I uderstand, this feature makes realtime reflection possible.




Maybe JCL or someone from Conitec would be able to commment on this. Although I can't see them offering a "slimmed down" shaders feature in the commercial edition.
Posted By: qwerty823

Re: FFP / VertexShader Water Code - 05/18/04 06:08

Quote:

Yeah, but I believe some of these shaders use "CameraSpaceRelflexionVector", which I thin is a Pro only feature. As I uderstand, this feature makes realtime reflection possible.




Not quite, It allows you map an environment map onto a surface based on the vector between the objects vertex and the camera. While not quite the same as a realtime reflection (which you'd need to use render to texture to compute the enviroment map in real time), it does give static reflections (like clouds on water).
Posted By: Aaron_H

Re: FFP / VertexShader Water Code - 05/18/04 06:11

Thanks for clearing that up qwerty,
I don't know much about shaders you see.
Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/18/04 10:22

qwerty823 is right on those. The thing that I find interesting is that all the code at the beginning of this thread worked on my ATI. While only the one labelled water_test_5 showed up on the geforce cards. Ventilator and Alkai both ran water_test_1, 2, ,3, ,4 & 5 and _only_ 5 showed up. Now why is it that in 5 I had to pass a DOT3 Normalmap _through_ Gstudio's bmap_to_uv() ?? This I do not know.
I would be curious if one could use the SDK to create the textures like in Microsoft BumpWaves.exe and if it would make a difference on the cards.
Posted By: William

Re: FFP / VertexShader Water Code - 05/18/04 10:33

So the fifth water test is the only one that works with all the Geforce Cards? Thanks.
Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/18/04 10:44

As far as I can tell from different posts... yes #5. I hope that someone who has one of the geforce cards and likes to dabble with code can determine why that is.
Posted By: qwerty823

Re: FFP / VertexShader Water Code - 05/18/04 10:58

Hmm, without going back and looking at how the stages were done, but are you saying you wern't passing a bmap_to_uv()'d bmap in the other shaders? From my test (ill have to dig up the thread), it looked like bmap_to_uv() changes the texture format to D3DFMT_V8U8. I'm wondering if there are cases where ATI will happily use other formats, and nVidia cards are stricter.
Posted By: Steempipe

Re: FFP / VertexShader Water Code - 05/18/04 11:08

Correct... The very 1st post, which works happily on my ATI, took a BMP & passed in through bmap_to_normals.

In the post with test #5, I put the info in comments of what type of texture I used and if I ran it through "bmap_to_whatever". However, each version did work on my ATI.

Bumpwaves.exe generates a V8U8 tex.
Posted By: qwerty823

Re: FFP / VertexShader Water Code - 05/18/04 11:33

When converting using bmap_to_normals(), the resulting texture format is D3DFMT_A8R8G8B8.
© 2024 lite-C Forums