User Tools

Site Tools


Image-Based Ambient Lighting

Simple in its approach, this effect tries to add environmental color to the ambient lighting of a particular tree model. A typical input image would be sky blue at the top and green at the bottom. The amount that this value impacts the ambient lighting is controlled per-base tree via CCore::SetAmbientImageScalar(). In our reference application, this value can also be set per base tree. This is useful for early experimenting.

The shader lookup function itself is in the shader template file Include_LightingUtility.fx and is called AmbientImageContribution():

///////////////////////////////////////////////////////////////////////
//  Helper Function: AmbientImageContribution
 
float3 AmbientImageContribution(float3 vNormal, float fScalar)
{
	// compute uv lookup into image map
	const float c_fImageMapU = vNormal.x * 0.5 + (ST_COORDSYS_Z_UP ? vNormal.y : vNormal.z) * 0.5;
	const float c_fImageMapV = ((ST_COORDSYS_Z_UP ? vNormal.z : vNormal.y) + 1.0) * 0.5;
 
	return fScalar * ST_TEXTURE_SAMPLE_LINEAR_WRAP(ImageBasedAmbientLightingMap, 
                                                       float2(c_fImageMapU, 1.0 - c_fImageMapV)).rgb;
}