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).
Blinn-Phong:
If you stagger the light falloff in the blinn-phong you can create a toon lighting effect:
Here you have two colors mixed by a fresnel effect to create a pearl effect:
Here's a blinn-phong with alpha:
Next: Skybox Reflections...
- 7
1 Comment
Recommended Comments