Fixed Function water?

Posted By: Matt_Aufderheide

Fixed Function water? - 03/26/04 03:48

anyone have an idea how to proceed with a fixed function water effect.. i would assume environmental bump mapping.... but i could never get it to work before..anyone figure that out?
Posted By: ventilator

Re: Fixed Function water? - 03/26/04 04:09

yes, i think environment bump mapping and multitexturing with some scrolling textures would lead to quite good fixed function water effects. the vertices maybe could be moved per script to achieve some waves in the geometry aswell...

but i didn't get environment bumpmapping to work either when i experimented with it a few weeks ago. neither with a fixed function effect nor with a shader. did anyone get it to work?
Posted By: ello

Re: Fixed Function water? - 03/26/04 04:28

there is an example in the directX9 sdk which could be the way. also, i just had a glimpse and will go for it. but as i am not the fastest one here you will find it:

directXsdk-->directX utilities--> effect edit
then go to file--> open and jump one folder up. find the water.fx file and go...

those files just need minimal ajustments from what i see at the moment.
Posted By: Matt_Aufderheide

Re: Fixed Function water? - 03/27/04 18:02

ok .. yes tthat example looks useful.. theres something i dont understand tho-
it calls for two matrices:
matrix mID; // Identity transform
matrix mENV; // Environment map transform

how do i derive these matrices?
Posted By: ello

Re: Fixed Function water? - 03/29/04 09:05

i tried some other, like matWorldViewProj; and matView; also matMtl; somehow its going into the right direction.
maybe some userdefined skills including the entities orientation and talking about setting up matrixes how can i set BUMPENVMAT00/01/10/11 with some dynamic floatvalues? in the dx example there are values like F2DW(0.0f); how do i get this into the fixed function pipeline?
Posted By: Matt_Aufderheide

Re: Fixed Function water? - 03/29/04 22:15

ok ive gotten environmental bump mapping to work.. here is the code:

Code:
function mtl_env_view()
{
mat_set(mtl.matrix,matViewInv);
// reset the translation part of the matrix
mtl.matrix41 = 0;
mtl.matrix42 = 0;
mtl.matrix43 = 0;

// mat_scale(mtl.matrix,0.5,0.5,0.5);
}

function mtl_water_init
{
vec_set(mtl.emissive_blue,mat_model.emissive_blue);
vec_set(mtl.ambient_blue,mat_model.ambient_blue);
vec_set(mtl.diffuse_blue,mat_model.diffuse_blue);
vec_set(mtl.specular_blue,mat_model.specular_blue);
mtl.power=mat_model.power;
mtl.albedo=mat_model.albedo;
bmap_to_cubemap(mtl.skin3);
mtl.enable_render=on;
mtl.event=mtl_env_view;
}

bmap water = <water_1.tga>;
bmap caustic = <water_1_caustic.tga>;
bmap enviromap = <envmap+6.tga>;

material mat_water
{
event=mtl_water_init;
skin1=water;
skin2=caustic;
skin3=enviromap;

effect=
"
texture mtlSkin1;
texture mtlSkin2;
texture mtlSkin3;
matrix matMtl;
matrix matWorld;

technique envcube
{
pass p0
{
Lighting = True;
SpecularEnable = True;

ADDRESSU[0]=wrap;
ADDRESSV[0]=wrap;
ADDRESSU[1]=wrap;
ADDRESSV[1]=wrap;
ADDRESSU[2]=wrap;
ADDRESSV[2]=wrap;


// Stage0
MinFilter[0] = Linear;
MagFilter[0] = Linear;
MipFilter[0] = Point;


Texture[0] = <mtlSkin1>;
//TextureTransform[0] = <matWorld>;
//TextureTransformFlags[0] = Count2;

ColorOp[0] = SelectArg1;
ColorArg1[0] = Texture;
AlphaOp[0] = SelectArg2;
AlphaArg2[0] = Current;

// Stage1
MinFilter[1] = Linear;
MagFilter[1] = Linear;
MipFilter[1] = Point;

Texture[1] = <mtlSkin2>;
// TextureTransform[1] = <matWorld>;
// TextureTransformFlags[1] = Count2;

ColorOp[1] = bumpenvmap;
ColorArg1[1] = Texture;
ColorArg2[1] = Current;
AlphaOp[1] = SelectArg2;
AlphaArg2[1] = Current;


// Stage2
MinFilter[2] = Linear;
MagFilter[2] = Linear;
MipFilter[2] = Point;

Texture[2] = <mtlSkin3>;
TextureTransform[2] = <matMtl>;
TextureTransformFlags[2] = Count3;
TexCoordIndex[2] = cameraspacereflectionvector;

ColorOp[2] = modulate;
ColorArg1[2] = Texture;
ColorArg2[2] = Current;
AlphaOp[2] = SelectArg2;
AlphaArg2[2] = Current;


}
}
";
}


