Created
July 17, 2020 09:20
-
-
Save CedricGuillemet/7c4cc0b8e15be56c08e4112f1bd8c9d1 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
float distanceFromSurface = 0.0; | |
float step = 0.03; | |
vec3 previousPosition = vPosition; | |
float previousDistance = 0.; | |
for (int i = 0; i < 100; i++) { | |
vec3 currentPosition = vPosition + distanceFromSurface * rayDir; | |
float distance = sphereDistance(currentPosition, sphereCenter, 1.0); | |
if (distance < 0.) { | |
vec3 hitPosition = mix(previousPosition, currentPosition, previousDistance / (previousDistance - distance)); | |
vec3 normal = (hitPosition - sphereCenter); | |
float dotLight = dot(normal, ligthDirection) * 0.5 + 0.5; | |
float noiseTexture = simplex3d(hitPosition * 4.0) * 0.5 + 0.5; | |
gl_FragColor = vec4(vec3(1.0, 0.5, 0.2) * dotLight * noiseTexture, 1.0); | |
return; | |
} | |
distanceFromSurface += step; | |
previousPosition = currentPosition; | |
previousDistance = distance; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment