Files
Demo/sdf.fs

37 lines
682 B
GLSL

R"###(
#version 330 core
out vec4 FragColor;
in vec2 texCoords;
vec3 center = vec3(0.0f,0.0f,20.0f);
float radius = 5.0f;
float sphereMin(vec3 pos){
return length(pos - center) - radius;
}
void main()
{
vec3 ray = vec3(texCoords.x, texCoords.y,2.0f);
ray = (ray - 0.5f) * 2;
vec3 pos = ray;
float min = sphereMin(ray);
while( (min < 100.0f) && (min > 0.1f) ) {
ray = normalize(ray);
ray = ray * min;
pos = pos + ray;
min = sphereMin(pos);
}
if(min <= 0.2f){
FragColor = vec4(texCoords.x, texCoords.y, 0.2f, 1.0f);
} else {
FragColor = vec4(0.0f,0.0f,0.0f,1.0f);
}
}
)###";