Thursday, February 16, 2012

Andrew Harmon - Weekly Report #3

One interesting thing that I did recently that someone could possibly find useful was creating a fog affect in an underwater ocean scene. The basic concept is that the further an object is from the camera, the more the color changes from one to another. So in a way the scene becomes kind of like a 3D gradient.

The changes that need to be made will take place in the fragment or pixel shader. First you must initialize your fog color, as well as the fog start distance (where does the change of color begin to take place in relation to your camera) and also the fog end distance (at what point is there no longer a change in color based on distance).

The remaining bit of code looks like this.

float diffuseIntensity = saturate( dot(-lightDirection, input.WorldNormal));   
float4 diffuseColor = lightColor * diffuseIntensity;  
float4 specularIntensity = specularColor *  pow( saturate(dot(input.refractVector, input.directionToCamera)), 1.0);   
float l = saturate((input.Position.z - FogStart) / (FogEnd - FogStart));

return float4(lerp(input.Color,FogColor, l));

input.Position in this case is the camera position. You will use this to figure out how far the pixel is from your camera. And based on the you will use the lerp function to effect the color based on "l". (that is an l as in lion, not the number 1)

You will then return color based on the calculation.

No comments:

Post a Comment