Ocean Water Shader

Posted By: oliver2s

Ocean Water Shader - 01/18/04 20:23

I have converted the Ocean Water Shader from ATI's Rendermonkey into 3DGS. It works very fine. But it was very hard to find a texture which looks very good in this shader.



1.) Here is the Material:
Code:
MATERIAL mat_oceanwater
{
flags = tangent;

effect
"
matrix matWorldViewProj;
matrix matWorld;
matrix matWorldView;

texture entSkin1; //first skin is a water texture
texture entSkin2; //second skin is a normalmap
texture entSkin3; //third skin is a texture with blue colors

vector vecSkill41;

technique oceanwater
{
pass p0
{
Texture[0] = <entSkin2>;
Texture[1] = <entSkin2>;
Texture[2] = <entSkin1>;
Texture[3] = <entSkin3>;

VertexShaderConstant[0]={0f,0.5f,1f,2f};
VertexShaderConstant[1]={0.85f,1.7f,3.14f,6.28f};
VertexShaderConstant[2]={0f,0f,0f,0f};
VertexShaderConstant[3]={0.5f,-0.04167f,0.00139f,-0.00002f};
VertexShaderConstant[4]=<matWorldViewProj>;
VertexShaderConstant[8]={0f,0f,0f,1f};
VertexShaderConstant[9]={0f,0f,0f,1f};
VertexShaderConstant[10]={0.98f,0.003f,0f,0f};
VertexShaderConstant[11]={0f,0f,0f,0f};
VertexShaderConstant[12]={0f,0.2f,0f,0f};
VertexShaderConstant[13]={0.45f,0.1f,0.221f,0.04f};
VertexShaderConstant[14]={6.22f,-2.2f,0.55f,2.12f};
VertexShaderConstant[15]={4f,-2.33f,2.5f,0f};
VertexShaderConstant[16]=<vecSkill41>;
VertexShaderConstant[18]={0.1f,0.1f,0.1f,0.1f};
VertexShaderConstant[19]={0.05f,0.055f,0f,1f};
VertexShaderConstant[90]={1f,0f,0f,0f}; //damit oFog gefüllt ist

PixelShaderConstant[1]={0.129f,0.415f,0.864f,0.839f};

VertexShader =
decl
{
stream 0;
float v0[3]; //Position
float v3[3]; //Normal
float v7[3]; //Textur Koordinaten 0
float v8[3]; //Textur Koordinaten 0
}
asm
{
vs.1.1

mul r0, c14, v7.x
mad r0, c15, v7.y, r0

mov r1, c16.x // time...
mad r0, r1, c13, r0 // add scaled time to move bumps according to freq
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 // mul by fixup (due to inaccuracy)
sub r0, r0, c0.y // subtract 0.5
mul r0, r0, c1.w // mul 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, c0.x //... 1-wave scale
mul r4, r4, r0 // scale sin
mul r5, r5, r0 // scale cos

dp4 r0, r4, c11 // mul by wave heights

mul r0.xyz, v3, r0 // mul wave mag 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 = ObjSpace * World-view-proj matrix

mul r1, r5, c11 // cos * wave height
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*waveheight
mov r4, v8 // tangent
mad r4.z, -r9.x, c10.y, r4.z // warped tangent vector

dp3 r10.x, r5, r5 // normalize the normal
rsq r10.y, r10.x
mul r5, r5, r10.y

dp3 r10.x, r4, r4 // normalize the tangent
rsq r10.y, r10.x
mul r4, r4, r10.y

mul r3, r4.yzxw, r5.zxyw // xprod to find binormal
mad r3, r4.zxyw, -r5.yzxw, r3


mov r6, c8 // get eye pos into object space
m4x4 r2, r6, c20

sub r2, r2, r0 // find view vector

dp3 r10.x, r2, r2 // normalize view vector
rsq r10.y, r10.x
mul r2, r2, r10.y

mov r0, c16.x
mul r0, r0, c18.xyxy
frc r0.xy, r0 // frac of incoming time
add r0, v7, r0 // add time to tex coords
mov oT0, r0 // output tex coords

mov r0, c16.x
mul r0, r0, c18.zwzw
frc r0.xy, r0 // frac of incoming time
add r0, v7, r0 // add time to tex coords
mov oT1, r0.yxzw // output distorted tex coord1

mov oT2, r2 // pass in view vector (world space)
mov oT3, r3 // tangent
mov oT4, r4 // binormal
mov oT5, r5 // normal
mov oFog,c90
};
pixelshader=
asm
{
ps.1.4

def c0, 0.5, 0.5, 0.5, 1.0;

texld r0, t0 // bump map 0
texld r1, t1 // bump map 1
texcrd r2.rgb, t2 // view vec
texcrd r3.rgb, t3 // tangent
texcrd r4.rgb, t4 // binormal
texcrd r5.rgb, t5 // normal

add_d4 r0.xy, r0_bx2, r1_bx2 // scaled avg of 2 bumpmap xy offsets

mul r1.rgb, r0.x, r3 // put bump maps into world space
mad r1.rgb, r0.y, r4, r1
mad r1.rgb, r0.z, r5, r1

dp3 r0.rgb, r1, r2 // V.N
mad r2.rgb, r1, r0_x2, -r2 // R = 2N(V.N)-V

mov_sat r0.rgb, r0_x2 // 2 * V.N (sample over range of 1D map)

phase

texld r2, r2 // env map
texld r3, r0 // index frenel map using 2*N.V

mul r2.rgb, r2, r2 // square env map
+mul r2.a, r2.g, r2.g // use green of env as specular
mul r2.rgb, r2, 1-r0.r // fresnel term
+mul r2.a, r2.a, r2.a // specular ^4

add_d4_sat r2.rgb, r2, r3_x2 // += water color
+mul r2.a, r2.a, r2.a // specular ^8

mad_sat r0, r2.a, c1, r2
};
}
}

technique fallback
{
pass p0
{
TEXTURE[0] = <entSkin1>;
COLOROP[0] = modulate;
}
}
";
}



