Shader Based Water Fx

Posted By: myrlyn68

Shader Based Water Fx - 10/02/03 04:18

As opposed to hijacking a post (my bad Ventilator...) a new thread should be created.

The demo found here on ATI's website should be easy enough to do with 3DGS. While I haven't seen any realease notes other then the Beta for the A6 shaders, all the commands used are pretty standard. The biggest benefit here, is the bump mapping (to create waves) and then applying a bit of a pixel shader on the high spots. It gives a very nice appearance.

To really sweeten the pot, you will also want to take a look at this (password required). It will allow you to take the light from the surface - refract it through your wave patterns and generate the light/dark spots on the floor of your body of water. Unfortunately the procedure used there does require DX9. Not that big of a deal though, as it can be done with a few tweaks using DX8 compatable shaders.

Granted since I don't have the Beta, I can't really say what is fully supported with A6 shaders, but I am assuming that it will have no problems with standard DX functions. Just something for you guys to run with while we wait.
Posted By: ventilator

Re: Shader Based Water Fx - 10/02/03 05:50

the problem is that most ati shaders use pixelshader version 1.4 which is much more powerful than version 1.3! so this effect would have to be simplified for geforce3/4 cards. and the current beta doesn't yet support environment cube textures. i think they are needed for good water effects.
Posted By: cbw

Re: Shader Based Water Fx - 10/02/03 07:52

Think it might be possible though Ventilator?
Posted By: ventilator

Re: Shader Based Water Fx - 10/02/03 08:43

sure, it will be possible to use that shader but only with ati (or dx9) cards! one of the next betas will support environment cube textures... but i think for geforce3/4 cards you will have to use a simpler pixelshader. i have seen impressive water on geforce3/4 cards too though!
Posted By: Marco_Grubert

Re: Shader Based Water Fx - 10/03/03 04:25

Here's my favorite water screenshot, but I don't know if it is real-time:
http://www.peroxide.dk/era/screenshots/Work%20in%20Progress/Coastline.jpg

I don't see why the ATI algorithm should not work with earlier PS versions as well. The tricky part will be having real-time environment maps that contain models and not just the sky.
Posted By: ventilator

Re: Shader Based Water Fx - 10/03/03 05:30

the muddy water is nice! ...i only had a quick look at the ati shader. it uses 2 phases and more than 8 arithmetic commands so i thought it needs simplifications for 1.3. but i haven't tried to understand it yet!

Quote:

The tricky part will be having real-time environment maps that contain models and not just the sky.


i think that's only tricky for jcl. for doing the shader it will be no difference?
Posted By: cbw

Re: Shader Based Water Fx - 01/03/04 07:36

So I got the Shader ATI used in their nature demo, but for some reason it doesn't work. It's DX 8.0, but it just gives me errors.

Any help?

matrix matWorldViewProj;
matrix matWorldView;