Posted By: Darkstorm

Re: Fixed Function water? - 03/29/04 23:06

What shader version do you need to use this? I get an unsupported error on my GeForce3 but then again I am fairly clueless about shaders.
Posted By: Taros

Re: Fixed Function water? - 03/29/04 23:45

If anyone think this will help them then here you go (it's a combination of dot3 bumpmapping and enviromental mapping:

Code:
    	

bmap bumpmap = <waves.tga>; // add some bumpmap
bmap enviromentmap = <cubecloudy+6.tga>; // cubemap

material mat_bump
{
skin2 = bumpmap; // set the bumpmap
skin3 = enviromentmap;
scale1 = 0.2; // factor for the skin scale at stage 0
// define a material effect string
effect = "
// declare the used textures and variables
texture entSkin1; // the entity skin
texture mtlSkin2; // the bump map
texture mtlSkin3; // the enviroment map
dword mtlSkill1; // the light vector
// default technique
technique bump_dot3
{
pass P0
{
// set texture stage states
Texture[0] = <mtlSkin2>;
Texture[1] = <entSkin1>;
Texture[2] = <mtlSkin3>;
TextureFactor = <mtlSkill1>;
ColorArg1[0] = Texture; // stage 0 = bumpmap
ColorOp[0] = DotProduct3;
ColorArg2[0] = TFactor;
ColorArg1[1] = Texture; // stage 1 - skin texture
ColorOp[1] = AddSigned;
ColorArg2[1] = Current;
texCoordIndex[2]=cameraSpaceReflectionVector;
ColorOp[2] = AddSigned;
ColorArg1[2] = Texture;
ColorArg2[2] = Current;
ColorArg1[3] = Diffuse; // stage 2 - lighting
ColorOp[3] = Modulate2x;
ColorArg2[3] = Current;
}
}

// fallback technique for devices that do not support bumpmapping
technique fallback
{
pass P0
{
// set texture stage states
Texture[0] = <entSkin1>;
ColorArg1[0] = Texture; // stage 0 = skin texture
ColorOp[0] = Modulate2x;
ColorArg2[0] = Diffuse; // modulate by lighting
}
}
"; // end of the effect string
}

starter mat_bump_init {
// initialize the material properties
vec_set(mat_bump.ambient_blue,mat_model.ambient_blue);
vec_set(mat_bump.diffuse_blue,mat_model.diffuse_blue);
vec_set(mat_bump.specular_blue,mat_model.specular_blue);
mat_bump.power = mat_model.power;
// create the normals map for DOT3 bumpmapping
bmap_to_normals(mat_bump.skin2,2);
// set a lighting vector for DOT3 bumpmapping
mat_bump.skill1 = pixel_for_vec(vector(200,200,200),100,8888);
bmap_to_cubemap(mat_bump.skin3);
}

action envbump
{
my.material = mat_bump;
}



Also, if you want to have env. mapping in ps1.1 you can fake it using texbem or texbeml instructions. I almost got it to work (but it lacks color, for now )
Posted By: VoodooFactory

Re: Fixed Function water? - 03/30/04 01:18

Would it also be possible to slide the bumpmap over the model? Just normal UV-shifting I mean.
Posted By: Matt_Aufderheide

Re: Fixed Function water? - 03/30/04 04:58

yeah sure.. just shift the UV values in script by using my.u and my.v
Posted By: Matt_Aufderheide

Re: Fixed Function water? - 03/30/04 05:00

About the unsupported error.. i dont know why it doesnt work on a geforce 3.. maybe it doesnt support environmental bumpmapping..
its a not a shader btw its a fixed function texture effect
Posted By: Darkstorm

Re: Fixed Function water? - 03/30/04 05:05

See I told you I was clueless. Anyway, I wrote an action that assigns "mat_water". That is how you set it up correct? As far the environment mapping, I can get that to work using a different script.
Posted By: Alexander Esslinger

Re: Fixed Function water? - 03/30/04 05:06

TFactor is a DWORD value, not a texture. Maybe that's the problem.
Posted By: ventilator

Re: Fixed Function water? - 03/30/04 05:12

maybe the geforce3 does only support 2 texture stages in the fixed function pipeline? that would explain it... jcl added the number of texture stages to this table -> http://conitecserver.com/wiki/index.php/ShaderSupportOverview it's strange though that 4 stages can be used with pixel shaders on a geforce3.

@matt: where do you set up bumpenvmat? isn't it needed? and why isn't it necessary to convert the bumpmap to a uv-offset map? could you post a screenshot or a demo of that effect?


Posted By: Matt_Aufderheide

Re: Fixed Function water? - 03/30/04 17:09

Yes it could be the geforece 3 dosent have 3 stages.. in this case you will need a 2 stage fallback.. i would then forego the first stage and just use the last two.. that way you will still have the environment bump mapping.

I dont really know what the purpose of bumpenvmat is.. it seems to work ok without setting it up...when i do put it in it doesnt seem to work correctly..
maybe someone can figure it out?

Yeah you probably should convert the the bump map to a normal map.. i just forgot
Posted By: Darkstorm

Re: Fixed Function water? - 03/30/04 20:29

For some reason when I use the code that Taros posted it works. Looks a bit funky but both the bump and the env mapping show up.
Posted By: ello

Re: Fixed Function water? - 03/30/04 21:53

however this looks totally cool. using different textures is a loot of fun. thx for this
Posted By: mk_1

Re: Fixed Function water? - 03/31/04 06:50

Could someone please make a screenshot?
Posted By: Joey

Re: Fixed Function water? - 04/01/04 21:49

@Ello:
how would the code have to be changed to convert it into a two-passes-technique?

JOEY.
Posted By: Joey

Re: Fixed Function water? - 04/04/04 21:52

GeForce 4MX only supports two stages, so would anybody who knows explain how to transform this code into a two-passes-effect? That would be very nice!

Or isn't there anyone who knows how to do it?

JOEY.
Posted By: Marco_Grubert

Re: Fixed Function water? - 04/06/04 11:54

Quote:

What shader version do you need to use this? I get an unsupported error on my GeForce3 but then again I am fairly clueless about shaders.



Since this is not using a pixel/vertex shader there is no version to be concerned about, but I am assuming that GeForce3 lacks support for the "bumpenvmap" texture operation.
Posted By: Steempipe

Re: Fixed Function water? - 04/13/04 09:36

Here's some shots from my water effect "test bed" project.

web page

The shots on this page are using techniques similar to the ones outlined above. It is unfortunate that after many hours of frustration I still do not get enviromapping to look good on anything other than a sphere.

Just thought I'd show what the heck I'm doing with these things since this thread seems to have cooled off.

Anybody else have any cool screens to share???

Eric
Posted By: Templar

Re: Fixed Function water? - 04/13/04 16:06

I think the left EMBM screenshot is absolutely great! Are you going to release source code for this?
Posted By: Steempipe

Re: Fixed Function water? - 04/14/04 09:18

Plan to post something when I get it figured out better. Thanks for the comment.
Posted By: William

Re: Fixed Function water? - 04/14/04 09:28

Totally agreed. The left EBM shot is great!
Posted By: ventilator

Re: Fixed Function water? - 04/24/04 08:58

@steempipe: please post the source of this environment bump mapping effect!



it looks great!

...
no matter what i do i can't get this to work. it drives me crazy! ...i'd have some nice ideas for ice and water effects with environment bump mapping...

...
i know geforce cards can do embm. it's listed under the device caps and i have seen this effect running on my pc (for example the far cry water uses it).
Posted By: Nadester

Re: Fixed Function water? - 04/24/04 09:13

I totally agree! Lol I know that I have been hounding you for it latelly Steempipe.. but who could resist?
Posted By: ventilator

Re: Fixed Function water? - 04/24/04 09:28

Quote:

Currently my chief frustration is that the cubic environment mapping will not work correctly on anything
besides a sphere. This is too bad. However, I am dealing with workarounds on that and learning a little at a time.


show your code and i will tell you the workaround!
Posted By: Steempipe

Re: Fixed Function water? - 04/24/04 10:07

hmmm... that sounds like a deal

Looks like I may have to put a pot of coffee on and edit the code for posting.
Posted By: Drew

Re: Fixed Function water? - 04/24/04 12:36

yes please share!!! the video is so sweet!
Highly impressive.
Posted By: Steempipe

Re: Fixed Function water? - 04/24/04 14:11

Okay.... the published demo is here:

http://steempipe.technicalfoundry.com/water/water.html

There are 3 bodies of water. 2 have different versions of the effect.

Card will need to support EMBM and for one of the effects~ 3 stages/pass. FPS may take a dive with the terrain thing and the 3 waters going on. Since I installed Directx 9, my FPS has been essentially stuck at 58-59. So I really don't know.

Hope that this will give someone an idea or two. I have not screwed with this thing for maybe 2 weeks and did not keep any notes as to where I was with the cubic environment stuff. I did keep an important instruction to the cubic env map in the file, but commented out so I would not forget it. The cameraspacereflectionvector part.

A placeholder for me right now (until the CubeEnvMap) is the cloud specular map that moves with the view. It's going to take a different noise type or specular texture but I am too whacked right now to make one.

Have fun! Make this better, and post the code
Posted By: Nadester

Re: Fixed Function water? - 04/24/04 14:35

Its 2:00am here and I have been waiting for this online since your last post. You are awesome Steempipe - thank you soo much!
Posted By: William

Re: Fixed Function water? - 04/24/04 14:45

Thank you SteemPipe for all your hard work! I will try to improve on this as much as I can.
Posted By: Drew

Re: Fixed Function water? - 04/24/04 15:33

WOW that is nice! thank you
Posted By: ventilator

Re: Fixed Function water? - 04/24/04 17:08

it doesn't work on my geforce4! the water surfaces are just black. does anybody have a gf3/gf4/gffx and this effect shows up? i am sure that nvidia cards support this too somehow!

but thanks for sharing!

here is my explanation why environment mapping doesn't work on flat surfaces:

the vertex normals of flat surfaces all point into the same direction. with fixed function environment mapping the same view vector gets used for the whole object. so the resulting reflection vectors will all point into the same direction too and this causes that always the same pixel of the environment map gets sampled. the surface will be single colored because it shows one pixel only.

the way to do better environment mapping which works on planes is with a vertex shader. you can calculate an individual view vector per vertex:

Code:

texture mtlSkin1;
matrix matWorldViewProj;
matrix matWorld;
vector vecViewPos;

technique environment_mapping
{
pass p0
{
Texture[0]=<mtlSkin1>; // cube map

VertexShaderConstant[0]=<matWorldViewProj>;
VertexShaderConstant[4]=<matWorld>;
VertexShaderConstant[8]=<vecViewPos>;

VertexShader=
decl
{
stream 0;
float v0[3]; //position
float v3[3]; //normal
float v7[3]; //uv
}
asm
{
vs.1.1
m4x4 oPos,v0,c0 // output vertex position to clip space

m4x4 r0,v0,c4 // transform vertex position to world space

sub r0,c8,r0 // calculate view vector
dp3 r0.w,r0,r0 // renormalize it
rsq r0.w,r0.w
mul r0,r0,r0.w

m3x3 r1,v3,c4 // transform vertex normal to world space

// calculate reflection vector
dp3 r2,r1,r0 // n.v
add r3,r1,r1 // 2n
mad oT0,r2,r3,-r0 // 2n(n.v)-v
};
PixelShader=
asm
{
ps.1.1
tex t0
mov r0,t0
};
}
}


Posted By: Zio

Re: Fixed Function water? - 04/24/04 18:54

Quote:

it doesn't work on my geforce4! the water surfaces are just black.




Same thing on my GF3. I figured it was just a GF3 problem, since it seems to not support anything.

But it not working for your GF4 makes me feel a little better, lol. There must be something that needs to be done a little differently.


The screenshots remind me a lot of Morrowinds water, and that works fine on my GF3, so I know it's possible.
Posted By: Zapan@work

Re: Fixed Function water? - 04/24/04 19:43

same here on gf3, gf4 and ati 9800
Posted By: Taros

Re: Fixed Function water? - 04/24/04 20:11

Works great for me, but can kill the framerate (not much but is noteably slower than without it.)

I have a ATI Radeon 9800SE 256-bit modded to ATI Radeon 9800 Pro via Omega drivers
Posted By: Nadester

Re: Fixed Function water? - 04/24/04 21:16

Doesn't work on my Intel Extreme Graphics card. I'm going to see if it works on my Geforce 4 and Radeon 7500 when I get home - hopefully it will work on one of them.
Posted By: Alexander Esslinger

Re: Fixed Function water? - 04/24/04 21:37

...and it doesn't work on a GeForce FX 5900.
Posted By: ventilator

Re: Fixed Function water? - 04/24/04 22:02

@alexander: as far as i know you have experience with direct3d programming. do you get such an effect to work with a simple direct3d application? ...maybe there is something wrong within a6?
Posted By: Steempipe

Re: Fixed Function water? - 04/24/04 22:14

@ventilator: Thanks for posting the cube map code.

Okay... what I have gathered this far is that there is a problem with some cards, maybe mainly GeForce, doing EMBM AND projected vertices at the same time.

Now what??? I have some ideas.... will have to work them out later tonight.
1). One option is to translate to vertex/pixelshader instructions.
2) Could also do a combo FFP and Vertexshader thing.