2.) Here is the Action for the water entity:
Code:

var count;

ACTION water_fx
{
my.material = mat_oceanwater;
while(1)
{
my.skill41=float(count);
my.skill42=float(0);
my.skill43=float(0);
my.skill44=float(0);
count += 0.005*time; //U Texcoord
wait(1);
}
}



3.) Here is my water model with the 3 textures you need:
water.mdl

The shader needs Vertexshader 1.1 and Pixelshader 1.4.
Posted By: Captain_Kiyaku

Re: Ocean Water Shader - 01/18/04 20:42

hi, sieht einfach genial aus.

würde es auch gerne mal testen, das problem ist immer nur, wenn man die texte aus dem "code" auflistung kopiert und dann irgendwo einfügt, wird das alles hintereinander aufgelistet, und das ist nervig alles wieder untereinander zu machen.

Also könntest du den code bitte ohne diese "code" tags hier rein kopieren oder als textdatei? Wäre dir sehr dankbar ^^

Cu
Posted By: oliver2s

Re: Ocean Water Shader - 01/18/04 20:48

Here is the complete code in a wdl file, because there are some troubles with copy and paste the code:

water_fx.wdl
Posted By: Captain_Kiyaku

Re: Ocean Water Shader - 01/18/04 20:53

thx!!
Posted By: Zio

Re: Ocean Water Shader - 01/18/04 21:16

This looks very nice! The screenshot looks alot like Morrowind's water, which leads me to my question...

I have a GeForce 3, which only has VS 1.1 and PS 1.1, so I can't use this shader. However, like I said, the result looks alot like Morrowind's water, and I can see that perfectly fine. So I assume that basicly the same effect can be done with PS 1.1 instead of 1.4. I don't have a bit of skill or knowledge when it comes to shaders, so I'm only guessing here.

Would it be possible to edit this and get nearly the same effect with PS 1.1? I'd love to have Morrowind style water in 3DGS!


Thanks for posting this. Even though I can't use it, I still love to see all these cool shaders getting shared.
Posted By: oliver2s

Re: Ocean Water Shader - 01/18/04 21:27

@A c e: I would edit the shader so that he can used with PS 1.1, but I have no shader knowledge to make this. I can only convert existing shaders into 3DGS and no write or edit shaders.
Posted By: Shurik

Re: Ocean Water Shader - 01/19/04 01:37

I have GeForce4, pixel shaders supports 1.3 for me this not work

RenderMonkey looks great soft, for NVidia cards have soft like this?
Posted By: qwerty823

Re: Ocean Water Shader - 01/19/04 07:54

Looks like your c2 is wrong. c2 and c3 are taylor series values for calculating sin/cos in the shader. Also, you should probably include more significant digits for .5 pi, pi, and 2 pi, to give a more accurate representation. Same thing with the factorals in the taylor series. Also, and im not 100% sure about this, but in your action, you should probably change the 2nd skin to a normal map (using bmap_to_normals). I have a slightly different ATI demo for water shading that also incorporates an environment map as well (to give sky reflections in the water) that I was trying to convert (with little luck), but now that this one works, maybe Ill see if i can get the reflection stuff added in (no promises). Id also like to see the c11 - c15 constants get replaced by using the mtl matrix and mtl skills so that they can be tweaked at run time (maybe via a panel, hmm.. i see a water studio coming for this effect) so you can get just the right water look.

Edit: Here is the link for the OceanWater shader i was talking about.
Posted By: ventilator

Re: Ocean Water Shader - 01/19/04 08:39

i wish i had an ati card! ...i tried to convert this shader to ps 1.3 but didn't have much success. i didn't get the environment bumpmapping and some other things to work. my version looks very crappy and soapy...
Posted By: TimeOut

Re: Ocean Water Shader - 01/19/04 23:18

The Water looks very nice. But I Cant use it, because I have a Geforce 4 Grafik Card.
Posted By: Zapan@work

Re: Ocean Water Shader - 01/20/04 04:29

This thing is really slow...
Posted By: old_bill

