getting subnode id

This commit is contained in:
Piotrek
2021-04-18 23:02:17 +02:00
parent 3e94e5d2cf
commit 5e8068705a
2 changed files with 25 additions and 12 deletions
Binary file not shown.
+25 -12
View File
@@ -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