Water Demo - Now OpenGL and DX supported

Announce new projects or updates of Irrlicht Engine related tools, games, and applications.
Also check the Wiki
devsh
Competition winner
Posts: 2057
Joined: Tue Dec 09, 2008 6:00 pm
Location: UK
Contact:

Post by devsh »

cool how did you do underwater caustics???
Valerien
Posts: 17
Joined: Wed Apr 08, 2009 6:12 pm

Post by Valerien »

That's a good job BlindSide, but well, could be improved a lot.

Image

http://modclub.rigsofrods.com/xavi/04_Pics/5.png

These are screenshots of ogre app using hydrax. It's quite realistic as a tropical warm water. Well, the main problem on your work is the height of the waves like... the terrain's refracted image takes a big part of the screen so it gives an idea of the real scale of the scene. So the waves should have a minimal height instead of bump ;). And the caustics are also a little bit too big.

Image

Here you have an image of how the light is err... gathered ? Dunno the right term in english.

I love your projet ;).
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

God damn that water looks good.... If only I wasn't so thirsty right now!! :lol:
Image Image Image
grunt
Posts: 96
Joined: Tue Aug 17, 2004 9:14 pm
Contact:

Post by grunt »

Any chancw of the source on this?
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

No. It's too old, sorry. You can look at the source code for my Irrlicht contest entry (Listed here: http://irrlicht.sourceforge.net/phpBB2/ ... hp?t=31885) for some slightly different ocean water code.
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

I managed to extract the shader code strings from the executable (hope you don't mind, Blindside). Unfortunately, I can't make it work correctly since I don't know how it was implemented. I simply tried using the water material on a flat surface and setting the obvious callbacks (matrices, CamPos, time) but it doesn't look right at all; I used the textures that came along with the demo as normalmap, terrainmap, dudvmap. So I guess there's something wrong with my reflection RTT (s0).

Maybe, if Blindside recalls some bits and pieces we could make it work again. I would very much like to see it running again since (even though old) it looks pretty awesome and gives me (unlike other water shaders) 300fps :)

shader 1 (water surface itself)

Code: Select all

float4x4 mWorldViewProj;  // World * View * Projection transformation
float4x4 mWorld;
float4 CamPos;
float Time;

struct VS_OUTPUT
{
  float4 Position   : POSITION0;
  float4 waterpos   : TEXCOORD0;
  float3 WorldView  : TEXCOORD1;
  float2 TexCoords  : TEXCOORD2;
  float3 MultiVar   : TEXCOORD3; // X: Addition, Y: Timer, Z: UnderWater
  float2 terrCoords : TEXCOORD4;
};

VS_OUTPUT vertexMain( float3 Position  : POSITION0,
                      float2 TexCoords : TEXCOORD0 )
{
VS_OUTPUT OUT = (VS_OUTPUT)0;

OUT.Position = mul(float4(Position.x,Position.y,Position.z,1.0), mWorldViewProj);
OUT.waterpos = float4(Position.x,Position.y,Position.z,1.0);
OUT.MultiVar.y = Time / 10000.0;

##ifdef USE_SIN
OUT.MultiVar.x = (sin((Position.x/3.0) + (Time * 10.0 / 10000.0))) +
                 (cos((Position.z/3.0) + (Time * 10.0 / 10000.0)));
OUT.Position.y += OUT.MultiVar.x;
##endif

OUT.MultiVar.z = CamPos.y;

float4 PosW = mul(float4(Position.x,Position.y,Position.z,1.0), mWorld);

OUT.WorldView =  CamPos.xyz - PosW.xyz;
OUT.TexCoords = TexCoords + float2(OUT.MultiVar.y, OUT.MultiVar.y);
OUT.terrCoords = TexCoords * 0.03 - float2(0.5,0.5);

return(OUT);
}

// -----------------------------------------------------------------------------------------

float4x4 mWorldViewProjP;  // World * View * Projection transformation

sampler2D ReflectionTexture : register(s0) ;
sampler2D NormalMap : register(s1) ;
sampler2D TerrainMap : register(s2) ;

##ifdef USE_REFRACTION
sampler2D DUDVMap : register(s3) ;
##endif

float4 pixelMain(float4 waterpos   : TEXCOORD0,
                 float3 WorldView  : TEXCOORD1,
                 float2 TexCoord   : TEXCOORD2,
                 float3 MultiVar   : TEXCOORD3, // X: Addition, Y: Timer, Z: UnderWater
                 float2 terrCoords : TEXCOORD4 ) : COLOR0
{
float4 projCoord = mul(waterpos, mWorldViewProjP);

projCoord.x = projCoord.x / projCoord.w / 2.0 + 0.5;
projCoord.y = projCoord.y / projCoord.w / 2.0 + 0.5;

##ifdef USE_SIN
projCoord.x += sin(MultiVar.x * 5) * (2 / 1000.0);
projCoord.y += cos(MultiVar.x * 5) * (2 / 1000.0);
TexCoord.x += sin(MultiVar.x * 5) * (5 / 1000.0);
TexCoord.y += cos(MultiVar.x * 5) * (5 / 1000.0);
##endif

##ifdef USE_REFRACTION
float4 DUDVoffset = tex2D(DUDVMap,TexCoord);
projCoord.x += (DUDVoffset.x / 40.0) - (1.0 / 80.0);
projCoord.y += (DUDVoffset.y / 40.0) - (1.0 / 80.0);
##endif

projCoord = clamp(projCoord, 0.001, 0.999);
float4 normal = float4(0.0, 1.0, 0.0, 0.0);

if(MultiVar.z < 0.0)
  projCoord.y = 1.0 - projCoord.y;

float4 refTex = tex2D(ReflectionTexture,projCoord);
float facing = (1.0 - max(dot(normalize(WorldView), normalize(normal.xyz)), 0));
float4 MultCol = float4(0.2,0.4,0.8,0.0);
refTex = (refTex + float4(0.0,0.0,0.1,0.0)) * MultCol;
float4 norMap = tex2D(NormalMap,TexCoord);
float lightComp = 1.0 - max(dot(normalize(norMap.xyz),normalize(abs(WorldView))),0.0);
float4 finalCol = refTex;

if(MultiVar.z < 0.0)
  finalCol *= 0.8;

finalCol.a = 0.6 + (facing / 2.0);
finalCol += lightComp;

if(MultiVar.z > 0.0)
{
  float shoreFactor = max((tex2D(TerrainMap,terrCoords).y - 0.4) * 2.0, 0.0);
  finalCol = (float4(0.0,0.8,1.0,0.6) * shoreFactor) + (finalCol * (1.0 - shoreFactor));
}

return(finalCol);
}
shader 2 (looks like terrain, underwater and light)