Here's the thing:
If this demo did not run on your card. Run the DirectX SDK BumpWater.Exe sample and see what it tells you. It tells me that it's running in the fixed-function pipe on my card. If it tells you it's running with a vertexshader, then we have a direction to go.
*Please report* what you find here. I want to translate things and ultimatley have adequate fallback techniques.

For those of us that like to tinker.... the BumpWater.Cpp is going to be our friend here.
Posted By: mk_1

Re: Fixed Function water? - 04/24/04 22:50

Doesn't work on my GF2 MX400 either. Supports EMBM & 3 passes.
Posted By: Dyc

Re: Fixed Function water? - 04/24/04 23:35

No luck on my GF fx 5600
Posted By: ventilator

Re: Fixed Function water? - 04/25/04 00:25

i tried it on a radeon 8500. there it works... but that doesn't help me much!

@steempipe: if you use a projection texture you could try to render an inverted camera view to the bitmap you use for that. i think you would have a realistic reflection of the level then...
Posted By: Drew

Re: Fixed Function water? - 04/25/04 01:17

works great over here... radeon 9600 mobile (m10)
Fun stuff!

Ventilator- wouldn't using a render view to texture make this a pro ver. only shader? hope not...

Posted By: ventilator

Re: Fixed Function water? - 04/25/04 02:35

