Przeglądaj źródła

Not working, problem with the type of the texture in the shader

Ghastrod 1 rok temu
rodzic
commit
080d8d7bcb
1 zmienionych plików z 21 dodań i 20 usunięć
  1. 21 20
      src/shaders/Heightmap_compute.wgsl

+ 21 - 20
src/shaders/Heightmap_compute.wgsl

@@ -1,44 +1,45 @@
 //Constants
-let PI: f32 = 3.14159265358979323846;
-let GRAVITY:f32= 9.81;
+const PI: f32 = 3.14159265358979323846;
+const GRAVITY:f32= 9.81;
 
 //Structs
-struct Complex{
-    a: f32,
-    b: f32
-}
+struct Complex {
+  a: f32,
+  b: f32,
+};
 
-fn add_complex(x:Complex, y:Complex)-> Complex{
-    return Complex(
-        x.a + y.a,
-        x.b + y.b 
-    )
+fn complex_add(a: Complex, b: Complex) -> Complex {
+  return Complex(
+    a.a + b.a,
+    a.b + b.b,
+  );
 }
 
-fn multiply_complex(x:Complex, y: Complex)->Complex{
-    return Complex(
-        (x.a * y.a) - (x.b * y.b),
-        (y.b * x.a) + (y.a * x.a)
-    )
+fn complex_multiply(a: Complex, b: Complex) -> Complex {
+  // Perform complex number multiplication (a + bi) * (c + di)
+  let real = a.a * b.a - a.b * b.b;
+  let imaginary = a.a * b.b + a.b * b.a;
+  return Complex(real, imaginary);
 }
+
 fn angle_to_complex(x:f32)-> Complex{
     return Complex(
         cos(x),
         sin(x)
-    )
+    );
 }
 
 struct ComputeInput{
     @builtin(local_invocation_id) local_invocation_id: vec3<u32>,
     @builtin(local_invocation_index) local_invocation_index: u32,
-    @builtin(global_invocation_index) global_invocation_index: vec3<u32>,
+    @builtin(global_invocation_id) global_invocation_id: vec3<u32>,
     @builtin(workgroup_id) workgroup_id: vec3<u32>,
     @builtin(num_workgroups) num_workgroups: vec3<u32>
 }
 
 //Actual code
 
-@group(0) @binding(0) var heightmap_texture: texture_2d<rgba8unorm,write>;
+@group(0) @binding(0) var heightmap_texture: texture_2d<rgba8unorm, write>;
 fn gaussian(x: f32, y:f32)-> f32{
     let mean = 0.0;
     let spread = 1.0;
@@ -57,7 +58,7 @@ fn compute_main(in: ComputeInput){
 
     let vec4_pixel_color = vec4<f32>(pixel_color_1_channel);
 
-    textureStore(heightmap_texture, coordonnees, vec4_pixel_color)
+    textureStore(heightmap_texture, coordonnees, vec4_pixel_color);
 }