News:

One Minute Game Review by The Happy Friar: https://ugetube.com/@OneMinteGameReviews
Also on Rumble: https://rumble.com/c/c-1115371

idTech 4 (aka Doom 3 tech) Discord Server! https://discord.gg/9wtCGHa

Main Menu

How would you make a good looking water surface ?

Started by motorsep, March 18, 2015, 11:21:23 PM

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

motorsep

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):

https://www.youtube.com/watch?v=vP6k7ncWk9w

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

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):

https://www.youtube.com/watch?v=TPqRipp8YLE

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

BielBdeLuna

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

#2
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):

# 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.

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

motorsep

Quote from: BloodRayne 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 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

#4
Quote from: motorsep on March 19, 2015, 02:35: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.

motorsep


BielBdeLuna

#6
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.

motorsep

Quote from: BielBdeLuna 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.

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

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.


motorsep

#9
I think I got it working (in Phaeton):

https://www.youtube.com/watch?v=Qpy_o8aBoHQ

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.

BloodRayne

Quote from: motorsep on March 19, 2015, 09:48:30 PM
I think I got it working (in Phaeton):

https://www.youtube.com/watch?v=Qpy_o8aBoHQ

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!


oneofthe8devilz

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

Quote from: oneofthe8devilz 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...

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

#14
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 ?
I got six little friends and they all run faster than you ;)


Check out our mods at
moddb or the SPS Homepage