Perhaps someone reading this will say, "Well, that's just a toy demo!" ... well ... until it's not.
I saw a video on my YouTube feed at about 9 AM EST and it inspired me, asking, "Can I do this SDF thing in Eiffel with Claude helping?"
The answer is: Simple SDF
Right now, Claude is busy planning out, implementing, and testing a cluster of new Eiffel classes that will be responsible for allowing one to build and compile shaders at design/build-time or at run-time. You might be wondering: How do the Shaders and the SDF work together?
The shaders interact with SDF through ray marching:
1. SDF Primitives → Distance functions in GLSL:
float sdSphere(vec3 p, float r) { return length(p) - r; } // Distance to sphere
float sdBox(vec3 p, vec3 b) { vec3 q = abs(p) - b; return length(max(q,0.0)); }
2. Scene Composition → Boolean operations combine primitives:
float sceneSDF(vec3 p) {
float d = sdSphere(p - vec3(0,1,0), 1.0); // Sphere at (0,1,0)
d = min(d, sdBox(p - vec3(2,0.5,0), vec3(0.5))); // Union with box
return d;
}
3. Ray Marching → GPU iteratively steps along rays:
vec3 ro = camera_pos; // Ray origin
vec3 rd = ray_direction; // Ray direction
float t = 0.0; // Distance traveled
for (int i = 0; i < 128; i++) {
vec3 p = ro + rd * t; // Current position
float d = sceneSDF(p); // Distance to nearest surface
if (d < 0.001) break; // Hit!
t += d; // Safe to step this far
}
4. Shading → Compute normals from gradient, apply lighting.
The Eiffel DSL will generate this GLSL automatically from SDF_SCENE objects.
---
GLSL (OpenGL Shading Language) is the C-like programming language used to write shaders for GPUs. Key points:
- Purpose: Programs that run on the GPU for rendering/compute
- Shader Types: Vertex, fragment, compute, geometry, tessellation
- Compiled to SPIR-V: For Vulkan (what shaderc does)
- Syntax: C-like with vector types (vec3, mat4), texture samplers
- Example:
#version 450
layout(local_size_x = 16, local_size_y = 16) in;
void main() {
vec2 uv = gl_GlobalInvocationID.xy;
// GPU parallel computation here
}