Gamestudio Links
Zorro Links
Newest Posts
Change chart colours
by 7th_zorro. 05/11/24 09:25
Data from CSV not parsed correctly
by dr_panther. 05/06/24 18:50
Help with plotting multiple ZigZag
by degenerate_762. 04/30/24 23:23
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
2 registered members (dr_panther, henrybane), 1,096 guests, and 4 spiders.
Key: Admin, Global Mod, Mod
Newest Members
firatv, wandaluciaia, Mega_Rod, EternallyCurious, howardR
19050 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 8 of 9 1 2 3 4 5 6 7 8 9
Re: Realtime water reflections shader [Re: Matt_Aufderheide] #40508
02/13/05 22:01
02/13/05 22:01
Joined: Nov 2003
Posts: 44
sriram Offline
Newbie
sriram  Offline
Newbie

Joined: Nov 2003
Posts: 44
Thanks Matt! Got it working with 6.31

Re: Realtime water reflections shader [Re: sriram] #40509
02/14/05 12:38
02/14/05 12:38
Joined: May 2004
Posts: 157
Earth, for the moment
MASTERJUNOJET Offline
Member
MASTERJUNOJET  Offline
Member

Joined: May 2004
Posts: 157
Earth, for the moment
I need some help here, i see that the water effect in the demo is very nice, how can i impelement it into my own application? Ive tried to mess around with the scripts and all that jazz, and splice them into my own, no success however, can someone tell me how to get this great water effect in my project please?


Projects: Jet Force Gemini 2
Implementing the Realtime water reflections shader [Re: XNASorcerer] #40510
02/21/05 06:37
02/21/05 06:37
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
///////////////////////////////////////////////////////////
Shader Code from Oliver2s and tranparency code from Matt_Aufderheide.
///////////////////////////////////////////////////////////


In Wed, add a big Hollowed cubes and increase it so that it involves your level and activate the flag Sky of Hollowed cube.
The water terrain needs to have a 3rd skin (a normalmap).
You also need to have a SkyCube+6.tga inside your level folder.
Apply terrainobject action to your terrain and Water action to your water terrain.

Make a WaterShader.wdl and include it inside of your level.wdl.

You can find the code for each files (WaterShader.wdl; water.fx; clip.fx) below.

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////// WaterShader.wdl
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Code:


var bumpness =24;
var speed = 1;

bind <water.fx>;

entity* water_ent;

var temp2[3];

var hoch;
var hoch1 = 3.2;

SKY himmel1
{
type = SkyCube+6.tga;
layer = 3;
flags = cube,visible;
z = 0;
}

VIEW mirror
{
layer = 10;
}

function render_event();

MATERIAL waterfx
{
}

var hoch;
var hoch1 = 3.2;

ACTION water
{
water_ent = me;
var count;
var count1;
var a = 180;
var b;
my.transparent = on;
my.nofog = on;
my.material = waterfx;
my.scale_x = 50;
my.scale_y = 50;
my.z += 20;
hoch = my.z;
while(1)
{
my.z = hoch;
my.skill41=float(count);
my.skill42=float(count1);
my.skill43=float(0);
my.skill44=float(0);
a += speed*time;
a %= 360;
b += speed*time;
b %= 360;
count = sin(a)+bumpness;
count1 = cos(b)+bumpness;
hoch1 = my.z*0.049;
wait(1);
}
}

STARTER init_water
{
wait(2);

while(water_ent==null){wait(1);}

mirror.size_x = camera.size_x;
mirror.size_y = camera.size_y;

d3d_fogcolor1.red = 128;
d3d_fogcolor1.green = 128;
d3d_fogcolor1.blue = 150;

fog_color = 1;

camera.fog_start = 8000;
camera.fog_end = 10000;
mirror.fog_start = 8000;
mirror.fog_end = 10000;

camera.clip_near = 0;
mirror.clip_near = 0;
mirror.nocull = on;

mirror.bmap = bmap_for_entity(water_ent,1);
mirror.bmap = bmap_for_entity(water_ent2,1);
mirror.aspect = -1;
mirror.visible = on;


IF(d3d_shaderversion < 2020)
{
while(1)
{
draw_text("You need a video card with Pixelshader 2.0",screen_size.x-520,screen_size.y-280,vector(0,0,0));
wait(1);
}
}

loadfx();
mirror.aspect = -1;

proc_late();
while(1)
{
mirror.x = camera.x;
mirror.y = camera.y;
mirror.z = -camera.z+ (2*water_ent.z);
mirror.z = -camera.z+ (2*water_ent2.z);
mirror.pan = camera.pan;
mirror.tilt = -camera.tilt;
wait(1);
}
}

MATERIAL terrain_clipping //for clipping the terrain underwater in the mirror view

{
event = render_event();
flags = enable_view;
effect=
"
float4x4 matWorldViewProj: register(c0);
texture entSkin1;
vector vecSkill41;
float1 mtlSkill1;
struct VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 eyeLinear: TEXCOORD1;
};

