Jump to content

Fresnel and Blinn-Phong


havenphillip

1,656 views

 Share

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:

fresnel.thumb.jpg.206319ffced0a26fa568b30b094b3319.jpg

09_fresnel.zip

 

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).

Blinn-Phong:

blinnphong.thumb.jpg.e1fcb5ca9b615801e3741d80b3d83240.jpg

10_blinn-phong.zip

 

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

toonlighting.thumb.jpg.ca081728ac91ef3b2187662d9c2e2ea4.jpg

11_toon lighting.zip

 

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

pearl.thumb.jpg.f4a6242011ce6e5fd2385627bb94ff57.jpg

12_pearl.zip

Here's a blinn-phong with alpha:

bpa.thumb.jpg.de61d7559013c1a497fe523bdab387da.jpg

13_blinn-phong + alpha.zip

 

Next: Skybox Reflections...

  • Like 7
 Share

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.

image.thumb.png.139afff3f4a046e0e224bbc4a2486db3.png

  • Like 2
Link to comment
Guest
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...