Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Fresnel and Blinn-Phong



If you took a bowl full of water and looked straight down into the bowl, the water would be clear. But if you were to then move the bowl up to your eye and look from the side along the surface of the water, you'd see it becomes highly reflective. That's fresnel.

It's a cool effect. And it's easy to code. You add a uniform vec3 cameraposition towards the top and a fresnel color, and then a fresnel effect is little more than this:

vec3 eyevec = normalize(cameraposition - ex_vertexposition.xyz);
float ndotv = dot(normal,eyevec);

After that all you need to do is output it. I put it in the specular output (fragData2). But you can put it in the the diffuse output as well. You just mix these two colors by the fresnel effect (or the 1.0-fresnel effect):

fragData0 = mix(outcolor,fresnel color,ndotv);

...and there it is. Effects like this are nice because you can just keep tweaking them to make different things:




So if fresnel is a step up from the base shader, blinn-phong seems to me like a logical second step. Blinn-phong puts a "dot" on an object which simulates a light. I find this useful in particular if you want to z-sort a material to gain semi-transparency. For instance, glass. The problem is once you z-sort it you lose specular information. So you can add a blinn-phong to your object and maintain specular. You can also adjust the size of the dot to give the impression of "shininess" like you can with specular. But one thing you can do quite easily with this is change the color of the light. Later I would like to write a shader that allows for multiple blinn-phong lights. I haven't gotten around to it.

So in the fresnel you established the normalized difference between the cameraposition (eye) and the object position(ex_vertexposition). With blinn-phong you also want to establish the normalized difference between the object position and a light source (projectionmatrix). You then add the fresnel to this, get your dot product just like in the fresnel, and then mix this into an output line (fragDatasomething).





If you stagger the light falloff in the blinn-phong you can create a toon lighting effect:


11_toon lighting.zip


Here you have two colors mixed by a fresnel effect to create a pearl effect:



Here's a blinn-phong with alpha:


13_blinn-phong + alpha.zip


Next: Skybox Reflections...

  • Like 6

1 Comment

Recommended Comments

Thanks for the Blinn-Phong shader. I was able to use your code to make a nice glass shader which uses Alpha blending and Z-Sort like my previous glass, but the added phong makes it less flat. The phong is relative to the camera's position, and everything can be changed with the material's colors and flags.


  • Like 2
Link to comment
Add a comment...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...