|
FFP / VertexShader Water Code
#27395
05/15/04 07:36
05/15/04 07:36
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
OP
Serious User
|
OP
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
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); }
}
|
|
|
Re: FFP / VertexShader Water Code
[Re: Steempipe]
#27396
05/15/04 07:38
05/15/04 07:38
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
OP
Serious User
|
OP
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
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; }
|
|
|
Re: FFP / VertexShader Water Code
[Re: Steempipe]
#27398
05/15/04 07:59
05/15/04 07:59
|
Joined: Dec 2003
Posts: 1,097 Maryland, USA
Steempipe
OP
Serious User
|
OP
Serious User
Joined: Dec 2003
Posts: 1,097
Maryland, USA
|
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);}
}
|
|
|
Re: FFP / VertexShader Water Code
[Re: William]
#27401
05/17/04 04:37
05/17/04 04:37
|
Joined: Jan 2002
Posts: 1,276 trapped in a paper bag
Drew
Serious User
|
Serious User
Joined: Jan 2002
Posts: 1,276
trapped in a paper bag
|
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
|
|
|
|