VS_OUTPUT VS_p0(float4 Pos1: POSITION, float2 basemap: TEXCOORD0)
{
VS_OUTPUT Out;
Out.Pos = mul(Pos1, matWorldViewProj);
Out.texCoord = basemap;
Out.eyeLinear.x = Pos1.x;
Out.eyeLinear.y = Pos1.y;
Out.eyeLinear.z = Pos1.z;
return Out;
}
sampler BaseMap = sampler_state
{
texture=(entSkin1);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

float4 PS_p0( float2 texCoord: TEXCOORD0,
float3 eyeLinear: TEXCOORD1) : COLOR
{
float4 base = tex2D(BaseMap, texCoord);
clip((eyeLinear.y-vecSkill41)*mtlSkill1);
// Output
return base * 1.2;
}
technique water
{
pass p1
{
VertexShader = compile vs_1_1 VS_p0();
PixelShader = compile ps_2_0 PS_p0();
}
}
";
}

FUNCTION loadfx
{
effect_load(terrain_clip ping,"clip.fx");
effect_load(waterfx,"water.fx");
}

ACTION terrainobject
{
IF(d3d_shaderversion < 2020) { return; }
while(water_ent==null){wait(1);}
var hoch1;
my.material = terrain_clipping;
my.nofog = on;
while(1)
{
my.skill41 = float(hoch1);
wait(1);
}

}

function render_event()
{
if(render_view == camera)
{
mtl.skill1 = float(0);
}
if(render_view == mirror)
{
mtl.skill1 = float(1);
}
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////End of WaterShader.wdl
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////Water.fx
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Code:
 


float4x4 matWorldViewProj: register(c0);
float4 matWorld;
float4 vecViewPos;

texture entSkin1;
texture entSkin2;
texture entSkin3;

vector vecSkill41;

float1 mtlSkill1;

sampler BumpMap = sampler_state
{
texture=(entSkin3);
MinFilter = LINEAR;
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = WRAP;
AddressV = WRAP;
};

sampler ReflectionMap = sampler_state
{
texture=(entSkin1);
MagFilter = LINEAR;
MipFilter = LINEAR;
AddressU = CLAMP;
AddressV = CLAMP;
AddressW = CLAMP;
};

struct VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 eyeLinear: TEXCOORD1;
float4 fresnel: COLOR0;
};

VS_OUTPUT VS_p0(float4 Pos: POSITION)
{
VS_OUTPUT Out;

float4 pos = float4(1 * Pos.x, 1 * Pos.y - 1, 1 * Pos.z, 1);
float4 pPos = mul(float4(pos.xyz,1), matWorldViewProj);

Out.Pos = pPos;

Out.texCoord.x = Pos.x * 0.5;
Out.texCoord.y = Pos.z * 0.5;

Out.eyeLinear.x = 0.5 * (pPos.z + pPos.x);
Out.eyeLinear.y = 0.5 * (pPos.z - pPos.y);
Out.eyeLinear.z = pPos.z * 1;

float3 PositionWorld = mul(Pos, matWorld);
float dist=distance(PositionWorld, vecViewPos);

if (dist<=300)
{
Out.fresnel.xyzw=dist*0.005;
}

if (dist>300)
{
Out.fresnel.xyzw=1.0;
}


return Out;
}


