Fresnel Effect
by Daniel Ly · in Torque Game Engine · 06/26/2006 (9:47 am) · 3 replies
Hey All,
I'm trying to implement the Fresnel effect on some gooey models in TGE but I'm having some problems on finding out where to start.
The Fresnel effect occurs since the amount of reflection is dependant on the viewing angle. For example, you can see straight through the middle of a glass rod, but the edge of the rod reflects light. Take a look at http://stevenchan.us/publications/mayafacingratio, and scroll down to the image "Facing ratio connected to transparency" for an example.
The concept seems simple enough: just take the dot product of the camera's directional vector and the surface's normal and use that to map the transparency value. Unfortunately, I can't seem to figure out where the engine implements the rendering or how to get a handle on each vector. If someone can point out where are some of the rendering blocks or how to manipulate the necessary vectors, that would be great.
Thanks,
Daniel
I'm trying to implement the Fresnel effect on some gooey models in TGE but I'm having some problems on finding out where to start.
The Fresnel effect occurs since the amount of reflection is dependant on the viewing angle. For example, you can see straight through the middle of a glass rod, but the edge of the rod reflects light. Take a look at http://stevenchan.us/publications/mayafacingratio, and scroll down to the image "Facing ratio connected to transparency" for an example.
The concept seems simple enough: just take the dot product of the camera's directional vector and the surface's normal and use that to map the transparency value. Unfortunately, I can't seem to figure out where the engine implements the rendering or how to get a handle on each vector. If someone can point out where are some of the rendering blocks or how to manipulate the necessary vectors, that would be great.
Thanks,
Daniel
About the author
#2
For pixel perfect results, you will need to use a pixel shader. Using TSE, you would be able to construct a Fresnel shader for the object with possibly no code change to the engine.
06/26/2006 (1:36 pm)
TSMesh::render is where actual triangles get sent to opengl for most shapes (terrain & interriors are handled elsewhere), but as was stated above, you probably want to do the processing of the vertex alpha in ShapeBase::prepRenderImage based on a flag or subclass ShapeBase and make a special object type. Then it is a matter of rotating the camera's directional vector into object space for your test.For pixel perfect results, you will need to use a pixel shader. Using TSE, you would be able to construct a Fresnel shader for the object with possibly no code change to the engine.
#3
But I'm sure you can fake fresnel by using environment mapping. With proper OpenGL TEV (texture environment) settings, you can map a texture as environment-mapped (it's UV coords are calculated based on the vertices' normals and the view direction) and use it to mask another texture, creating a fresnel effect.
06/27/2006 (5:00 am)
TGE only touches TSShape's individual vertices while updating skinned meshes, when it re-calculates the position of each vertex based on the bones' transformations. That'd be the most suitable place for doing extra stuff yo your vertices.But I'm sure you can fake fresnel by using environment mapping. With proper OpenGL TEV (texture environment) settings, you can map a texture as environment-mapped (it's UV coords are calculated based on the vertices' normals and the view direction) and use it to mask another texture, creating a fresnel effect.
Torque Owner John Doppler Schiff
Hopefully someone with (much) more experience tinkering under the hood will be of more help.