diff --git a/src/shaders/bin/shader.frag.spv b/src/shaders/bin/shader.frag.spv index d33f54e..0823b7b 100644 Binary files a/src/shaders/bin/shader.frag.spv and b/src/shaders/bin/shader.frag.spv differ diff --git a/src/shaders/raycasting.cginc b/src/shaders/raycasting.cginc index a2bb3b5..bc0357d 100644 --- a/src/shaders/raycasting.cginc +++ b/src/shaders/raycasting.cginc @@ -1,4 +1,24 @@ +/* + point: Hit point + view: View vector (camera ray) + normal: Normal vector +*/ +vec3 solve(vec3 point, vec3 view, vec3 normal) +{ + // Lighting + vec3 light_color = vec3(1.0, 1.0, 1.0); + vec3 light_dir = normalize(point-vec3(0.0, 1.5, 4.0)); + + vec3 ambient = light_color * 0.1; + vec3 diffuse = light_color * max(1.0-dot(normal, light_dir), 0.0); + vec3 specular = light_color * pow(max(dot(view, reflect(-light_dir, normal)), 0.0), 32); + + // Combine colors + vec3 object_color = vec3(0.0, 0.1, 0.5); + return (ambient + diffuse + specular) * object_color; +} + vec3 raycast(vec3 origin, vec3 dir) { // Round input pos to nearest voxel @@ -13,7 +33,7 @@ vec3 raycast(vec3 origin, vec3 dir) // Closest axis to increment in grid will be stored here (x=1 or y=1 or z=1) vec3 incAxis = vec3(0,0,0); - + float level = 1; for(int i=0;i<50;i++) { // Get node @@ -27,17 +47,10 @@ vec3 raycast(vec3 origin, vec3 dir) // Normal vector (negate previous increment axis and mult by sign) vec3 normal = -incAxis * raySign; - // Lighting - vec3 light_color = vec3(1.0, 1.0, 1.0); - vec3 light_dir = normalize(point-vec3(0.0, 1.5, 4.0)); - - vec3 ambient = light_color * 0.1; - vec3 diffuse = light_color * max(1.0-dot(normal, light_dir), 0.0); - vec3 specular = light_color * pow(max(dot(dir, reflect(-light_dir, normal)), 0.0), 32); - - // Object color - vec3 object_color = vec3(0.0, 0.1, 0.5); - return (ambient + diffuse + specular) * object_color; + // Get subnode + return step(vec3(0.5, 0.5, 0.5), point - pos); + + //return solve(point, dir, normal); } // Get new closest axis to increment