Hey that shader is cool
Keep up the good work.
I kinda modified your shader but i couldn't test it. I just added the ventilator's enviromental mapping shader as another pass, but i can't guarantee it'll work cause i'm a newbie to shader programing.
-------------------------------------------------------------------------------
bmap water = <water.tga>;
bmap waternoise = <waternoise.bmp>;
bmap enviroment = <mornsky+6.tga>; // Enviromental cube map
MATERIAL mat_riverwater
{
Skin1 = water;
Skin2 = waternoise;
Skin3 = enviroment;
effect=
"
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
vector vecSunDir;
vector vecDiffuse;
vector vecAmbient;
vector vecLight;
vector vecFog;
vector vecSkill41;
texture mtlSkin1; //Water
texture mtlSkin2; //Noise
texture mtlSkin3; //Enviromental map
technique riverwater
{
pass p0
{
Texture[0]=<mtlSkin1>; // Texture
Texture[1]=<mtlSkin2>; // Noise Texture
Texture[2]=<mtlSkin2>; // Noise Texture
Texture[3]=<mtlSkin2>; // Noise Texture
ALPHATESTENABLE= true;
ALPHAFUNC=NOTEQUAL;
ALPHAREF= 0x00;
ALPHABLENDENABLE= true;
SRCBLEND=SRCALPHA;
DESTBLEND= INVSRCALPHA;
Cullmode=1;
zWriteEnable=true;
magFilter[0]=linear;
minFilter[0]=linear;
mipFilter[0]=linear;
//ADDRESSU[0]=wrap;
//ADDRESSV[0]=wrap;
magFilter[1]=linear;
minFilter[1]=linear;
mipFilter[1]=linear;
//ADDRESSU[1]=wrap;
//ADDRESSV[1]=wrap;
magFilter[2]=linear;
minFilter[2]=linear;
mipFilter[2]=linear;
//ADDRESSU[2]=wrap;
//ADDRESSV[2]=wrap;
magFilter[3]=linear;
minFilter[3]=linear;
mipFilter[3]=linear;
//ADDRESSU[3]=wrap;
//ADDRESSV[3]=wrap;
//////////////////////////////////////////////////////
// Vertex Shader Constants
// c0..c3 - MVP
// c11.xy - scroll speed 1
// c12.xy - scroll speed 2
// c13.xy - scroll speed 3
// c14.xy - scale 1
// c15.xy - scale 2
// c16.xy - scale 3
// c41.x - time
vertexShaderConstant[0]=<matWorldViewProj>;
vertexShaderConstant[4]=<matWorld>;
vertexShaderConstant[8]=<matWorldView>;
// scroll speed - change as needed with model scaling
VertexShaderConstant[11]={0.0f, 1.0f, 0.0f, 0.0f};
VertexShaderConstant[12]={0.0f, -1.2f, 0.0f, 0.0f};
VertexShaderConstant[13]={1.0f, 1.5f, 0.0f, 0.0f};
// scale - change according to model scaleing
VertexShaderConstant[14]={2.0f, 2.0f, 0.0f, 0.0f};
VertexShaderConstant[15]={3.0f, 3.0f, 0.0f, 0.0f};
VertexShaderConstant[16]={4.0f, 4.0f, 0.0f, 0.0f};
vertexShaderConstant[17]=<vecSunDir>;
vertexShaderConstant[18]=<vecDiffuse>;
vertexShaderConstant[19]=<vecAmbient>;
vertexShaderConstant[20]=<vecLight>;
vertexShaderConstant[21]=<vecFog>;
// time
VertexShaderConstant[41]=<vecSkill41>;
vertexShaderConstant[95]=(0.0f,0.0f,0.0f,0.0f);
///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// Pixel Shader Constants
// distortion (pertrubation factors)
PixelShaderConstant[1]={0.3f, 0.2f, 0.0f, 0.0f};
PixelShaderConstant[2]={0.1f, 0.3f, 0.0f, 0.0f};
PixelShaderConstant[3]={0.1f, 0.1f, 0.0f, 0.0f};
// hight-based bias and scale
PixelShaderConstant[4]={0.5f, 0.1f, 0.0f, 0.0f};
///////////////////////////////////////////////////////////
vertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //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
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
// Pass base texture coordinates
mov oT0, v7
// Time
mov r0, c41.x
// Compute texture coordinates for 1st noise texture
mul r1, r0, c11
frc r1.xy, r1
mad oT1, v7, c14.xyxy, r1.xyxy
// Time
mov r0, c41.y
// Compute texture coordinates for 2nd noise texture
mul r1, r0, c12
frc r1.xy, r1
mad oT2, v7, c15.xyxy, r1.xyxy
// Time
mov r0, -c41.x
// Compute texture coordinates for 3rd noise texture
mul r1, r0, c13
frc r1.xy, r1
mad oT3, v7, c16.xyxy, r1.xyxy
};
pixelShader=
asm
{
ps.1.4
// Pass base texture coordinates
texcrd r0.rgb, t0
// Fetch noise
texld r1, t1
texld r2, t2
texld r3, t3
// noise0 * disamount0
mul r1.rgb, c1, r1_bx2
// noise1 * disamount1 + noise0 * disamount0
mad r1.rgb, c2, r2_bx2, r1
// noise2 * disamount2 + noise1 * disamount1 + noise0 * disamount0
mad r1.rgb, c3, r3_bx2, r1
// Scale and bias y coord of base map based on height
+mad r0.a, 1-r0.g, c4.x, c4.y
// Multiply distortion by scaled biased y coord
mad r1.rgb, r1, r0.a, r0
phase
// Perturb
texld r0, r1
};
{
pass p1
{
texture[0]=<mtlSkin1>;
texture[1]=<mtlSkin3>;
zWriteEnable=true;
alphaBlendEnable=false;
colorArg1[0]=Texture;
colorOp[0]=Modulate2x;
colorArg2[0]=Diffuse;
colorArg1[1]=Texture;
colorOp[1]=AddSigned; //blendCurrentAlpha if this doesn't work
addressU[1]=Clamp;
addressV[1]=Clamp;
texCoordIndex[1]=cameraSpaceReflectionVector;
// textureTransformFlags[1]=Count3;
// textureTransform[1]=<matMtl>; // transform camera space back to world space
}
} // end of pass
} // end of technique
";// end of effect
} // end of material
starter mat_riverwater_init
{
// Need to create MipMaps for the mtlSkins
bmap_to_mipmap(mat_riverwater.skin1);
bmap_to_mipmap(mat_riverwater.skin2);
// Create the CubeMap for the shader
bmap_to_cubemap(mat_riverwater.skin3);
}
-------------------------------------------------------------------------------
Hope it works. Now i must learn physics, i have a test tommorow
. Good night