Skip to main content
GameDev.net gamedev.net
🔒 Locked

"Rendering Natural Waters" coefficients conversion

Started by Viik Mar 8, 2009 at 6:13 AM 9 replies 4.5k views
Original Post
Viik
Viik
I'm reading this article now: http://citeseer.ist.psu.edu/cache/papers/cs/26265/http:zSzzSzwww.cs.sunysb.eduzSz~ashzSzwaterCGF.pdf/premoze01rendering.pdf Technique looks quite good, especially ability to build different type of water with respect to it's color (open ocean, tropical coast, harbor). At the same time real time equation is pretty simple and fast as most of the coefficients can be precomputed on CPU. But there are one point that i'm concerned, provided coefficients should be used with wavelenght rather than RGB model. I had a similar experience with dynamic sky based on Perez model, all calculations was done using wavlenght and than converted from XYZ to RGB. For water there is no need to do all calculation in realtime as the most of parameters can be precalculated. The question is - is it possible to precalculated coefficients dependent on wavelength is such a way that they can be directly used in RGB space?
Yann L
Yann L
Quote:
Original post by Viik
The question is - is it possible to precalculated coefficients dependent on wavelength is such a way that they can be directly used in RGB space?

Depends on the type of simulation you're running. An RGB value is a type of SPD (spectral power distribution) also, but a much more crude one than a real SPD. It uses three rather wide wavelength ranges, which are partially overlapping. Now, consider an algorithm using, say, 20 narrow wavelength bands in its distribution:

*) If all manipulations dependent on the wavelength are carried out in the pre-process, and the end result while rendering is independent on the wavelength band, then it can safely be converted to an RGB value. An example would be a physically based radiosity system.

*) If the realtime shader carries out manipulations that are non-linear and dependent on the specific wavelength (eg. chromatic dispersion, diffraction, etc), then converting them to RGB will have an impact on the result, since the lambda-dependent calculations will now operate on fewer and wider bands. The net result is that the whole thing becomes more approximate and less precise. Depending on your application, the artifacts arising from this can range from completely invisible to absolutely unacceptable.

If the algorithm used in that paper is of the second type, then doing everything in RGB could produce lower quality or artifacts. But then again, it might still be completely acceptable visually.
filousnt
filousnt
Quote:
Original post by Viik
The question is - is it possible to precalculated coefficients dependent on wavelength is such a way that they can be directly used in RGB space?


yes. you can precompute a 1D or 2D texture. Both methods are based on Pre00/01.

1D way :
http://artis.imag.fr/Publications/2006/BD06a/water06.pdf
"4.1. Underwater light absorption" p5

2D way :
http://www.graphicon.ru/2004/Proceedings/Technical/2%5B2%5D.pdf

[Edited by - filousnt on March 8, 2009 11:22:09 AM]
Viik
Viik
Yann L
In that case it make a sence to try both variants, maybe difference would be subtle. Thank you for valuable information!

filousnt
Thank you for links, I saw a first one, but second is really nice surprise. I'll try to post results.
Viik
Viik
If I understand correctly we don't need any look-up textures. Reffering to filousnt's thread:
http://www.gamedev.net/community/forums/topic.asp?topic_id=497607
this formula from original paper:
L(0,θ,φ) = L(Z,θ,φ) e(−cR) + Ldf(0)(1 − e((−c+Kd cos θ)R))
containe two parameters that are in "radiance space": c and Kd, for Kd we have a table of values for corresponding wavelenght and c we need to completely calculate. If we focus only on one water type at a time than both of this values will be constant vectors. So, theoretically we can manually find these values without any calculations. But main issue is that vector of scalar under exponent dosnt give color variations like water have, all what you get is a specific color exponentially fading to black (no green->light_blue->dark_blue transition). The only point I can see it happening is that L(Z,θ,φ) e(−cR) and Ldf(0)(1 − e((−c+Kd cos θ)R)) would give different colors. But again that would be a blend of two scalar vectors raised by exponent.
I'm missing something?
Viik
Viik
Just to summarise, I dont see how technically results shown here
http://artis.imag.fr/Publications/2006/BD06a/water06.pdf
(I'm talking about small 1D look up texture) can be achived using this method.

Maybe there are more simple and nice way to imitate shallow water color.
Viik
Viik
Decided to drop "accurate" calculations, simple expression as:
refraction = refr_texture * exp((-scatering_color) * waterVolumeLenght) + backScatering_color

gives such results:
WIP Powerboat - water scatering 02
WIP Powerboat - water scatering 01

Back scatering can be more complex, using second exponent for it gives more interesting shades but it's more difficult to tweak final color.

Bytheway, your landscape shape is very important. So even if you have a good parameters, untypical terrain can ruin effect.
filousnt
filousnt
Nice :)

post some code, if you don't mind.
Viik
Viik
This is part from shader:
	float3	ext_coef = exp(-(ext_color) * depthDelta.x);	float3	backScaterCoef = back_scat_color * shadow * .5f + back_scat_color * .5f;	half3	refraction = refr_texture * ext_coef + backScaterCoef;			color = lerp(refraction, ref_texture, fresnel_term);			/* ext_color - vector of water extinction coefficients  depthDelta.x - distance from water surface to bottom along view vector  back_scat_color - back-scatering color*/


Just need to carefully tweak parameters. Back scatering should be very small, this gives a small tint to water color. Extinction coefficients can be bigger than 1, bigger values gives very "foggy water".

It makes sence to build back_scatering more complex, influence it by sky color and LdotN with sun. Make it dependable from depth, so it dosnt influence color too much in shallow waters. Didn't find yet a good combination of coefficients for what I want.

Some examples with used parameters:

Photobucket

Photobucket

Photobucket
JorenJoestar
JorenJoestar
Great shots!
The feeling is really good...it feels like being near the sea :)

A question if I may...how do achieve caustics? Are them physically computed or textures?

thanks!
---------------------------------------http://badfoolprototype.blogspot.com/
Viik
Viik
Just textures, you can take 2-3 different textures, animate texture coordinates and combined them in real-time. Or even map them using projection from sun, anyway you would have it if you using shadow maps.

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.