Recently, we need to study water implementation and add water to the client for testing to easily implement water refraction and reflection.
Note: The demo demo_fresnel in ogre1.7 already exists.
Keywords: RTT Fresnel
Implementation Method:
First, you must manually create two texture, one for rendering reflection and the other for rendering refraction.
At last, Fresnel is used as the weight to perform color interpolation in the refraction and reflection textures.
Note:
When the texture is rendered twice, you need to implement the rendertarget listener: rendertargetlistener.
Void prerendertargetupdate (const rendertargetevent & EVT)
{
// Sets the water entity to be invisible.
// Set the camera as an image for reflection.
// Set the custom near-cut plane
//! Attention
Note that a mistake was made here to use the same plane for reflection and refraction (the plane for reflection is normal to Y axis up, and the normal of the refraction plane is opposite to that of reflection ).
}
Void postrendertargetupdate (const rendertargetevent & EVT)
{
// Related recovery
}
Shader analysis:
Here is the implementation Part Of The pixel shadow. In the material script, we can see three texture items.
1. Texture waves2.dds
2. Texture reflection
3. Texture Refraction
2 and 3 do not need to be described as manually created textures. 1 is Perlin Noise volume.
In the shader code, we can see that by sampling waves2.dds and finding out the normal interference, we can interfere with the reflection and refraction textures.
Float2 final = projectioncoord. XY/projectioncoord. W;
// Noise
Float3 noisenormal = (tex2d (noisemap, (noisecoord. XY/5). RGB-0.5). rbg * noisescale;
Final + = noisenormal. xz;
The Fresnel term is calculated using the Fresnel simple formula. The actual Fresnel is complex, fresnelbias is the offset coefficient, fresnelscale is the scaling coefficient, fresnelpower is the Fresnel index, and eyedir is the angle vector, n is the normal vector.
Float Fresnel = fresnelbias + fresnelscale * POW (1 + dot (eyedir, normal), fresnelpower );
Finally, the reflection and refraction are interpolated according to the Fresnel coefficient.
From: http://blog.csdn.net/nullah/archive/2010/05/03/5553668.aspx