-
-
Save kayk5654/3b56c9fa8df61b7f75affb4b8096ca7d 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
// fit a value in a specific range to another specific range | |
float fitRange(float value, float inMin, float inMax, float outMin, float outMax) | |
{ | |
float lerpFactor = lerp(0, 1, (clamp(value, inMin, inMax) - inMin) / (inMax - inMin)); | |
return lerp(outMin, outMax, lerpFactor); | |
} | |
// get reflection vector for box projection | |
float3 boxProjection(half3 worldRefl, float3 worldPos, float3 cubemapCenter, float3 boxMin, float3 boxMax) | |
{ | |
// normalize reflection vector | |
half3 normalizedDir = normalize(worldRefl); | |
// get magnitude of a vector from world position to the closest surface of a box | |
half3 magnitudeMax = (boxMax - worldPos) / normalizedDir; | |
half3 magnitudeMin = (boxMin - worldPos) / normalizedDir; | |
half3 magnitude = (normalizedDir > 0) ? magnitudeMax : magnitudeMin; | |
half smallestMagnitude = min(min(magnitude.x, magnitude.y), magnitude.z); | |
// adjust reflection vector considering position offset of world position from cubemap center | |
return (worldPos - cubemapCenter) + normalizedDir * smallestMagnitude; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment