Probleme mit Wassershader

Posted By: Sebe

Probleme mit Wassershader - 08/04/04 20:37

Ich habe folgendes Problem mit terrainbasierenden Wassershadern:

In meinem Level befindet sich ein relativ grosses Meer, bestehend aus einer 1x1 hmp, welche mit Steempipes Rivershader ausgestattet ist. Um den Meeresgrund besser aussehen zu lassen, habe ich kleine Muschelmodels und Algensprites auf den Boden gesetzt. Doch da trat das Problem auf: Die Muscheln waren durch den transparenten Shader (tga) gut sichtbar, verschwanden jedoch, sobald ich mit der Kamera näher als ca. 300 Quants herankam. Warum?

Um herauszufinden, ob es am transparenten TGA der HMP liegt, habe ich dieselbe HMP mit dem auch beim Shader verwendetem transparenten TGA ausgestattet und einfach ohne Shader getestet. Und hier ging es wunderbar; die Models/Sprites unter der HMP waren sichtbar.

Vielleicht weiss einer der Shader-Gurus hier Rat?
Posted By: Blattsalat

Re: Probleme mit Wassershader - 08/05/04 09:06

poste mal den shader code hier den du benutzt...steempipe hat schon etliche versionen von shadern geschrieben
Posted By: Sebe

Re: Probleme mit Wassershader - 08/05/04 16:16

Wie gesagt, ich benutze Steempipes Rivershader, einfach mit etwas anderem Skin sowie leicht angepasster Waternoise... Hier ist der Code (nach dem Shader hätte es noch einen längeren Mesh Deformation Code für die Wellen, den lass ich mal weg)

Code:
 //-----------------------------------------------------------------------------
// Simple Riverwater Shader
//
// For use on transparent pools and streams.
//
// It's a start.... hopefully imoprovements will happen and be posted at
// http://steempipe.technicalfoundry.com
//-----------------------------------------------------------------------------

// Based on ATI's Procedural Fire Shader.
// Rev. 2.23.04.01

// Note: Vertexshader 1.1 and Pixelshader 1.4 needed.

bmap water = <waterdorfumlandpart1.tga>; // Nur um den Strand herum transparent
bmap waternoise= <waternoise.bmp>;

MATERIAL mat_riverwater
{

Skin1 = water;
Skin2 = waternoise;

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

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


};


} // 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);
}


Posted By: Mr Wurm

Re: Probleme mit Wassershader - 08/08/04 19:39

Kennt irgendwer das problem, oder sogar die Lösung?
Posted By: MMike

Re: Probleme mit Wassershader - 08/16/04 10:09

Why i can't see the effect? I just see a black block(the shader) and a bump on it(maybe the bump skin) Does my card support it??
A6 test level screenshot

Halo shader shot

Geforce Fx 5600 256MB? last driver :6.7

And why in other games like halo , shader works perfect the water shader and other shaders, ?
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/16/04 18:29

I'm sure the card suppoorts it... otherwise you would have had "effect not supported".

Is this using the stock textures from the demo of the shader?? If not, it may be more of a scaling and texture issue.

Many games have multiple effects for fallback to support a wide array of cards. Also, they (the coders) have more flexibility in how they program the effects as they are not limited to the same functions we are right now. They have more control over texture coordinates, the streams, and also multipasses, among other things.
Posted By: MMike

Re: Probleme mit Wassershader - 08/16/04 21:54

for example the shaders of water that i download at ur werbsite don't work on my card! i just see the water as black!

And i used my textures for apply the shader above

And BTW what does the line command -emu does?? i read on manual...
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/16/04 23:41

Try this version water and you *may* see other than black. Good luck!
web page

If I recall, I have alpha channels in the riverwater textures.... long time ago so I may be wrong. What happens when you use those textures on your block??

-EMU??? Don't know, never looked into it.
Posted By: MMike

Re: Probleme mit Wassershader - 08/17/04 10:21

it works perfect..so why i see the black thing? in other kinds of shaders?
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/17/04 18:11

Post, or email me (in my profile), the textures you are using. If posting, show the alpha, too.
Posted By: MMike

Re: Probleme mit Wassershader - 08/17/04 22:04

This is the Images...
But... Alpha channel? they don't have !
water :

water Bump:



