I've been trying to convert an ATI OceanWater Shader and i think i'm almost done, but when i run my level i get this error: mat_water(73):syntax error.
Sure it says syntax error but i can't find where (i know it's supposed to be in the 73. line of code but it isn't
). So i'm gonna post my conversion here and hope that somebody will find the error i'm looking for.
-------------------------------------------------------------------------------
// Note: Vertexshader 1.1 and Pixelshader 1.4 needed.
// Converted from ATI Ocean Water Shader
// Conversion by Taros
bmap gradient = <oceangradient.bmp>;
bmap waterbump = <waterbump3.bmp>;
bmap enviroment = <cubecloudy+6.tga>;
MATERIAL mat_water
{
Skin1 = waterbump;
Skin2 = gradient;
Skin3 = enviroment;
flags = tangent;
effect=
"
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;
matrix matViewInv;
vector vecSunDir;
vector vecDiffuse;
vector vecViewPos;
vector vecAmbient;
vector vecLight;
vector vecFog;
vector vecTime;
vector vecSkill41;
texture mtlSkin1; //Bump
texture mtlSkin2; //Gradient
texture mtlSkin3; // Cubemap
technique water
{
pass p0
{
Texture[0]=<mtlSkin1>; // Bump
Texture[1]=<mtlSkin1>; // Bump
Texture[2]=<mtlSkin3>; // Enviroment
Texture[3]=<mtlSkin2>; // Gradient
minFilter[0]=linear;
magFilter[0]=linear;
minFilter[1]=linear;
magFilter[1]=linear;
minFilter[2]=linear;
magFilter[2]=linear;
minFilter[3]=linear;
magFilter[3]=linear;
Cullmode = 0;
zWriteEnable = false;
//////////////////////////////////////////////////////
//////////////////////////////////////////////////////
// Vertex Shader Constants
// v0 - Vertex Position
// v3 - Vertex Normal
// v7 - Vertex Texture Data u,v
// v8 - Vertex Tangent (v direction)
// v5 - Wave Height Scale
//
// c0 - { 0.0, 0.5, 1.0, 2.0}
// c1 - { 4.0, .5pi, pi, 2pi}
// c2 - {1, -1/3!, 1/5!, -1/7! } //for sin
// c3 - {1/2!, -1/4!, 1/6!, -1/8! } //for cos
// c4-7 - Composite World-View-Projection Matrix
// c8 - ModelSpace Camera Position
// c9 - ModelSpace Light Position
// c10 - {fixup factor for taylor series imprecision, }(1.02, 0.1, 0, 0)
// c11 - {waveHeight0, waveHeight1, waveHeight2, waveHeight3} (80.0, 100.0, 5.0, 5.0)
// c12 - {waveOffset0, waveOffset1, waveOffset2, waveOffset3} (0.0, 0.2, 0.0, 0.0)
// c13 - {waveSpeed0, waveSpeed1, waveSpeed2, waveSpeed3} (0.2, 0.15, 0.4, 0.4)
// c14 - {waveDirX0, waveDirX1, waveDirX2, waveDirX3} (0.25, 0.0, -0.7, -0.8)
// c15 - {waveDirY0, waveDirY1, waveDirY2, waveDirY3} (0.0, 0.15, -0.7, 0.1)
// c16 - { time, sin(time)}
// c17 - {basetexcoord distortion x0, y0, x1, y1} (0.031, 0.04, -0.03, 0.02)
// c18 - World Martix
vertexShaderConstant[0]={0.0f, 0.5f, 1.0f, 2.0f};
vertexShaderConstant[1]={4.0f, .5pi, pi, 2pi};
vertexShaderConstant[2]={1, -1/3!, 1/5!, -1/7!};
vertexShaderConstant[3]={1/2!, -1/4!, 1/6!, -1/8!};
vertexShaderConstant[4]=<matViewInv>;
vertexShaderConstant[5]=<matViewInv>;
vertexShaderConstant[6]=<matViewInv>;
vertexShaderConstant[7]=<matViewInv>;
vertexShaderConstant[8]=<vecViewPos>;
vertexShaderConstant[9]=<vecLight>;
vertexShaderConstant[10]={1.02f, 0.1f, 0f, 0f};
VertexShaderConstant[11]={80.0f, 100.0f, 5.0f, 5.0f};
VertexShaderConstant[12]={0.0f, 0.2, 0.0f, 0.0f};
VertexShaderConstant[13]={0.2f, 0.15f, 0.4f, 0.4f};
VertexShaderConstant[14]={0.25f, 0.0f, -0.7f, -0.8f};
VertexShaderConstant[15]={0.0f, 0.15f, -0.7f, 0.1f};
VertexShaderConstant[16]={vecTime, sin(vecTime), 0f, 0f};
vertexShaderConstant[17]={0.031f, 0.04f, -0.03f, 0.02f};
vertexShaderConstant[18]=<matWorld>;
///////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////
// Pixel Shader Constants
//c0 - Common Const (0, 0.5, 1, 0.25)
//c1 - highlightColor (0.8, 0.76, 0.62, 1)
PixelShaderConstant[0]={0f, 0.5f, 1f, 0.25f};
PixelShaderConstant[1]={0.8f, 0.76f, 0.62f, 1f};
///////////////////////////////////////////////////////////
vertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v5[3]; //Wave Height Scale
float v7[2]; //uv
}
asm
{
vs.1.1
mul r0, c14, v7.x // use tex coords as inputs to sinusoidal warp
mad r0, c15, v7.y, r0 // use tex coords as inputs to sinusoidal warp
mov r1, c16.x //time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to frequency
add r0, r0, c12 // starting time offset
frc r0.xy, r0 // take frac of all 4 components
frc r1.xy, r0.zwzw //
mov r0.zw, r1.xyxy //
mul r0, r0, c10.x // multiply by fixup factor (due to inaccuracy)
sub r0, r0, c0.y // subtract .5
mul r0, r0, c1.w // mult tex coords by 2pi coords range from(-pi to pi)
mul r5, r0, r0 // (wave vec)^2
mul r1, r5, r0 // (wave vec)^3
mul r6, r1, r0 // (wave vec)^4
mul r2, r6, r0 // (wave vec)^5
mul r7, r2, r0 // (wave vec)^6
mul r3, r7, r0 // (wave vec)^7
mul r8, r3, r0 // (wave vec)^8
mad r4, r1, c2.y, r0 //(wave vec) - ((wave vec)^3)/3!
mad r4, r2, c2.z, r4 // + ((wave vec)^5)/5!
mad r4, r3, c2.w, r4 // - ((wave vec)^7)/7!
mov r0, c0.z //1
mad r5, r5, c3.x ,r0 //-(wave vec)^2/2!
mad r5, r6, c3.y, r5 //+(wave vec)^4/4!
mad r5, r7, c3.z, r5 //-(wave vec)^6/6!
mad r5, r8, c3.w, r5 //+(wave vec)^8/8!
sub r0, c0.z, v5.x //... 1-wave scale
mul r4, r4, r0 // scale sin
mul r5, r5, r0 // scale cos
dp4 r0, r4, c11 //multiply wave heights by waves
mul r0.xyz, v3, r0 //multiply wave magnitude at this vertex by normal
add r0.xyz, r0, v0 //add to position
mov r0.w, c0.z //homogenous component
m4x4 oPos, r0, c4 // OutPos = ObjSpacePos * World-View-Projection Matrix
mul r1, r5, c11 //cos* waveheight
dp4 r9.x, -r1, c14 //normal x offset
dp4 r9.yzw, -r1, c15 //normal y offset and tangent offset
mov r5, v3 //starting normal
mad r5.xy, r9, c10.y, r5 //warped normal move nx, ny according to
//cos*wavedir*waveeheight
mov r4, v8 //tangent
mad r4.z, -r9.x, c10.y, r4.z //warped tangent vector
mov r10, r5
m3x3 r5, r10, c18 // transform normal
dp3 r10.x, r5, r5
rsq r10.y, r10.x
mul r5, r5, r10.y //normalize normal
mov r10, r4
m3x3 r4, r10, c18 // transform tangent
dp3 r10.x, r4, r4
rsq r10.y, r10.x
mul r4, r4, r10.y //normalize tangent
mul r3, r4.yzxw, r5.zxyw
mad r3, r4.zxyw, -r5.yzxw, r3 //xprod to find binormal
mov r10, r0
m4x4 r0, r10, c18 // transform vertex position
sub r2, c8, r0 //view vector
dp3 r10.x, r2, r2
rsq r10.y, r10.x
mul r2, r2, r10.y //normalized view vector
mov r0, c16.x
mul r0, r0, c17.xyxy
frc r0.xy, r0 //frc of incoming time
add r0, v7, r0 //add time to tex coords
mov oT0, r0 //distorted tex coord 0
mov r0, c16.x
mul r0, r0, c17.zwzw
frc r0.xy, r0 //frc of incoming time
add r0, v7, r0 //add time to tex coords
mov oT1, r0.yxzw //distorted tex coord 1
mov oT2, r2 //pass in view vector (worldspace)
mov oT3, r3 //binormal
mov oT4, r4 //tangent
mov oT5, r5 //normal
};
pixelShader=
asm
{
ps.1.4
texld r0, t0 //bump map 0
texld r1, t1 //sample bump map 1
texcrd r2.rgb, t2 //View vector
texcrd r3.rgb, t3 //Binormal
texcrd r4.rgb, t4 //Tangent
texcrd r5.rgb, t5 //Normal
add_d2 r0.xy, r0, r1 //Scaled Average of 2 bumpmaps xy offsets
mul r1.rgb, r0.x, r3
mad r1.rgb, r0.y, r4, r1
mad r1.rgb, r0.z, r5, r1 //Put bumpmap normal into world space
dp3 r0.rgb, r1, r2 //V.N
mad r2.rgb, r1, r0_x2, -r2 //R = 2N(V.N)-V
mov_sat r1, r0_x2 //2 * V.N (sample over range of 1d map!)
phase
texld r2, r2 //cubic env map
texld r3, r1 //Index fresnel map using 2*V.N
mul r2.rgb, r2, r2 //Square the environment map
+mul r2.a, r2.g, r2.g //use green channel of env map as specular
mul r2.rgb, r2, 1-r0.r //Fresnel Term
+mul r2.a, r2.a, r2.a //Specular highlight ^4
add_d4_sat r2.rgb, r2, r3_x2 //+= Water color
+mul r2.a, r2.a, r2.a //Specular highlight ^8
mad_sat r0, r2.a, c1, r2 //+= Specular highlight * highlight color
};
} // end of pass
} // end of technique
";
}
starter mat_water_init
{
bmap_to_cubemap(mat_water.skin3);
bmap_to_normals(mat_water.skin1,2);
}
action water_setting
{
my.material = mat_water;
} // end
-------------------------------------------------------------------------------
Also, how do i setup this vecTime vector i need for the c16 vertexshaderconstant?
Thank you for your time