Man.... water is good to drink, but hard to make.

Posted By: Steempipe

Man.... water is good to drink, but hard to make. - 02/24/04 12:53

I have been screwing around with 2 types of water shaders. An ocean type and one for pool/river type things.

It is going, well, fair.... I guess.

For now I just have a few screens to post and hopefully I can get this thing ironed out and post the code.

http://steempipe.technicalfoundry.com/water/watershader.htm

Anyone else getting any progress made on a water shader?? Frustrating.

Time to sleep.........



Posted By: William

Re: Man.... water is good to drink, but hard to make. - 02/24/04 14:57

Thats awsome! I wish I could see it in action.
Posted By: ello

Re: Man.... water is good to drink, but hard to make. - 02/24/04 16:57

hey, it isnt that bad. if there is motion it will look all good.
i am curious to see your code, to learn and play with it...
Posted By: tesanders

Re: Man.... water is good to drink, but hard to ma - 02/24/04 17:07

That looks very nice; I'd also like to see more, (esp. a video).
Posted By: Templar

Re: Man.... water is good to drink, but hard to ma - 02/24/04 19:30

[gulp] - I've been waiting for something like this for ages! Can't wait to see it in action!
Posted By: Steempipe

Re: Man.... water is good to drink, but hard to make. - 02/25/04 06:35

In the event that I do not get any service calls to run out to tonight, I plan on cleaning up the code files. Right now they are in utter chaos. Many, many lines of commented out bits and pieces of things. They are very confusing right now. Almost as confused as I am!!!

The shader is PS.1.4 , but I hope to see if PS.1.1-1.3 can do the same.

Fraps does not want to record my screen for some reason. Wish it would.

I have played with various methods and have not had the absolute affect that I am seeing in my minds-eye. This is where I hope that we can all make something great out of this.

Methods I have been playing with are:
-alpha transparency
-reflections
-ripple simulation
-whether to use a MDL or an HMP.
-What bumpmaps to use
-What scales to use
-etc, etc, etc.

I know very little about Gamestudio C-script and even less about DirectX and shader programming. This water situation has been a good way of "getting thrown to the wolves" and learning.

I'll get things posted as soon as I can and thanks for the interest!
Posted By: Nadester

Re: Man.... water is good to drink, but hard to make. - 02/25/04 07:35

That looks decent. How about some enviromental mapping though? Would look even nicer.
Posted By: Steempipe

Re: Man.... water is good to drink, but hard to make. - 02/25/04 11:04

@Nadester: Thats a good point you make about using an environment map, hope to work on that in the future.

Here is a demo of the shader (approx 3.8MB download) . I call it riverwater. The requirements are PS14 & VS11.
Tested on ATI Radeon 9200 128MB with Gstudio A6.20.2 Comm.

See the readme.txt in the ZIP.

If anyone has any additions, fixes, or comments please post!!! This shader has a long way to go.

Eric



Posted By: VoodooFactory

Re: Man.... water is good to drink, but hard to make. - 02/25/04 17:03

That actually looks pretty cool, especially from upclose. But as been said, environment mapping would add infinitely to it.
Posted By: Steempipe

Re: Man.... water is good to drink, but hard to make. - 03/20/04 23:37

Okay. Updated the screenshots to the current views. Slow progress and still not anywhere near what I have in my mind.

Just a "progress report" and a bump in the hopes that someone else has some
news to report regarding these water type shaders. I would be curious how anyone else is addressing the water problems.

http://steempipe.technicalfoundry.com/water/watershader.htm

I would really like to add environments reflections and things, but I fear that those are a bit down the road as I am attempting to learn these things and trial and error is my only teacher right now.

I will probably not spend much time on ocean type shaders because I really only want to use river and pool type things.

**the archive above still has the old build**

Eric
Posted By: Taros

Re: Man.... water is good to drink, but hard to make. - 03/22/04 06:25

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
Posted By: Shurik

Re: Man.... water is good to drink, but hard to make. - 03/23/04 00:10

mat_riverwater syntax error

Posted By: Taros

