|Non-Confidential||PDF version||ARM 100140_0201_00_en|
|Home > Advanced Graphics Techniques > Dynamic soft shadows based on local cubemaps > Rendering shadows|
Build a vector
PiL in world space from a vertex or fragment, to the light or lights, and fetch the cubemap shadow using this vector.
PiLvector. ARM recommends you make the local correction in the fragment shader to obtain more accurate shadows.
Cto the intersection point
P. This gives you the final vector
CPthat you use to fetch the texel.
_EnviCubeMapPosThe cubemap origin position.
_BBoxMaxThe maximum point of the bounding box of the environment.
_BBoxMinThe minimum point of the bounding box of the environment.
PiThe fragment position in world space.
PiLThe normalized fragment-to-light vector in world space.
CP. This is the corrected fragment-to-light vector that you use to fetch a texel from the shadow cubemap.
// Working in World Coordinate System. vec3 intersectMaxPointPlanes = (_BBoxMax - Pi) / PiL; vec3 intersectMinPointPlanes = (_BBoxMin - Pi) / PiL; // Looking only for intersections in the forward direction of the ray. vec3 largestRayParams = max(intersectMaxPointPlanes, intersectMinPointPlanes); // Smallest value of the ray parameters gives us the intersection. float dist = min(min(largestRayParams.x, largestRayParams.y), largestRayParams.z); // Find the position of the intersection point. vec3 intersectPositionWS = Pi + PiL * dist; // Get the local corrected vector. CP = intersectPositionWS - _EnviCubeMapPos;
CPvector to fetch a texel from the cubemap. The alpha channel of the texel provides information about how much light or shadow you must apply to a fragment:
float shadow = texCUBE(cubemap, CP).a;
The cubemap shadow technique does not use depth information to apply shadows. This means that some faces are incorrectly lit when they are meant to be in shadow.
PiL. If the angle, in degrees, is outside of the range -90 to 90, the surface is in shadow.
if (dot(PiL,N) < 0) shadow = 0.0;
shadow *= max(dot(PiL, N), 0.0);
shadowis the alpha value fetched from the shadow cubemap.
PiLis the normalized fragment-to-light vector in world space.
Nis the normal vector of the surface in world space.
This shadow technique can provide realistic soft shadows in your scene.
distfrom the code snippet for local correction as the length of the segment from the fragment position to the intersection point of the fragment-to-light vector with the bounding box:
float texLod = dist;
texLodby the distance coefficient:
texLod *= distanceCoefficient;
texCUBElod()or the GLSL function
XYZrepresents a direction vector and the
Wcomponent represents the LOD.
CP.w = texLod; shadow = texCUBElod(cubemap, CP).a;