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 P_{i}L
in world space from a vertex or fragment, to the light or lights, and fetch the cubemap shadow using this vector.
P_{i}L
vector. ARM recommends you make the
local correction in the fragment shader to obtain more accurate shadows.C
to the intersection point P
. This gives you the final vector CP
that you use to
fetch the texel._EnviCubeMapPos
The cubemap origin
position._BBoxMax
The maximum point of the
bounding box of the environment._BBoxMin
The minimum point of the
bounding box of the environment.Pi
The fragment position in world
space.PiL
The 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.CP
vector:// 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;
CP
vector 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.
P_{i}L
. 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(P_{i}L, N),
0.0);
shadow
is the alpha value
fetched from the shadow cubemap.P_{i}L
is the normalized
fragment-to-light vector in world space.N
is the normal vector of the
surface in world space.This shadow technique can provide realistic soft shadows in your scene.
0.08
.dist
from 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;
texLod
by the distance
coefficient:texLod *= distanceCoefficient;
texCUBElod()
or the GLSL function textureLod()
. vec4
where XYZ
represents a direction vector and the W
component represents the LOD.CP.w = texLod; shadow = texCUBElod(cubemap, CP).a;