yes, it would be pro only then. ...but i think this is what they do in far cry so it would be worth a try!
Posted By: pocorev

Re: Fixed Function water? - 04/25/04 02:52

very nice!!! thanks for sharing this.

btw, every time i run the demo it reboots my computer after aprox. 45 seconds to a minute.
Posted By: William

Re: Fixed Function water? - 04/25/04 03:06

All I can see is 1 body of water, and it looks spectacular! 128MB Radeon 9800. BTW - Isn't there supposed to be 3 bodies of water? Thanks.
Posted By: Steempipe

Re: Fixed Function water? - 04/25/04 04:52

Correct, there should be (3) bodies of water. Are you seeing the one if you walk to the right? I am curious as to which effect file you are seeing.

@pocorev: Man, that is worse than just seeing black! Can't even begin to speculate on that one.

Looks like~ TextureTransformFlags[1] = count3 | projected; ~ is out of the question for most cards. Think I go out, cut the grass, and ponder this for awhile.
Posted By: Taros

Re: Fixed Function water? - 04/25/04 05:13

yes i only see one of the waters, the bright blue on the left..
Posted By: William

Re: Fixed Function water? - 04/25/04 06:14

I only see the bright blue one on the left too.
Posted By: Marco_Grubert

Re: Fixed Function water? - 04/25/04 16:12

Same thing here: one pool of water to the far end which has bumps and environment map. Card: Radeon 9700.
© 2023 lite-C Forums