random trace tweaks

This commit is contained in:
2025-07-10 20:50:59 +01:00
parent 52cc5c7385
commit e3d61c87f5
2 changed files with 21 additions and 38 deletions
+4 -3
View File
@@ -491,7 +491,8 @@ impl SSATape {
.begin_function( .begin_function(
float, float,
if with_module { Some(1000) } else { None }, if with_module { Some(1000) } else { None },
spirv::FunctionControl::DONT_INLINE //spirv::FunctionControl::DONT_INLINE
spirv::FunctionControl::INLINE
| spirv::FunctionControl::PURE | spirv::FunctionControl::PURE
| spirv::FunctionControl::CONST, | spirv::FunctionControl::CONST,
point_fn_type, point_fn_type,
@@ -1285,7 +1286,7 @@ impl SSATape {
b.end_function().unwrap(); b.end_function().unwrap();
} }
{ /*{
let _scene = b let _scene = b
.begin_function( .begin_function(
vec2, vec2,
@@ -2819,7 +2820,7 @@ impl SSATape {
} }
} }
b.end_function().unwrap(); b.end_function().unwrap();
} }*/
let module = b.module(); let module = b.module();
+10 -28
View File
@@ -1,5 +1,3 @@
// global fragment shader
#version 460 #version 460
#extension GL_GOOGLE_include_directive:require #extension GL_GOOGLE_include_directive:require
#include "include.glsl" #include "include.glsl"
@@ -12,41 +10,25 @@ layout(depth_greater) out float gl_FragDepth;
layout(location = 0) out uint material; layout(location = 0) out uint material;
const float EPSILON = .001; const float EPSILON = .001;
const uint MAX_STEPS = 50;
const float NEARPLANE = 0.;
float FARPLANE = length(object_uniforms.dimensions / 32.); float FARPLANE = length(object_uniforms.dimensions / 32.);
vec2 spheretracing(vec3 ori, vec3 dir, out vec3 p) {
vec2 td = vec2(NEARPLANE, 1.);
p = ori;
td.y = scene(vec4(p, camera_uniforms.campos_and_time.w)) * .98;
td.x += td.y;
p = fma(dir, vec3(td.x), ori);
for (int i = 0; td.y > EPSILON && td.x < FARPLANE; i++) {
td.y = scene(vec4(p, camera_uniforms.campos_and_time.w)) * .98;
td.x += td.y;
p = fma(dir, vec3(td.x), ori);
}
return td;
}
//Implicit Surface Entrypoint
void main() { void main() {
vec3 raypos = pos.xyz; vec3 raypos = pos.xyz;
vec3 p;
vec3 raydir = normalize(raypos - (pc.inv_world * vec4(camera_uniforms.campos_and_time.xyz, 1)).xyz); vec3 raydir = normalize(raypos - (pc.inv_world * vec4(camera_uniforms.campos_and_time.xyz, 1)).xyz);
vec2 td = spheretracing(raypos, raydir, p); vec3 p = raypos;
float total_dist = 0.;
if (td.y < EPSILON) do {
{ float dist = scene(vec4(p, camera_uniforms.campos_and_time.w)) * .98;
total_dist += dist;
p = fma(raydir, vec3(total_dist), raypos);
if (dist < EPSILON) {
vec4 tpoint = camera_uniforms.proj_view * pc.world * vec4(p, 1); vec4 tpoint = camera_uniforms.proj_view * pc.world * vec4(p, 1);
gl_FragDepth = (tpoint.z / tpoint.w); gl_FragDepth = (tpoint.z / tpoint.w);
material = object_uniforms.material; material = object_uniforms.material;
} return;
else } else if (total_dist > FARPLANE) {
{
discard; discard;
} }
} while (true);
} }