The files are all TGA but with Bmp is the same..
And the water don't move ! is is static! has no waves! but i can see the bump!

I'm useing a block (wmb) to attach the action with the shader Above!
Posted By: JeremyB

Re: Probleme mit Wassershader - 08/18/04 03:24

I am having the same problem I think. I am using a 32 bit 256x256 targa for the water cahnnel and a 24 bit 256x256 bmp dot3 image for the noise channel. It looks really nice and I can see the ripples of the water, but it is not animated. It looks like something needs to be done with the entities skill41 to cause the animation to happen? I have tried setting it equal to time and incrementing it by time and very small increments in a loop in the entities action. This causes the noise texture to sort of spastically jump, but does not give the smooth animation as you would expect to see. I think I am on the right track here, but a little help would be appreciated . Thanks!
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/18/04 04:07

Okay.... My "water.tga" is this:


The color and the noise is in the RGB channel, but it is also using the tex in the alpha channel to do some scaling of the noise. Also, without it you will not get your transparency to work.

I used a flat terrain to render the effect to.

Depending on the size/scale of your model, you will need to adjust some areas.

First the vertex shader:

For the scaling and the scroll, you only need to concern yourself with the X and Y's.
ex; VertexShaderConstant[11]={X, Y, Z, W}; //First noise texture

<<------The scroll speed of the textures.

If you have a small model then try smaller numbers?? I forget exactly.

Note: The (3) noise textures are derived from the water color texture RGB channels.

// scroll speed - change as needed with model scaling
VertexShaderConstant[11]={0.0f, 1.0f, 0.0f, 0.0f}; //First noise texture
VertexShaderConstant[12]={0.0f, -1.2f, 0.0f, 0.0f}; //Second noise texture
VertexShaderConstant[13]={1.0f, 1.5f, 0.0f, 0.0f}; //Third noise texture


The scale of the (3) noise textures:

// scale - change according to model scaleing
VertexShaderConstant[14]={2.0f, 2.0f, 0.0f, 0.0f}; //First noise tex
VertexShaderConstant[15]={3.0f, 3.0f, 0.0f, 0.0f}; //Second noise tex
VertexShaderConstant[16]={4.0f, 4.0f, 0.0f, 0.0f}; //Third noise tex.

In the action, the part that more or less seeds the vertex shader,
VertexShaderConstant[41]=<vecSkill41>;

Is indeed controlled by this in the action:
again, you may need to dick with it depending on the size of your model.

////////////////////////////////////////////////
var ShaderCount;
var ShaderCount2;