technique water
{
pass p0
{
ZWriteEnable=true;
AlphaTestEnable=true;
CullMode=none;



VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[2]; //uv
}
asm
{
vs.1.1
mul r0, c14, v7.x
mad r0, c15, v7.y, r0

mov r1, c16.x
mad r0, r1, c13, r0
add r0, r0, c12
frc r0.xy, r0
frc r1.xy, r0.zwzw
mov r0.zw, r1.xyxy

mul r0, r0, c10.x

sub r0, r0, c0.y
mul r0, r0, c1.w

mul r5, r0, r0
mul r1, r5, r0
mul r6, r1, r0
mul r2, r6,r0
mul r7, r2, r0
mul r3, r7, r0
mul r8, r3, r0

mad r4, r1, c2.y, r0
mad r4, r2, c2.z, r4
mad r4, r3, c2.w, r4

mov r0, c0.z
mad r5, r5, c3.x, r0
mad r5, r6, c3.y, r5
mad r5, r7, c3.z, r5
mad r5, r8, c3.w, r5

dp4 r0, r4, c11

mul r0.xyz, c0.xxzx, r0
add r0.xyz, r0, v0
mov r0.w, c0.z

m4x4 oPos, r0, c4

mul r1, r5, c11
dp4 r9.x, -r1, c14
dp4 r9.yzw, -r1, c15
mov r5, c0.xxzx
mad r5.xy, r9, c10.y, r5

mov r4, v9
mad r4.z, -r9.x, c10.y, r4.z
dp3 r10.x, r5, r5
rsq r10.y, r10.x
mul r5, r5, r10.y

dp3 r10.x, r4, r4
rsq r10.y, r10.x
mul r4, r4, r10.y
mul r3, r4.yzxw, r5.zxyw
mad r3, r4.zxyw, -r5.yzxw, r3
sub r1, c9, r0
sub r2, c8, r0
dp3 r10.x, r1, r1
rsq r10.y, r10.x
mul r1, r1, r10.y
dp3 r6.x, r1, r3
dp3 r6.y, r1, r4
dp3 r6.z, r1, r5
dp3 r10.x, r2, r2
rsq r10.y, r10.x
mul r2, r2, r10.y

dp3 r7.x, r2, r3
dp3 r7.y, r2, r4
dp3 r7.z, r2, r5

mov r0, c16.x
mul r0, r0, c24
frc r0.xy, r0
mul r1, v7, c26

add oT0, r1, r0
mov r0, c16.x
mul r0, r0, c25
frc r0.xy, r0
mul r1, v7, c27

add oT1, r1, r0
dp4 r0.x, v0, c20
dp4 r0.y, v0, c21
dp4 r0.zw, v0, c22

mov oT2, r0

mov oT3, r7
mov oT4, v7
mov oT5, r6
};

PixelShader=
asm
{
ps.1.4
texld r0, t0
texld r1, t1

texcrd r2.xy, t2_dw.xyw
texcrd r4.xyz, t3
texcrd r5.xyz, t5

add_d2 r1.rgb, r0_bx2, r1_bx2

mov r3.xy, r2

dp3 r0.r, r4, r1
dp3 r0.g, r1, r5

mad_sat r5.rg, r1, c2, r3
mad_sat r4.rg, r1, c1, r3

phase

texcrd r0.rgb, r0

texld r2, r4
texld r3, r5

mul_sat r2.rgb, r3, c3
+mul r2.a, r0.g, r0.g

mul_sat r3.rgb, r3, c4
+mul_sat r2.a, r2.a, r2.a

mad_sat r0.rgb, 1-r0.r, r2, r3
+mul_sat r2.a, r2.a, r2.a

mad_sat r0.rgb, r2.a, c6, r0
+mov r0.a, r0.r
};
}
}

Posted By: MaxF

Re: Shader Based Water Fx - 01/12/04 02:16

Hi All

I opened the Project/Solution in MS Visual Studio and got errors after compiling, opened it in MSVS 6.0 and it was fine.

It's looks GREAT, How can one set this up in 3DGS, I know which parts are shaders and which are C++.

Do we have a tutorial on "how to implementation shaders in 3dGS", I can't fine one on here?
Posted By: VoodooFactory

Re: Shader Based Water Fx - 01/17/04 03:36

Is there anyone who's actually made a working watershader? Using environment mapping and bumbmapping for example.
Posted By: cbw

Re: Shader Based Water Fx - 01/18/04 03:49

apparently the shader above works, it's just my video card doesn't support it, try it out.
Posted By: VoodooFactory

Re: Shader Based Water Fx - 01/18/04 21:46

Great! But I'm new to the whole shader thing; could you also give me a simple action to use it on a model?
Posted By: Thomas_Nitschke

Re: Shader Based Water Fx - 01/29/04 21:52

Hi,
to implement the code by cbw just try this
Code:
 
material mat_water
{
effect = ""; // the shader code goes here
}

action act_waterMdl
{
my.material = mat_water;
//and so on
}


As far as I'm concerned this should work well, if else please let me know...
© 2024 lite-C Forums