Author Topic: How would you make a good looking water surface ?  (Read 4746 times)

0 Members and 1 Guest are viewing this topic.

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
How would you make a good looking water surface ?
« on: March 18, 2015, 11:21:23 PM »
So I spent two evenings trying to make good water surface using whatever capacity Doom 3 has and I found it impossible :(

Here is what I came up with (realtime reflection is a custom shader and has artifacts on object partially submerged into water, so unless we fix that, I won't use it):


Basically it's just a brush with 5 sides of nodraw and surface having my water material:

Code: [Select]
textures/water/water_surface1
{
translucent
twoSided
noShadows
noSelfShadow
nonsolid
qer_editorimage textures/water/water_surface1_strip16_editor.tga
{
vertexProgram heatHaze.glsl
vertexParm 0 time * .1, time * 0.08
vertexParm 1 2
fragmentProgram heatHaze.glsl
fragmentMap 0 _currentRender
fragmentMap 1 normalMap textures/water/water_surface1_local.tga
}
{
blend blend
map textures/water/water_surface1_d.tga
alpha 0.15
scroll sinTable[time * .02] * .01, time * 0.02
shear sinTable[time * .02] * .02, cosTable[time * .02] * .02
rotate sinTable[time * .01] * .01
}
{
blend bumpmap
map textures/water/water_surface1_local.tga
scroll sinTable[time * .02] * .01, time * 0.02
shear sinTable[time * .02] * .02, cosTable[time * .02] * .02
rotate sinTable[time * .01] * .01
}
{
blend specularmap
map textures/water/water_surface1_s.tga
scroll sinTable[time * .02] * .01, time * 0.02
shear sinTable[time * .02] * .02, cosTable[time * .02] * .02
rotate sinTable[time * .01] * .01
}

}

If I add cubemap reflection, it looks like crap, since it just sits there, doesn't deform or anything like that, so my water looks like ice (I tested it in stock Doom 3 and it's the same story):


Can anyone point me in the right direction for vanilla Doom 3 (without sikkmod or anything like that, unless it's impossible) ? Thanks!

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: How would you make a good looking water surface ?
« Reply #1 on: March 19, 2015, 12:20:11 PM »
i guess, in water and in smoke, the less light it gets the less light has to spread, so the result is that is not seen (therefore is more transparent)

BloodRayne

  • Old Forum Goer
  • Full Member
  • ***
  • Posts: 136
  • Karma: +13/-0
  • Doom Newbie
    • View Profile
    • Grimm Quest for the Gatherer's Key
Re: How would you make a good looking water surface ?
« Reply #2 on: March 19, 2015, 02:22:36 PM »
This was pretty easy to make. I use two layers, one flat fresnel reflection, the other a bumpmapped transparent surface (without heathaze interaction).



Place two single planes beneath each other, 1 or 2 units apart.
Texture the bottom layer with the material 'textures/inolen_water_mirror' and the top one with 'textures/inolen_water'. Size it with the texture editor accordingly to the scale of your map.

Install the fresnel shader and materials as posted below.

Fresnel shader (fresnel.vfp):

Code: [Select]
# Fresnel shader written by inolen 2005
# http://www.inolen.com

#################
# vertex shader #
#################

!!ARBvp1.0
OPTION ARB_position_invariant;

TEMP R1, R2, R3, R4;

SUB R1, program.env[5], vertex.position;
DP3 R2, R1, R1;
RSQ R2, R2.x;
MUL R1, R1, R2.x;

DP3 R2, R1, vertex.normal;

SUB R3, 1.0, R2;

MUL R4, R3, R3;

MUL R4, R4, R3;

MUL R4, R4, R3;

MUL R4, R4, R3;

SUB R3, 1.0, program.local[0];

MAD result.texcoord[2].x, R4, R3, program.local[0];

END

################
# pixel shader #
################

!!ARBfp1.0
OPTION ARB_precision_hint_fastest;

TEMP A, C;

MUL A, fragment.position, program.env[1];

TEX C, A, texture[0], 2D;

MOV result.color, C;

MOV result.color.a, fragment.texcoord[2].x;

END

Materials.
Code: [Select]
textures/inolen_water
{
translucent
noshadows
twosided
forceOverlays

qer_editorimage textures/glass/glass1
{
blend blend
map textures/water/watertest_local.tga
// give it a blue tint
red 0.7
green 0.7
blue 1.0

// opacity
alpha 0.3

translate 0.5, 0.5
scale 0.5, 0.5
}

{
program heatHaze.vfp
vertexParm 0 time * 0.1 , time * 0.1 //scroll
vertexParm 1 0.5 //magnitude
fragmentMap 0 _currentRender
fragmentMap 1 textures/water/watertest_local.tga
    }
}

textures/inolen_water_mirror
{
translucent
noshadows

qer_editorimage textures/glass/glass1
{
blend blend
mirrorRenderMap 512 256

translate 0.5, 0.5
scale 0.5, 0.5

        program   fresnel.vfp
vertexParm 0 .00200593122
fragmentMap 0 _scratch
}
}
« Last Edit: March 19, 2015, 02:37:03 PM by BloodRayne »

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: How would you make a good looking water surface ?
« Reply #3 on: March 19, 2015, 02:35:38 PM »
This was pretty easy to make. I use two layers, one flat fresnel reflection, the other a bumpmapped transparent surface (without any other interaction).



Doom 3 doesn't have fresnel shader :/

I tried having bumpmap on transparent surface, but it doesn't work. Normal maps work only on interactive surfaces and transparent surfaces are non-interactive - thus not possible having bump on them.

Did you make it with Sikkmod or vanilla Doom 3 ? If latter, care to share basic scene for Doom 3 ? Thanks.

BloodRayne

  • Old Forum Goer
  • Full Member
  • ***
  • Posts: 136
  • Karma: +13/-0
  • Doom Newbie
    • View Profile
    • Grimm Quest for the Gatherer's Key
Re: How would you make a good looking water surface ?
« Reply #4 on: March 19, 2015, 02:37:38 PM »
Doom 3 doesn't have fresnel shader :/

I tried having bumpmap on transparent surface, but it doesn't work. Normal maps work only on interactive surfaces and transparent surfaces are non-interactive - thus not possible having bump on them.

Did you make it with Sikkmod or vanilla Doom 3 ? If latter, care to share basic scene for Doom 3 ? Thanks.
I included it for you in the code segment! :P

ps: Doom3 has any shader you can program into it. It's only always been limited by the expertise of the programmers. In the beginning there were some dedicated VFP programmers out there (Inolen being one of them). And he created this pretty OK working fresnel shader, which works like a charm.
« Last Edit: March 19, 2015, 02:39:28 PM by BloodRayne »

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: How would you make a good looking water surface ?
« Reply #5 on: March 19, 2015, 03:12:42 PM »
Thanks, I'll poke at it.

BielBdeLuna

  • Full Member
  • ***
  • Posts: 242
  • Karma: +8/-20
  • Doom Newbie
    • View Profile
    • my Github repositories
Re: How would you make a good looking water surface ?
« Reply #6 on: March 19, 2015, 07:26:37 PM »
you will need to translate the fresnel.vfp to glsl.
in the dark mod they did a water with a heathaze that didn't deform the stuff in.front of the water, i don't know what they did but it seems to work.
« Last Edit: March 19, 2015, 07:28:27 PM by BielBdeLuna »

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: How would you make a good looking water surface ?
« Reply #7 on: March 19, 2015, 07:32:27 PM »
you will need to translate the fresnel.vfp to glsl.
in the dark mod they did a water with a heathaze that didn't deform the stuff in.front of the water, i don't know what they did but it seems to work.

Well, I need to figure out water in plain Doom 3 first. I don't know why I can't get results (even without Fresnel) I see on other mods.

Heat haze and edge artifacts is a well know bug that is in almost any engine. They just mask it (if you look carefully around the edges, warping effect is missing). The issue isn't noticeable in my game, unless you are specifically looking for it :)

nbohr1more

  • Jr. Member
  • **
  • Posts: 97
  • Karma: +13/-8
  • Doom Newbie
    • View Profile
Re: How would you make a good looking water surface ?
« Reply #8 on: March 19, 2015, 08:27:43 PM »
We fixed problems with foreground objects interacting with some of our water shaders by sampling the Depth Buffer.
Any of the "haze" VFP's that have "Depth" in the name do this but some the developer (SteveL) didn't want trample on other
materials that might intend that effect so it wasn't done for all. Arcturus's water shader in the TDM forums uses one of the VFP's
without the depth sample but I'll be it would work to swap out the better version.

[/youtube]

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: How would you make a good looking water surface ?
« Reply #9 on: March 19, 2015, 09:48:30 PM »
I think I got it working (in Phaeton):


Had to do it in 3 layers (overdraw is intense I bet) - bottom layer is reflection with Fresnel, middle layer is color/normal/spec/gloss and the upper layer is refraction. Also turned out my normal map's Y was inverted :)

Thanks for the input guys.
« Last Edit: March 19, 2015, 10:01:24 PM by motorsep »

BloodRayne

  • Old Forum Goer
  • Full Member
  • ***
  • Posts: 136
  • Karma: +13/-0
  • Doom Newbie
    • View Profile
    • Grimm Quest for the Gatherer's Key
Re: How would you make a good looking water surface ?
« Reply #10 on: March 20, 2015, 02:03:13 PM »
I think I got it working (in Phaeton):


Had to do it in 3 layers (overdraw is intense I bet) - bottom layer is reflection with Fresnel, middle layer is color/normal/spec/gloss and the upper layer is refraction. Also turned out my normal map's Y was inverted :)

Thanks for the input guys.
Looks great!

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel

oneofthe8devilz

  • Sr. Member
  • ****
  • Posts: 374
  • Karma: +96/-87
  • Doom Newbie
    • View Profile
    • Scared Pixel Studios
Re: How would you make a good looking water surface ?
« Reply #12 on: March 21, 2015, 07:01:38 AM »
I wish someone would fix Doom3's mirror shader...

The way it currently calculates reflections is very limiting as it keeps rendering objects that lay inside the mirroring plane which makes it pretty much unusable... 
I got six little friends and they all run faster than you ;)


Check out our mods at
moddb or the SPS Homepage

motorsep

  • Hero Member
  • *****
  • Posts: 1,008
  • Karma: +74/-131
  • Artist
    • View Profile
    • Kot in Action Creative Artel
Re: How would you make a good looking water surface ?
« Reply #13 on: March 21, 2015, 10:35:14 AM »
I wish someone would fix Doom3's mirror shader...

The way it currently calculates reflections is very limiting as it keeps rendering objects that lay inside the mirroring plane which makes it pretty much unusable...

It's actually the most accurate mirror out there. Most games either have none, or have post process reflections. What kind of limitation did you run into with it?

oneofthe8devilz

  • Sr. Member
  • ****
  • Posts: 374
  • Karma: +96/-87
  • Doom Newbie
    • View Profile
    • Scared Pixel Studios
Re: How would you make a good looking water surface ?
« Reply #14 on: March 21, 2015, 11:19:43 AM »
R u serious ?

The bug is even visible in your own water youtube video showcase... look closely at the water surface reflection in your video at 0:30 at 0:38 and again at 0:50...

The part of your pool ladder that is under water (inside the mirror reflection plane) is rendered magnified on top of your water mirroring surface...

This actually happens with EVERY object in Doom3 that intersects and continues below the water/mirror line.

:o

And here a more detailed illustration of the problem:



See how the reflection is continuing to draw/reflect the parts of the marine (his legs and boots) which clearly lay below the water/mirror line ?
« Last Edit: March 21, 2015, 11:43:38 AM by oneofthe8devilz »
I got six little friends and they all run faster than you ;)


Check out our mods at
moddb or the SPS Homepage