while(1)
{


my.skill41=float(ShaderCount);
my.skill42=float(ShaderCount2);
my.skill43=float(0);
my.skill44=float(0);

ShaderCount += 0.0015;
ShaderCount2 -= 0.0013;

..................................


The junk that you may need to change in the Action for the mesh deforming is, and here we go again, based on the model size:

///////////////////////////////
// I override the skills
my.activate_dist = 3000; //Distance from the player for deformation to start.
my.direction = 3;
my.wave_speed = 1.500;
my.skew_value = 0;

// Depending on the scale of the model the wave size will need adjusting.
// For instance, ff you scale the model up huge, then decrease wave size

my.wave_size = 0.06; //random(0.06)-0.06;
my.crests_per_unit = 10;

////////////////////////////////////////////

So really, depending on the model size you will need to tinker. Just plug some numbers ans see what happens. It will take tweaking because many factors.

Eric
Posted By: JeremyB

Re: Probleme mit Wassershader - 08/18/04 04:20

Ha ha! That is excellent! Thank you it works perfectly. What a beautiful effect. I was only updating skill41. I am new to GS, so let me see if I get this straight.

VertexShaderConstant[41]=<vecSkill41>;

So c41 now points to skill41. So when you use c41.x later does that just offset the pointer to point to skill42? And why set skill43 and 44 to 0? I don't see how they are used in the shader.

Also, when you say you override the skills for the following variables:
activate_dist
direction
wave_speed
skew_value
wave_size
crests_per_unit

does that correspond to skill1-6?

Thank you for all of your patient and generous help!
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/18/04 04:40

Skill41-44 are what we are given by Conitec to interact with the vectors in a vertexshader.

vector vecSkill41; // vector(X, Y, Z, W)

vertexShaderConstant(41)= <vecSkill41>;

my.skill41=float(ShaderCount); //X
my.skill42=float(ShaderCount2); //Y
my.skill43=float(0); //Z
my.skill44=float(0); //W

c41.x is saying to use the x component of the vector. c41.y is saying to use the y component of the vector.

Here we are sending the X of c41 to a register for use in multiplying.
// Time
mov r0, c41.x

So, if we send 13.2 thru <my.skill41> and 16.4 thru <my.skill42> then

vertexShaderConstant(41)= <vecSkill41>;

would look like this to the effect:

vertexShaderConstant(41)= {13.2f, 16.4f, 0, 0};


Your right, c43 and c44 are not used here. They were during expirimenting but not at final. Guess they carried over.


If you define things, the wave skills that I over-rode, would be used in the skills box. I just edit the text and run as I was working on this and had no need to really use the skills properties box. But yes, you are right.

Eric
Posted By: MMike

Re: Probleme mit Wassershader - 08/18/04 15:33

Man i'm not getting it to work..!

Can someone post the sample code to just paste there to see if it workS?

I assign different skin values, and nothing...

Where i define the skills?? And I have this;:

action River {

var ShaderCount;
var ShaderCount2;
while(1){

my.skill41=float(ShaderCount);
my.skill42=float(ShaderCount2);
my.skill43=float(0);
my.skill44=float(0);

ShaderCount += 0.0015;
ShaderCount2 -= 0.0013;





My.skill1=5;// activation dsic
My.skill2= 2; //directions
My.skill3=2; //wave speed
My.skill4= 3; //skwel value
My.skill5=20; //wave size
my.skill6= 2; //crests_per_unit
my.material=mat_riverwater;


wait(1);
}






But the effect look abit weird.. like waves too small
}



And It has no transparency!..How can this be done?
Posted By: DARKLORD

Re: Probleme mit Wassershader - 08/18/04 22:29

Könnten wir nochmal zum eigentlichen Problem zurückkehren (Modells werden mit Shader unter Wasser nicht angezeigt)?
Ich habe nähmlich auch dieses Problem und wäre dankbar für eine Lösung.
Posted By: JeremyB

Re: Probleme mit Wassershader - 08/19/04 00:12

First, this part:

My.skill1=5;// activation dsic
My.skill2= 2; //directions
My.skill3=2; //wave speed
My.skill4= 3; //skwel value
My.skill5=20; //wave size
my.skill6= 2; //crests_per_unit
my.material=mat_riverwater;

should not be in the loop. The material only needs to be assigned once, before you go into the loop, and the other values as well. You can adjust the size of the waves in the shader by changing the following values. I think if you want to use the skills to affect the values, you will have to change the shader to use them. Right now it seems they are hardcoded. Change the following line to affect the wave size:

// 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};

You only need to change x and y. The smaller the number, the larger the waves.
Posted By: MMike

Re: Probleme mit Wassershader - 08/19/04 04:12


What those number do?

Like I will give this Variable for bettter understand:
VertexShaderConstant[14]={x, y, A, B};

" VertexShaderConstant[14]={2.0f, 2.0f, 0.0f, 0.0f}; "
What does the A and B does?
Posted By: JeremyB

Re: Probleme mit Wassershader - 08/19/04 04:28

As far as I can tell, the script uses the noise texture as three separate "layers". You can get a nice effect by using a different scale and speed for each layer. So:

// 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};

Think of 14 as layer 1, 15 layer 2, and 16 layer 3. You want to use a different scale in each layer to get a more interesting effect. I am using:

VertexShaderConstant[14]={0.1f, 0.1f, 0.0f, 0.0f};
VertexShaderConstant[15]={0.2f, 0.2f, 0.0f, 0.0f};
VertexShaderConstant[16]={0.3f, 0.3f, 0.0f, 0.0f};

How did I get the numbers? Just by messing with them. There is no formula, just find some that look nice.
I also modified my action to make the animation time based instead of frame based:

var ShaderCount;
var ShaderCount2;
action water_shader
{
bmap_to_mipmap(mtl_water.skin1);
bmap_to_mipmap(mtl_water.skin2);
my.material = mtl_water;

while(1)
{
my.skill41=float(ShaderCount);
my.skill42=float(ShaderCount2);

ShaderCount += time;//0.0015;
ShaderCount2 -= time;//0.0013;
wait(1);
}
}

And then I can set the speed here:

// scroll speed - change as needed with model scaling
VertexShaderConstant[11]={0.0001f, 0.001f, 0.0f, 0.0f};
VertexShaderConstant[12]={0.001f, -0.002f, 0.0f, 0.0f};
VertexShaderConstant[13]={0.002f, 0.003f, 0.0f, 0.0f};

And it runs the same rate no matter the what the frame rate is. Again, it is just by trial and error that you will discover the values that work for you. Try a really big number and really small number and see the effect. Just remember that you have really four layers that are interacting to create the final effect (3 layers for the noise and 1 for the base texture).
Posted By: MMike

Re: Probleme mit Wassershader - 08/19/04 04:41

okay thax..it help .. But What does the :
eg:
1st var does and the 3.0f and the 0.0f and then 0.0f ..They correspond to what?

VertexShaderConstant[15]={3.0f, 3.0f, 0.0f, 0.0f};

Another thing.. Can i get the water slower! it goes too fast!
Changed to this but stills fast:

VertexShaderConstant[11]={0.0001f, 0.001f, 0.0f, 0.0f};
VertexShaderConstant[12]={0.0001f, -0.0002f, 0.0f, 0.0f};
VertexShaderConstant[13]={0.0002f, 0.0030f, 0.0f, 0.0f};




And How can I put the water transparent!?? Tryed with alpha map ..but i didn't work!

Thax For your help again :P
Posted By: Thomas_Nitschke

Re: Probleme mit Wassershader - 08/19/04 20:03

In Antwort auf:

Try this version water and you *may* see other than black. Good luck!
web page




Just tried this compilation on my geForce 4 ti card - it worked perfectly! I thought this needed ps 1.4? As far as I'm concerned here, it doesn't! It would be great if you could post the code for this example here because this one seems very usable!
Posted By: Steempipe

Re: Probleme mit Wassershader - 08/20/04 05:07

Here's the thread where I put all the water effects I played with.
web page

You will want to look at "water test 5" post.

Eric
Posted By: MMike

Re: Probleme mit Wassershader - 08/20/04 19:24

So the Tga map has an alpha channel, and its not necessary to assign my.transparent=on;

But it look great, the final effect is this:

Posted By: doggie96

Re: Probleme mit Wassershader - 08/20/04 23:16

gj looks good for an ocean
Posted By: Thomas_Nitschke

Re: Probleme mit Wassershader - 08/21/04 00:44

Allright thanks a lot Steempipe it looks great!
Just one more question: It seems that, although the colormap is moved, the bummap stays absolutely static, which does look good in screenshots but makes it seem unreal in the game itself because the water alwas has the same wave-shape. What would I have to add to the effect if I wanted to scroll the bumpmap as well, preferably in the opposite direction as the colormap?

EDIT:
Oh and something else coming to my mind: What would I have to modify if I whant the water to be influenced by camera.ambient or, if that isn't possible, by sun_light?
Posted By: JeremyB

Re: Probleme mit Wassershader - 08/21/04 03:56

Are you sure you aren't just loading the noise map as the base map and the base map as the noise?
Posted By: MMike

Re: Probleme mit Wassershader - 08/21/04 21:02

Jeremy ur talking to who?
Posted By: MMike

Re: Probleme mit Wassershader - 08/22/04 10:08

A blood pool


Posted By: Thomas_Nitschke

Re: Probleme mit Wassershader - 08/22/04 19:37

In Antwort auf:

Are you sure you aren't just loading the noise map as the base map and the base map as the noise?



I guess that was meant for me
No, I don't, I'm sure I load the bitmaps correctly. I found out that this was more a scaling issue though. My second questions would be of interest much more now I think because I need the shader in a game with day- and night change so it would look a bit crappy having a dark world with completely li water in it
Posted By: MMike

Re: Probleme mit Wassershader - 08/22/04 21:15

Same here.. i also need to know how to control the shader ambient..


what does this do?? : vertexShaderConstant[19]=<vecAmbient>;
Posted By: Thomas_Nitschke

Re: Probleme mit Wassershader - 08/27/04 00:35

I got no idea... Steempipe where are you we need you here!
© 2024 lite-C Forums