float4 PS_p0( float2 texCoord: TEXCOORD0,float3 eyeLinear: TEXCOORD1, float4 fresnel: COLOR0) : COLOR
{

// addiere die Geschindigkeit von vecSkill41 hinzu für Wellenbewegung
float2 waterCoord = texCoord.xy * 0.001 * vecSkill41;

// die Bumpmap mit der waterCoord Koordinaten
float4 bump = tex2D(BumpMap, waterCoord) * 2 - 1;
bump = normalize(bump);

float2 mid = eyeLinear.xy / eyeLinear.z + bump.xy * 0.1f;

// Reflektierte Wasseroberfläche
float4 reflection = tex2D(ReflectionMap, mid);

float4 final=reflection;


float3 watercolor=(0.93,0.93,0.75); //adjust this change water coloring
final.rgb*=watercolor;
final.w=(1*fresnel)*0.93;//0.8;



// Output
//return reflection;
return final;
}
technique water
{
pass p1
{
zwriteenable=false;
zenable=true;
alphablendenable=true;

VertexShader = compile vs_1_1 VS_p0();
PixelShader = compile ps_2_0 PS_p0();

}
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////End of Water.fx
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////End of clip.fx
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Code:
 


float4x4 matWorldViewProj: register(c0);

texture entSkin1;

vector vecSkill41;

vector mtlSkill1;

struct VS_OUTPUT
{
float4 Pos: POSITION;
float2 texCoord: TEXCOORD0;
float3 eyeLinear: TEXCOORD1;
};

VS_OUTPUT VS_p0(float4 Pos1: POSITION, float2 basemap: TEXCOORD0)
{
VS_OUTPUT Out;

Out.Pos = mul(Pos1, matWorldViewProj);

Out.texCoord = basemap;

Out.eyeLinear.x = Pos1.x;
Out.eyeLinear.y = Pos1.y;
Out.eyeLinear.z = Pos1.z;

return Out;
}

sampler BaseMap = sampler_state
{
texture=(entSkin1);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;
};

float4 PS_p0( float2 texCoord: TEXCOORD0,
float3 eyeLinear: TEXCOORD1) : COLOR
{
float4 base = tex2D(BaseMap, texCoord);

clip((eyeLinear.y-vecSkill41)*mtlSkill1);

// Output

return base * 1.2;
}
technique water
{
pass p1
{
VertexShader = compile vs_1_1 VS_p0();
PixelShader = compile ps_2_0 PS_p0();
}
}




/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////End of clip.fx
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

Last edited by Sorcerer; 02/26/05 06:40.
Re: Implementing the Realtime water reflections shader [Re: XNASorcerer] #40511
02/22/05 02:41
02/22/05 02:41
Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Superku Offline
Senior Expert
Superku  Offline
Senior Expert

Joined: Sep 2003
Posts: 6,861
Kiel (Germany)
Thanks, Sorcerer.
But it still doesn't work for me.
What is "Shader_water" (in action water) ?

Felix


"Falls das Resultat nicht einfach nur dermassen gut aussieht, sollten Sie nochmal von vorn anfangen..." - Manual

Check out my new game: Pogostuck: Rage With Your Friends
Re: Implementing the Realtime water reflections shader [Re: Superku] #40512
02/26/05 06:55
02/26/05 06:55
Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
XNASorcerer Offline OP
Expert
XNASorcerer  Offline OP
Expert

Joined: Dec 2001
Posts: 2,172
Portugal - Brazil
Just forget this Shader_water.

Re: Implementing the Realtime water reflections shader [Re: XNASorcerer] #40513
03/04/05 08:17
03/04/05 08:17
Joined: Aug 2003
Posts: 183
BionicHero Offline
Member
BionicHero  Offline
Member

Joined: Aug 2003
Posts: 183
Hi! I also tried some stuff with the shader and I have one question: my project doesn't use a skybox but uses DOME to display the sky. But the sky is not visible on the mirror bitmap. Is there anything I could do to fix this?

Re: Implementing the Realtime water reflections sh [Re: BionicHero] #40514
03/10/05 04:00
03/10/05 04:00
Joined: Jan 2003
Posts: 710
T
Templar Offline
Developer
Templar  Offline
Developer
T

Joined: Jan 2003
Posts: 710
Hi! this is a realy nice and helpful shader. However I was wondering about one thing - there's something strange going on near the very borders of the view - there are some distortions happening. It seems to be present even on the screenshots in this thread. Is there any way how to get rid of this? thanks!

Re: Implementing the Realtime water reflections sh [Re: Templar] #40515
03/10/05 06:46
03/10/05 06:46
Joined: Oct 2003
Posts: 4,131
M
Matt_Aufderheide Offline
Expert
Matt_Aufderheide  Offline
Expert
M

Joined: Oct 2003
Posts: 4,131
Yes simply find this section :
sampler ReflectionMap = sampler_state
{
texture=(entSkin1);
MAGFILTER = LINEAR;
MINFILTER = LINEAR;
MIPFILTER = LINEAR;

};

and add these lines :
AddressU = CLAMP;
Addressv = CLAMP;

Re: Implementing the Realtime water reflections sh [Re: Matt_Aufderheide] #40516
03/10/05 08:11
03/10/05 08:11
Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
Rhuarc Offline
Expert
Rhuarc  Offline
Expert

Joined: Mar 2001
Posts: 3,298
Beverly, Massachusetts
I don't think that is his problem. The problem is that the rendered texture is in a 1:1 ratio (it's square) where the screen is a 4:3 ratio. This means that the sides will be stretched.

You have to change the texture transform matrix to use a 4:3 ratio:
m11=1.25
m22=1

I'll take a look at the code and show exactly how this is done (that isn't the actual code there) if I find some time in a little bit- unless someone beats me to it

-Rhuarc


I no longer post on these forums, keep in touch with me via:
Linkedin.com
My MSDN blog
Re: Implementing the Realtime water reflections sh [Re: Rhuarc] #40517
03/10/05 18:37
03/10/05 18:37
Joined: Jan 2003
Posts: 710
T
Templar Offline
Developer
Templar  Offline
Developer
T

Joined: Jan 2003
Posts: 710
great, thanks a lot! Just one more question though - would it be hard to make such changes to this shader that in case that the video card didn't support PS2.0, realtime reflections were disabled and only the skycube was used for enviromental mapping?

thanks everyone!

Page 8 of 9 1 2 3 4 5 6 7 8 9

Moderated by  Blink, Hummel, Superku 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1