Created
December 5, 2019 18:55
-
-
Save Piratkopia13/c2b646b5209196b0909a00d12c6fd823 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Calculates the angle of a cone that starts at position worldPosition and perfectly | |
// encapsulates a sphere at position light.position with radius light.radius | |
float3 toLight = normalize(light.position - worldPosition); | |
// Calculate a vector perpendicular to L | |
float3 perpL = cross(toLight, float3(0.f, 1.0f, 0.f)); | |
// Handle case where L = up -> perpL should then be (1,0,0) | |
if (all(perpL == 0.0f)) { | |
perpL.x = 1.0; | |
} | |
// Use perpL to get a vector from worldPosition to the edge of the light sphere | |
float3 toLightEdge = normalize((light.position + perpL * light.radius) - worldPosition); | |
// Angle between L and toLightEdge. Used as the cone angle when sampling shadow rays | |
float coneAngle = acos(dot(toLight, toLightEdge)) * 2.0f; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment