Slin's Water Shader

Posted By: DJBMASTER

Slin's Water Shader - 01/23/08 22:32

Hi guys, i've downloaded Slin's water shader>>

http://files.filefront.com/Water+for+Everyone/;8570332;/fileinfo.html

I have implemented it into my project and it works very well. The only addition i would like is that it is slightly transparent so i can see like the sea floor or rocks underneath the water plane/terrain.

I asked slin and he told me to add a couple of lines but they did not work and he said he has no more ideas.

I dont program shaders so does anyone know how to add transparency to the reflecting water shader?

Thanks.... DJB.
Posted By: lostclimate

Re: Slin's Water Shader - 01/23/08 23:12

post the shader script and ill try and tell you what to add and where
Posted By: DJBMASTER

Re: Slin's Water Shader - 01/24/08 00:12

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

matrix matMtl;

texture mtlSkin1;
texture mtlSkin2;

technique makewater2
{
pass p0
{
AlphaBlendEnable=false;
Zenable = True;
ZwriteEnable = True;

BlendOp=Add;
Lighting=True;

Texture[0] = <mtlSkin1>;
Texture[1] = <mtlSkin2>;

magFilter[0] = linear;
minFilter[0] = linear;
mipFilter[0] = linear;

COLOROP[0] = BumpEnvMap;
COLORARG1[0] = Texture;
COLORARG2[0] = Current;

TexCoordIndex[0] = 1;
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;


magFilter[1] = Linear;
minFilter[1] = Linear;
mipFilter[1] = Linear;

AddressU[1] = Clamp;
AddressV[1] = Clamp;

ColorOp[1] = Modulate; //Modulate/AddSigned/Modulate2x/Modulate4x/Add <----------This looks all okay
ColorArg1[1] = Texture;
ColorArg2[1] = Current;

texcoordindex[1] = cameraspaceposition | 1; // For cubemap use: cameraspacereflectionvector
TextureTransformFlags[1] = count3 | projected;
TextureTransform[1] = {
0.8, 0.0, 0.0, 0.0,//u-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 1.0, 0.0, 0.0,//v-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
}
}

//technique fallback { pass p0 { } }
Posted By: xXxGuitar511

Re: Slin's Water Shader - 01/24/08 01:41

Code:

matrix matMtl;

texture mtlSkin1;
texture mtlSkin2;

float4 AlphaX = {1.0, 1.0, 1.0, 0.5};
// change 0.5 to your alpha (0 - 1)

technique makewater2
{
pass p0
{
AlphaBlendEnable = true;
//AlphaTestEnable = true; // <-- you may need to add this
Zenable = True;
ZwriteEnable = True;

BlendOp=Add;
Lighting=True;

Texture[0] = <mtlSkin1>;
Texture[1] = <mtlSkin2>;

magFilter[0] = linear;
minFilter[0] = linear;
mipFilter[0] = linear;

COLOROP[0] = BumpEnvMap;
COLORARG1[0] = Texture;
COLORARG2[0] = Current;

TexCoordIndex[0] = 1;
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;


magFilter[1] = Linear;
minFilter[1] = Linear;
mipFilter[1] = Linear;

AddressU[1] = Clamp;
AddressV[1] = Clamp;

ColorOp[1] = Modulate;
ColorArg1[1] = Texture;
ColorArg2[1] = Current;

ColorOp[2] = Modulate;
ColorArg1[2] = AlphaX;
ColorArg2[2] = Current;

texcoordindex[1] = cameraspaceposition | 1;
cameraspacereflectionvector
TextureTransformFlags[1] = count3 | projected;
TextureTransform[1] = {
0.8, 0.0, 0.0, 0.0,//u-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 1.0, 0.0, 0.0,//v-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
}
}

//technique fallback { pass p0 { } }


Posted By: DJBMASTER

Re: Slin's Water Shader - 01/24/08 02:24

@XxXGuitar511 > I added your code and un-commented the alphatestenabled=true and i get the following error...

Error in Effect:
mtl_ffpwater(51): error X3000: syntax error: unexpected token
'TextureTransformFlags'

it seems the TextureTransformFlags[1] = count3 | projected; is causing the error.

BTW is the terrain model supposed to have the transparency flag set?
Posted By: Steempipe

Re: Slin's Water Shader - 01/24/08 09:35

remove the "cameraspacereflectionvector" right before the line you point out.
Posted By: DJBMASTER

Re: Slin's Water Shader - 01/24/08 15:41

Done that... now i get this error>>>

Error in effect:
Water_mat(56); ID3DXEffectCompiler: State 'COLORARG1' does not accept 'AlphaX' as a value. There was an error initializing the compiler.
ColorArg1[2] = AlphaX;

I have no idea what is going wrong, lol. Has anyone got this to work?
Posted By: xXxGuitar511

Re: Slin's Water Shader - 01/24/08 20:06

...since I havn't tested it, that was probably my mistake. Try adding "<" ">" around AlphaX
Posted By: Steempipe

Re: Slin's Water Shader - 01/24/08 20:15

ColorArg does not accept a float, it's a DWORD value. I doubt that just simply adding < > or ( ) around the variable will clear up the error. You could try getting a value into the stage by using texturefactor... But this whole idea seems a bit faulty. I would be going at it by setting up alpha states and blending operations.

Did you try putting <my.transparent = on;> and <my.alpha = 50;> in your material to see if it serves you well enough?
Posted By: DJBMASTER

Re: Slin's Water Shader - 01/24/08 22:14

placing <> around AlphaX just makes the water render as a black plane.

I have tried using >>

material mtl_ffpwater
{
skin1=waterbump;
event = mtl_ffpwater_event;
effect = "efx_water.fx";
my.transparent = on;
my.alpha=50;
}

But it doesnt accept transparent or alpha flags because it gives me errors when i run it.

I have tried adding transparent/translucent and alpha flags to the water action, view and material, but so far no look in making the water have alpha.
I am guessing the solution is to code it into the shader, but i am no good with programming shaders.

You mention alpha states and blending operations - i have no idea what these mean, lol.
Posted By: Steempipe

Re: Slin's Water Shader - 01/24/08 23:25

I'm sorry, the my.transparent and my.alpha should be in the "Action".

I think in the Wiki there was a link to the DX Effect File States. That may help you some. I do not have the time to get re-aquainted with the states right now.
Posted By: DJBMASTER

Re: Slin's Water Shader - 01/25/08 00:35

K, tried it in the action >> no luck, lol...

Ok, well it seems the only way i'm going to solve this is to learn part of FFP shaders. Am i on the right tracks>>>???

Texture mtlSkin2;
Texture[2] = <mtlSkin2>;
TexCoordIndex[2] = 1;

ColorOp[2] = Add; // add the .tga alpha map to the shader
ColorArg1[2] = Texture;
ColorArg2[2] = Current;

TextureTransformFlags[2] = count3 | projected;
TextureTransform[2] = {
0.8, 0.0, 0.0, 0.0, // u-scale of alpha
0.0, 1.0, 0.0, 0.0, // v-scale of alpha
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};

Then in my material WDL I define a BMAP>>

bmap alphamap = "bm_alpha.tga";

and add skin2=alphamap; to my material.

Any errors or code i should be aware of?

Thanks
Posted By: DJBMASTER

Re: Slin's Water Shader - 02/02/08 01:52

Doesn't anyone know how to fix this? It's a pretty big part of my project. Is there a way to apply an alpha map/channel to it?
Posted By: Steempipe

Re: Slin's Water Shader - 02/02/08 13:01

Hi,
I'm lazy . so could you PM me a link to a build with just your water portion?? I'll see what I can do for you.
Posted By: Blink

Re: Slin's Water Shader - 02/02/08 19:21

Steempipe, you are truly a master at water shaders, slin is awesome as well. can you help me understand how to get them to work? i cant use r2t for some reason. what should i be using? my card supports shader model 2.0.
Posted By: Steempipe

Re: Slin's Water Shader - 02/04/08 22:18

Quote:

Steempipe, you are truly a master at water shaders, slin is awesome as well. can you help me understand how to get them to work? i cant use r2t for some reason. what should i be using? my card supports shader model 2.0.




Funny thing is this: The DLL does not seem to render correctly on my setup as well. At least not with the "water for everyone" level. I'll have to spend a bit more time with this. Hmmmm.
Posted By: Blink

Re: Slin's Water Shader - 02/05/08 02:16

which one do you recommend for water shaders? sylex opens for me, but my ocean is huge, i always get a size error, and the shader wont work.
Posted By: sPlKe

Re: Slin's Water Shader - 02/06/08 09:44

i got it to run. here is the fx file code and the shader.wdl code:
FX file
Code:
 ////////////////////////////////////////////////////////
// Environment Mapping Bump Mapping Water
//
// Version 2
//
// Eric Hendrickson-Lambert (Steempipe)
//
////////////////////////////////////////////////////////

matrix matMtl;

texture mtlSkin1;
texture mtlSkin2;

technique makewater2
{
pass p0
{
AlphaBlendEnable=true;
Zenable = True;
ZwriteEnable = True;

BlendOp=Add;
Lighting=True;

Texture[0] = <mtlSkin1>;
Texture[1] = <mtlSkin2>;

magFilter[0] = linear;
minFilter[0] = linear;
mipFilter[0] = linear;

COLOROP[0] = BumpEnvMap;
COLORARG1[0] = Texture;
COLORARG2[0] = Current;

TexCoordIndex[0] = 1;
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;


magFilter[1] = Linear;
minFilter[1] = Linear;
mipFilter[1] = Linear;

AddressU[1] = Clamp;
AddressV[1] = Clamp;

ColorOp[1] = Modulate; //Modulate/AddSigned/Modulate2x/Modulate4x/Add <----------This looks all okay
ColorArg1[1] = Texture;
ColorArg2[1] = Current;

texcoordindex[1] = cameraspaceposition | 1; // For cubemap use: cameraspacereflectionvector
TextureTransformFlags[1] = count3 | projected;
TextureTransform[1] = {
0.8, 0.0, 0.0, 0.0,//u-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 1.0, 0.0, 0.0,//v-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
}
}

//technique fallback { pass p0 { } }



shader.wdl
Code:
 //use Render2Texture Dll by ChrisB
plugindir "Plugins";
dllfunction r2T_eventSky();
dllfunction r2T_eventEntities();
render_sky = r2T_eventSky;
render_entities = r2T_eventEntities;
//

bmap waterbump = <waves2.tga>;
//bmap envspec = <sky.tga>;

function mtl_ffpwater_event();

material mtl_ffpwater
{
skin1=waterbump;
// skin2=envspec;

event = mtl_ffpwater_event;
effect = "water.fx";
}

function mtl_ffpwater_event()
{
while(1)
{
//Lets make it scroll in some direction
mtl_ffpwater.skill1 += 0.3*time_step; //Move the water along the x axis with the given speed
mtl_ffpwater.skill2 += 0.1*time_step; //Move the water along the y axis with the given speed
mtl_ffpwater.matrix31 = floatd(sin(mtl_ffpwater.skill1)*100000,40000);
mtl_ffpwater.matrix32 = floatd(cos(mtl_ffpwater.skill2)*100000,40000);
wait(1);
}
}

VIEW view_mirror { layer = -1; }; // render mirror view before camera view
BMAP* bmap_mirrortarget;
//panel rtt{flags = visible;}
var water_height;

function fx_mirror()
{
// do nothing if mirror is already running
if (bmap_mirrortarget) { return; }

bmap_mirrortarget = bmap_createblack(512,512,888);
mtl_ffpwater.skin2 = bmap_mirrortarget;
view_mirror.bmap = bmap_mirrortarget;
view_mirror.size_x = bmap_width(bmap_mirrortarget);
view_mirror.size_y = bmap_height(bmap_mirrortarget);
// rtt.bmap = bmap_mirrortarget;

// vec_set(view_mirror.portal_x,my.x);
// vec_add(view_mirror.portal_x,vector(0,0,0));
// vec_set(view_mirror.pnormal_x,vector(0,0,1.0)); // reflect upwards
// view_mirror.portalclip = on; // clip at portal plane

view_mirror.noshadow = on; // suppress shadows in the mirror
// view_mirror.nocull = on; // view through walls
view_mirror.noparticle = on;
// view_mirror.noshader = on;

view_mirror.visible = on;

while (bmap_mirrortarget)
{
proc_late(); // camera must be moved and mtlfx_mirrorvisible set before

// view_mirror.aspect = 1;//1024/768; // screen aspect, independent of render target
view_mirror.arc = camera.arc;
view_mirror.fog_start = camera.fog_start;
view_mirror.fog_end = camera.fog_end;
view_mirror.clip_far = camera.clip_far;
view_mirror.clip_near = camera.clip_near;
view_mirror.x = camera.x;
view_mirror.y = camera.y;
view_mirror.z = 2*water_height-camera.z;//view_mirror.portal_z-camera.z; // move the camera at its mirror position
view_mirror.pan = camera.pan;
view_mirror.tilt = -camera.tilt; // flip the vertical camera angle
view_mirror.roll = -camera.roll;

wait(1);
}
}

action Water
{
water_height=my.z;
mtl_ffpwater.matrix11 = float(100); //Tilefactor of the Bumpmap in x direction
mtl_ffpwater.matrix22 = float(10); //Tilefactor of the Bumpmap in y direction

bmap_to_mipmap(mtl_ffpwater.skin1);
// bmap_to_mipmap(mtl_ffpwater.skin2);
my.transparent=on;
my.alpha=50;
my.material = mtl_ffpwater;
}




i testd it with skinc and it works flawlessy, however i dont know how it reacts if you change any value. i tested it with ym A6.com and render to texture plugin and it works fine, so i think it should work with any other version above A6.60 com...

hope that helps, if not, i am sorry
Posted By: Steempipe

Re: Slin's Water Shader - 02/09/08 01:34

Now we go back to your original posted code. Try adding as indicated.
Then... in your action, go back to attempting to use <my.transparent = on;> and <my.alpha = 50;>.

Good Luck!!

Code:
 
////////////////////////////////////////////////////////

matrix matMtl;

texture mtlSkin1;
texture mtlSkin2;

technique makewater2
{
pass p0
{
AlphaBlendEnable = True; // <------- Set to True
Zenable = True;
ZwriteEnable = True;

// BlendOp=Add; <------- Comment out
Lighting=True;

srcBlend = srcColor; // <------- Add this
destBlend = destColor; // <------- Add this


Texture[0] = <mtlSkin1>;
Texture[1] = <mtlSkin2>;

magFilter[0] = linear;
minFilter[0] = linear;
mipFilter[0] = linear;

COLOROP[0] = BumpEnvMap;
COLORARG1[0] = Texture;
COLORARG2[0] = Current;

TexCoordIndex[0] = 1;
TextureTransformFlags[0] = Count2;
TextureTransform[0] = <matMtl>;


magFilter[1] = Linear;
minFilter[1] = Linear;
mipFilter[1] = Linear;

AddressU[1] = Clamp;
AddressV[1] = Clamp;

ColorOp[1] = Modulate2x; //Modulate/AddSigned/Modulate2x/Modulate4x/Add <----------This looks all okay
ColorArg1[1] = Texture;
ColorArg2[1] = Current;

texcoordindex[1] = cameraspaceposition | 1; // For cubemap use: cameraspacereflectionvector
TextureTransformFlags[1] = count3 | projected;
TextureTransform[1] = {
0.8, 0.0, 0.0, 0.0,//u-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 1.0, 0.0, 0.0,//v-scale of lake rgb texture CHANGE THIS TO YOUR NEEDS!
0.0, 0.0, 1.0, 0.0,
0.0, 0.0, 0.0, 1.0
};
}
}

//technique fallback { pass p0 { } }





EDIT: Well, adding the my.transparent stuff does not do anythinng!. I'll chew on it a little more.
© 2024 lite-C Forums