summaryrefslogtreecommitdiff
path: root/assets/final/shaders/renderer_3d.wgsl
diff options
context:
space:
mode:
Diffstat (limited to 'assets/final/shaders/renderer_3d.wgsl')
-rw-r--r--assets/final/shaders/renderer_3d.wgsl37
1 files changed, 3 insertions, 34 deletions
diff --git a/assets/final/shaders/renderer_3d.wgsl b/assets/final/shaders/renderer_3d.wgsl
index 1183e3c..d3b0bae 100644
--- a/assets/final/shaders/renderer_3d.wgsl
+++ b/assets/final/shaders/renderer_3d.wgsl
@@ -1,5 +1,6 @@
#include "common_uniforms"
#include "math/common_utils"
+#include "math/sdf_utils"
@group(0) @binding(0) var<uniform> globals: GlobalUniforms;
@group(0) @binding(1) var<storage, read> object_data: ObjectsBuffer;
@@ -135,41 +136,9 @@ fn fs_main(in: VertexOutput) -> FragmentOutput {
let q_hit = ro_local + rd_local * t;
p = (obj.model * vec4<f32>(q_hit, 1.0)).xyz; // Correct world position
- // Calculate normal with bump mapping
- let e = vec2<f32>(0.005, 0.0);
+ // Calculate normal with bump mapping (using utility function)
let disp_strength = 0.05;
-
- let q_x1 = q_hit + e.xyy;
- let uv_x1 = spherical_uv(q_x1);
- let h_x1 = textureSample(noise_tex, noise_sampler, uv_x1).r;
- let d_x1 = get_dist(q_x1, obj.params) - disp_strength * h_x1;
-
- let q_x2 = q_hit - e.xyy;
- let uv_x2 = spherical_uv(q_x2);
- let h_x2 = textureSample(noise_tex, noise_sampler, uv_x2).r;
- let d_x2 = get_dist(q_x2, obj.params) - disp_strength * h_x2;
-
- let q_y1 = q_hit + e.yxy;
- let uv_y1 = spherical_uv(q_y1);
- let h_y1 = textureSample(noise_tex, noise_sampler, uv_y1).r;
- let d_y1 = get_dist(q_y1, obj.params) - disp_strength * h_y1;
-
- let q_y2 = q_hit - e.yxy;
- let uv_y2 = spherical_uv(q_y2);
- let h_y2 = textureSample(noise_tex, noise_sampler, uv_y2).r;
- let d_y2 = get_dist(q_y2, obj.params) - disp_strength * h_y2;
-
- let q_z1 = q_hit + e.yyx;
- let uv_z1 = spherical_uv(q_z1);
- let h_z1 = textureSample(noise_tex, noise_sampler, uv_z1).r;
- let d_z1 = get_dist(q_z1, obj.params) - disp_strength * h_z1;
-
- let q_z2 = q_hit - e.yyx;
- let uv_z2 = spherical_uv(q_z2);
- let h_z2 = textureSample(noise_tex, noise_sampler, uv_z2).r;
- let d_z2 = get_dist(q_z2, obj.params) - disp_strength * h_z2;
-
- let n_local = normalize(vec3<f32>(d_x1 - d_x2, d_y1 - d_y2, d_z1 - d_z2));
+ let n_local = get_normal_bump(q_hit, obj.params, noise_tex, noise_sampler, disp_strength);
normal = transform_normal(obj.inv_model, n_local);
// Apply texture to SDF color