Re: Man.... water is good to drink, but hard to make. - 03/23/04 05:47

Yep, tried it. Doesn't work. I also tried to use some other methods, but nothing. Guess i'm too much of a noob (for now ). I'll keep trying, no sense in giving up.

But i must say, this water looks really really good even without env. mapping.
Posted By: BlueFireV2

Re: Man.... water is good to drink, but hard to make. - 03/23/04 06:11

Yeah, you did a great job with the water,but might want to not have waves, seems to slow down the game for me.
Posted By: Steempipe

Re: Man.... water is good to drink, but hard to make. - 03/23/04 11:50

I have uploaded (2) different files. The effect is quite different than the first riverwater demo at the beginning of this thread.

It is still necessary to have pixelshader 1.4 and vertexshader 1.1.

Each file is about 2.8MB and as follows:
riverwater without waves
riverwater with waves

@Taros: Yah... I tried, fiddled with different things and could not get the envmap thing to work right. I am with you and am not going to give up. It's frustrating at times, but this is how we learn. Thanks for the contrib and the words.

@Num1BushFan: I have not gotten anything optimized yet. I hope to get some things figured out and optimized as such as I learn more. In case it helps for performance on someones machine, a version without mesh deforming is avail.

Later,
Eric



Posted By: BlueFireV2

Re: Man.... water is good to drink, but hard to make. - 03/23/04 12:21

I just tried the one without waves, it's pretty nice, it's a little faster but about the same as the other one. I dunno, I have a Geforce FX 128mb something or another and it's just a weird card...could just be my PC too.
Posted By: VoodooFactory

Re: Man.... water is good to drink, but hard to make. - 03/24/04 01:40

Well, it's improved over the first one, but I think that it would look better if you made the water shapes(kinda hard to explain, the reflections?) a lot bigger. The water looks very realistic if you look at it when you're right above it, but further away, it looks crap.
Posted By: Steempipe

Re: Man.... water is good to drink, but hard to make. - 03/24/04 09:01

I know what you mean by your explanation. It is important that you and others notice and mention these things. Sometimes in the scope of frustration and such it may go unnoticed to me. This helps keep things in focus for me.

I have fiddled with different textures, texture stage changes, and am trying to digesting as much info about shaders as I can to learn what instructions I should be using and how to make them work. I was hoping that there would be some additional changes and/or versions from other users as well.

I have tried to use VEC_DIST operations based on the player-to-the-object distance to pass info to the vertex shader. For example, when near to the water the textures are scaled smaller. When the player is far away, then the textures are scaled larger. This has it's own problems of being quite noticable when the change takes place.

As a basic example, the action modified to this:
///////////////////////////////////////////
if (vec_dist(my.x, player.x) < 100)
{
my.skill43=float(5); //z
my.skill44=float(3); //w
}
if (vec_dist(my.x, player.x) > 101)
{
my.skill43=float(1); //z
my.skill44=float(1); //w
}
////////////////////////////////////////

Then the vertex shader was changed to this:
////////////////////////////////////////
// Compute texture coordinates for 1st noise texture
mul r1, r0, c11
frc r1.xy, r1
mad oT1, v7, c14.zzzz, r1.xyxy


// Time
mov r0, c41.x

// Compute texture coordinates for 2nd noise texture
mul r1, r0, c12
frc r1.xy, r1
mad oT2, v7, c15.wwww, 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, c14.zzzz, r1.xyxy


Good luck and thanks for any input that you have to give.

Eric

Posted By: VoodooFactory

Re: Man.... water is good to drink, but hard to make. - 03/24/04 16:23

Can't seem to get it working, but I don't know much about programming. Perhaps you could also try to have an environment shader when you're further away, that would fade to this shader when you're closer to it...

Also, it's really noticable that one of texturemap stays in one place all the time.
Posted By: Darkstorm

Re: Man.... water is good to drink, but hard to make. - 03/25/04 09:59

Just a heads up to any of you guys who want to make a quick buck. I need various water shaders that are ps1.1 compatible.

thread link

Thanks.
© 2024 lite-C Forums