Analysis of Fresnel examples in ogre

Source: Internet
Author: User

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

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.