Last active
May 22, 2021 12:29
-
-
Save behreajj/ce10cca6c337373f797d0d579181dada to your computer and use it in GitHub Desktop.
linearGradient.osl
This file contains hidden or 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
float scalarProj(vector a, vector b) { | |
return dot(a, b) / dot(b, b); | |
} | |
float uquantize(float x, int levels) { | |
return select( | |
max(0.0, (ceil(x * levels) - 1.0) / (levels - 1.0)), | |
x, levels < 2); | |
} | |
shader linearGradient( | |
point Origin = point(-1.0, 0.0, 0.0), | |
point Dest = point(1.0, 0.0, 0.0), | |
point Point = P, | |
int Quantize = 0, | |
output float Fac = 0.0, | |
output float Dot = 0.0, | |
output point Vector = 0.0) { | |
point a = Point - Origin; | |
point b = Dest - Origin; | |
Dot = scalarProj(a, b); | |
Fac = uquantize(clamp(Dot, 0.0, 1.0), Quantize); | |
Vector = Origin + b * Fac; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment