Reflecting and refracting water

Posted By: Roel

Reflecting and refracting water - 07/30/08 14:03

Hi

Some week ago I was searching for a hlsl shader which supports
both reflection and refraction.
the shader in the templates has some strange distortion if the camera moves close
It might be blind, but I didn't find any
I made my own now, using reflection and refraction.

If you have questions, you may email me at leor_hectometer@hotmail.com
or just pm me


a picture

here is the link
water shader download

note, the refraction uses some fresnel, so it can be hard to see some times
Posted By: VeT

Re: Reflecting and refracting water - 07/30/08 14:29

looking great smile
Posted By: Blade280891

Re: Reflecting and refracting water - 07/30/08 14:30

Just wondering , does this have things like ripple effects?
Posted By: Slin

Re: Reflecting and refracting water - 07/30/08 14:33

you should check out lerp() wink
and the fresnel isnīt very correct... You need to get use the pixelposition in worldspace (you will need more vertices for the water...) and I am pretty sure that you donīt have to convert the valuerange.
Other than that it looks very nice smile
Posted By: Roel

Re: Reflecting and refracting water - 07/30/08 14:59

thank you for the comments very much

Originally Posted By: Slin
You need to get use the pixelposition in worldspace (you will need more vertices for the water...)


I moved the pixelpositon stuff to the pixel, because this eliminates the distortion when you look at the water really close
I think you mean that?
Posted By: Slin

Re: Reflecting and refracting water - 07/30/08 15:04

Nope, I meant for calculating vecView. For calculating it you need the vertexposition in worldspace.
Posted By: Roel

Re: Reflecting and refracting water - 07/30/08 15:05

I will look at it, thanks
Posted By: msl_manni

Re: Reflecting and refracting water - 07/30/08 15:35

Can I have rapidshare download link please? The filefront link is not working for me, cant download anything from filefront.
Posted By: Slin

Re: Reflecting and refracting water - 07/30/08 15:58

Something you could add is specularity for the sun.
It is very easy to add but improves the look a lot wink You can check out a tutorialchapter about it here: http://www.riemers.net/eng/Tutorials/XNA/Csharp/Series4/Specular_highlights.php
Posted By: Scorpion

Re: Reflecting and refracting water - 07/30/08 17:18

normally you could use the out-coordinate of the vs for projecting, but then the effect you described occurs. I didn't find a way to stop the shader doing that.

I think you use tex2Dproj() for it...the problem is, that ps<2.0 don't support it.
Posted By: frazzle

Re: Reflecting and refracting water - 07/30/08 18:41

Nice UC, pretty handy yes smile smile
When looking at a water shader, their are 2 things I immediatly look at since they are quite important for a proper water shader:

- Fresnel term
- lerp function

1) Regarding Fresnel, the function you used isn't fully correct although it is an approximated version but abit rough wink wink
This is a better approximated version of the Fresnel term:

// Schlick's approximation, accurate to within 1% ^^
const float FRI = 0.01f; // FRI is the Fresnel reflectance index of the material at normal incidence
float F = FRI + (1 - FRI) * pow((1 - N.V), 5.0f);

Important note is that this function is mostly used for outdoor scenes but it would fail in indoor games. The reason therefore is that attenuation is used for indoor light sources.

2) Regarding the lerp function, it's better to combine your color calculations within the pixel shader via lerp. Look at the beaty of the methode:

lerp(a,b,c)
// returns a + c.(b-c)
// when c = 0, a will get returned
// when c = 1, b will get returned

Thus when using this as a final calculation with water, you should input the corresponding parameters relative for a water shader to achieved a plausible output:

color = lerp(reflectColor,refractColor,F);

Not that your code was ineffective since the effect looks pretty nice but just to enhance the importance of little intrinsic functions smile smile

Thanks in progress

Frazzle
Posted By: jigalypuff

Re: Reflecting and refracting water - 07/30/08 20:14

getting a can`t load dll, it`s the render to texture one?
Posted By: Roel

Re: Reflecting and refracting water - 08/17/08 18:07

I improved the shader, you can download it here:
Download
Posted By: Roel

Re: Reflecting and refracting water - 08/19/08 16:38

I've taken the lerp function into the shader, thanks! smile

and yes, it is the render2texture dll. I do not have pro edition, and many other gstudio users either

about the fresnel, You are right, but I wanted to use the shader in indoor scenes too!
© 2024 lite-C Forums