Code: Select all

float4x4 mWorldViewProj;  // World * View * Projection transformation
float4x4 mWorld;
float3 LightPos;
float Time;

struct VS_OUTPUT
{
float4 Position: POSITION0;
float2 TexCoords : TEXCOORD0;
float2 TexCoords2        : TEXCOORD1;
float2 TexCoords3 : TEXCOORD2;
float2 MultiVar : TEXCOORD3; // Height, Light intensity
float2 TexCoords4 : TEXCOORD4;
}

VS_OUTPUT vertexMain( float3 Position : POSITION0,
                      float2 TexCoords : TEXCOORD0,
                      float2 TexCoords2 : TEXCOORD1,
                      float3 Normal : NORMAL0 )
{
VS_OUTPUT OUT = (VS_OUTPUT)0;
float Timer = Time / 5000.0;
OUT.Position = mul(float4(Position.x,Position.y,Position.z,1.0), mWorldViewProj);
float4 Pos = mul(float4(Position.x,Position.y,Position.z,1.0), mWorld);
OUT.MultiVar.x = Pos.y;
float3 lightDir = normalize(LightPos - Pos.xyz);
float3 normal = normalize(Normal);
OUT.MultiVar.y = max(dot(normal,normalize(lightDir)),0.2);


OUT.TexCoords = TexCoords;
OUT.TexCoords2 = TexCoords2;
OUT.TexCoords3 = TexCoords2 + float2(Timer,Timer);
OUT.TexCoords4 = TexCoords2 + float2(-Timer,Timer);

return OUT;
}

// ------------------------------------------------------------------------------------------

float DrawBottom, UnderWater;

sampler2D ColoredTextureSampler : register(s0) ;
sampler2D DetailMap : register(s1) ;
sampler2D SeaFloorMap : register(s2) ;

float4 pixelMain( float4 Position   : POSITION0,
                  float2 TexCoords  : TEXCOORD0,
                  float2 TexCoords2 : TEXCOORD1,
                  float2 TexCoords3 : TEXCOORD2,
                  float2 MultiVar   : TEXCOORD3, // Height, Light intensity
                  float2 TexCoords4 : TEXCOORD4 )
{
float4 finalCol = tex2D( ColoredTextureSampler, TexCoords.xy) * tex2D( DetailMap, TexCoords2.xy) * MultiVar.y * 2;
finalCol.a = 1.0;
float4 originCol = finalCol;

if(MultiVar.x < 0.0)
{
finalCol *= 0.3;
finalCol += tex2D( SeaFloorMap, (TexCoords3) / 2.0) / 4.0;
finalCol += tex2D( SeaFloorMap, (TexCoords4) / 2.0) / 4.0;

  if(MultiVar.x > -5.0)
  {
  float edgeComp = (MultiVar.x + 5) / 5;
  finalCol = (finalCol * (1 - edgeComp) + (originCol * (edgeComp)));
  }

  finalCol.a = 1.0;

  if(UnderWater > 0.5)
    finalCol.a = DrawBottom;
}

if(UnderWater < 0.5 && DrawBottom > 0.5 && MultiVar.x < 1.5)
  finalCol *= float4(0.4,0.6,1.0,1.0);

return finalCol;
}
Never take advice from someone who likes to give advice, so take my advice and don't take it.
charl3s7
Posts: 11
Joined: Sat Oct 03, 2009 3:17 am

Post by charl3s7 »

Wow, that looks amazing!
//Charles
BlindSide
Admin
Posts: 2821
Joined: Thu Dec 08, 2005 9:09 am
Location: NZ!

Post by BlindSide »

I have the source but it's too messy to release! I guess I can PM you if you promise to clean it up and make it nice and presentable before showcasing :)
ShadowMapping for Irrlicht!: Get it here
Need help? Come on the IRC!: #irrlicht on irc://irc.freenode.net
Bate
Posts: 364
Joined: Sun Nov 01, 2009 11:39 pm
Location: Germany

Post by Bate »

Deal! :D
Never take advice from someone who likes to give advice, so take my advice and don't take it.
havok2063
Posts: 6
Joined: Tue Mar 15, 2011 12:56 am

Post by havok2063 »

Any update on that sourcecode release? :D I'm really looking forward to an underwater shader.
Post Reply