Re: Ocean Water Shader - 01/20/04 04:32

Könntest du das bitte mal publishen, nur das Wasser, würd ich mir gerne mal ansehen!

old_bill
Posted By: oliver2s

Re: Ocean Water Shader - 01/20/04 04:54

@Zapan: auf meinem System läuft es ziemlich schnell. Ich hab 132 Frames mit dem Shader + Levelgeometrie.

@old_bill: Hier ist der Wassershader: Published Ocean Water
Posted By: Drew

Re: Ocean Water Shader - 01/20/04 05:42

VERY COOL! Thanks guys
especially forputting it into a wdl and posting a demo...
Posted By: Rhuarc

Re: Ocean Water Shader - 01/20/04 08:14

*distant scream of agony* My crappy video card doesn't support vertex shaders... heh I guess it's time to go tack another $100 on a new video card to go with my new $400 pc upgrade package

Shot looks great, I'm sure with some work on the skin and such it would really look nice.

-Rhuarc
Posted By: oliver2s

Re: Ocean Water Shader - 01/20/04 19:24

In Antwort auf:

I'm sure with some work on the skin and such it would really look nice.




oh yes, It is very hard to find a good looking texture for this shader, but I'm sure that some people can create a great texture for this shader.
Posted By: old_bill

Re: Ocean Water Shader - 01/21/04 00:50

Danke Oliver2s!

Nur scheint der Shader auf meiner GF4 ti 4600 nicht zu laufen, das Wasser ist animiert,
aber nix mit Shader...

old_bill
Posted By: DJ_SPHYX

Re: Ocean Water Shader - 01/21/04 01:05

THNX for putting up the demo but when i want to run it there is the error:
CAN'T COMPILE SCRYPT!
What can i do?

Greetings
DJ_SPHYX
Posted By: oliver2s

Re: Ocean Water Shader - 01/21/04 01:10

In Antwort auf:

THNX for putting up the demo but when i want to run it there is the error:
CAN'T COMPILE SCRYPT!
What can i do?





This code works only in A6.2 Com/Pro or above.
Posted By: DJ_SPHYX

Re: Ocean Water Shader - 01/21/04 01:12

Ummm O.K
Thats too high for me
But the screen looks cool!!!
DJ_SPHYX
Posted By: Ix

Re: Ocean Water Shader - 01/23/04 20:52

geht das mit jeder version von a6?
sieht echt extrem geil aus.

greetz, daniel
Posted By: Steempipe

Re: Ocean Water Shader - 01/30/04 07:43

First of all thanks for the shader! This will bring many hours of enjoyment AND frustrations! ;}

But man, I am trying to learn these things little by little and have spent the better part of how many days trying to do one thing with poor results. That is make the fog work like in the terrain multitexturing shader.

Anyone have any solutions for us shader newbies?

The terrain below shows the fog like I set it up in the main WDL as far as color and fog ranges. But I cannot get the water model to do that.


Posted By: ventilator

Re: Ocean Water Shader - 01/30/04 15:26

you have to handle the fog in the vertex shader and output the fog value of each vertex to oFog. here is an example -> http://www.conitecserver.com/ubbthreads/showflat.php?Cat=&Number=298311&page=0&view=collapsed&sb=5&o=&fpart=1&vc=1
Posted By: Steempipe

Re: Ocean Water Shader - 01/30/04 17:41

Thanks! I'll look at your shader closer and do some more research.

Posted By: MrFreakMan

Re: Ocean Water Shader - 03/28/04 02:15

english:
Hi the shader looks very good

How can i use it with geforce 4 garphic cards ?

deutsch:
Hi der shader sieht einfach Hammer aus

Wie can ich den mit der geforce 4 Grafikkarte
benutzen
Posted By: thermalheat

Re: Ocean Water Shader - 05/13/05 12:22

Oliver2s or anyone who has downloaded and still have a copy of the water.mdl, could you please mirror the file? Because the link no longer works.

Many thanks in advance
Posted By: william_123

Re: Ocean Water Shader - 05/19/05 06:15

Because the link no longer works.
http://web108.webbox180.server-home.net/3DGS/water.zip
http://web108.webbox180.server-home.net/3DGS/water_fx.wdl

anyone who has downloaded and still have a copy

Many thanks in advance
Posted By: anime

Re: Ocean Water Shader - 03/10/06 10:06

Hi. Tried to download your mdl file, but was not allowed. also where do I get the shaders you mention? Vertexshader 1.1 and Pixelshader 1.4.
Posted By: Damarus

Re: Ocean Water Shader - 03/10/06 22:38

can someone post a new link this one doesnt work either.
Posted By: Sebe

Re: Ocean Water Shader - 03/10/06 22:50

Forget this water shader guys, there are much better ones. And btw, Vertex- and Pixelshader are no software, so you can't "get" them (except in a hardware store @_@)
Posted By: Damarus

Re: Ocean Water Shader - 03/11/06 20:14

i like that shader and i just wanna see how it looks like just post these two links again i would like it thx.
© 2024 lite-C Forums