VSFX755 : Proc 3D/Shader Programming
PROFESSOR: Virginia Wissler
P1. Custom Shading Function
Project Brief: The assigned project is to create a custom shading function. The function chosen was that of a fake rim shader which would calculate a fake rim light effect built into the shader with user parameters to control the wrap amount, intensity, color, and thickness based off of a light's position. This functionality would then be added ontop of a standard plastic shader model with controllable diffuse wrap and specular.
Process: The following are steps which I took to achieve the fake rim effect and the process of implementing it with a plastic type shader.
Step 1.

Calculate the dot product of a normalized surface normal and camera view vector, and take the inverted result.
float VdotN = 1 - V.Nf;
Step 2.

VdotN is ran through a smoothstep function with user parameter control to adjust the fall off of the rim.
float rimMask = smoothstep(1.0 - rim_thickness, 1.0, VdotN);
Step 3.

Multiply the above rimMask by a modified diffuse function labeled: diffuseWrap().
diffuseWrap takes not only the surface normal but also a user defined variable called "wrapAmount." wrapAmount lets the user input a degree amount which allows the diffuse shading not to be limited to a 90degree maximum. Below, "rim_wrap" is the user parameter for the degree amount.
(diffuseWrap(Nf, rim_wrap) * rimMask)
Step 4.

The combined results are then added on top of another diffuseWrap function allowing the user to control the diffuse angle. Before we were using a lot of multiplication to make mattes. Here we are adding the final matte to the base diffuse to act as a rim effect.
(diffuseWrap(Nf, diffuse_wrap) * diffuse_color * Kd)
+
(diffuseWrap(Nf, rim_wrap) * rimMask * rim_color * rim_intensity)
Step 5.

The specular component is then added on top.
(diffuseWrap(Nf, diffuse_wrap) * diffuse_color * Kd)
+
(diffuseWrap(Nf, rim_wrap) * rimMask * rim_color * rim_intensity)
+
(specular(Nf, V, specular_roughness) * specular_color * Ks));
Step 6.

A final version showing off rim component and various colors for diffuse, spec, and the rim.
------------------------------------------Final Scene-----------------------------------------------
Render 01 (1 light, no rim applied, normal diffuse wrap)

Render 02 (0 light, rim applied, normal diffuse wrap)

Render 03 (1 light, rim applied, modified diffuse wrap)

Self Evaluation: The rim light wrap effect is very convenient because it allows you to create a soft light effect without heavy computing of an area light. Upon completing this process, I have gained a better understanding of how lighting models work via code. It was a interesting to see how much a surface is described based upon dot products. I am very comfortable with the compositing process it takes within the code to create such desired effects. The only shady area which still is challenging is that of illumance functions. Because it requires a more advanced understanding of math, it can be a bit tricky.
I would like to implement features such as inverting the rim and the option to use the fresnel effect in the opacity channel as well to create a x-ray effect. The shader as of now is still very useful, but could use some fine tuning with scene management. For instance, which lights are effected by the shader instead of all the lights in a scene. I would also need to modify the light shadows because as of now, they are not responding properly to the diffuse wrap modifier.





