diff --git a/src/scripts/light2/light.ts b/src/scripts/light2/light.ts index 2a3f8fc..28db990 100644 --- a/src/scripts/light2/light.ts +++ b/src/scripts/light2/light.ts @@ -26,13 +26,16 @@ export class LightPropagation2 extends GPUAbstractRunner { textureSrc: Texture bind_group_layout: GPUBindGroupLayout - bind_groupa: GPUBindGroup - bind_groupb: GPUBindGroup + bind_group_atob: GPUBindGroup + bind_group_btoa: GPUBindGroup + scene_bind_group_layout: GPUBindGroupLayout scene_bind_group: GPUBindGroup + pipeline_layout: GPUPipelineLayout compute_pipeline: GPUComputePipeline shader: GPUProgrammableStage + stagingBuffer: Buffer stagingData: Float32Array @@ -102,7 +105,7 @@ export class LightPropagation2 extends GPUAbstractRunner { }] }) - this.bind_groupa = GPU.device.createBindGroup({ + this.bind_group_atob = GPU.device.createBindGroup({ layout: this.bind_group_layout, entries: [{ binding: 0, @@ -116,7 +119,7 @@ export class LightPropagation2 extends GPUAbstractRunner { }] }) - this.bind_groupb = GPU.device.createBindGroup({ + this.bind_group_btoa = GPU.device.createBindGroup({ layout: this.bind_group_layout, entries: [{ binding: 0, @@ -168,16 +171,16 @@ export class LightPropagation2 extends GPUAbstractRunner { GPU.device.queue.writeBuffer(this.stagingBuffer.buffer, 0, this.stagingData) let encoder: GPUCommandEncoder = GPU.device.createCommandEncoder({}); - for(let i = 0; i < 60; i++) { + for(let i = 0; i < 80; i++) { let pass: GPUComputePassEncoder = encoder.beginComputePass(); - pass.setBindGroup(0, this.bind_groupa); + pass.setBindGroup(0, this.bind_group_atob); pass.setBindGroup(1, this.scene_bind_group); pass.setPipeline(this.compute_pipeline); pass.dispatchWorkgroups(this.width / 8, this.height / 8); pass.end(); pass = encoder.beginComputePass(); - pass.setBindGroup(0, this.bind_groupb); + pass.setBindGroup(0, this.bind_group_btoa); pass.setBindGroup(1, this.scene_bind_group); pass.setPipeline(this.compute_pipeline); pass.dispatchWorkgroups(this.width / 8, this.height / 8); diff --git a/src/scripts/light2/propagate.wgsl b/src/scripts/light2/propagate.wgsl index bd82009..3a633f9 100644 --- a/src/scripts/light2/propagate.wgsl +++ b/src/scripts/light2/propagate.wgsl @@ -62,6 +62,17 @@ fn retrieveConstants(pn: vec2i, F: ptr, E: ptr(1.5, 0.5)); // ~53.13°, projecting to the right side of our pixel + //const sa2: f32 = solid_angle(vec2f(0.5, 0.5), vec2(1.5, 0.5)); // ~18.43°, projecting to the top/bottom side of our pixel + //const dn1: vec2f = normalize(vec2f(2., 1.0)); // normal to the center of the top side of our pixel + + // TODO: the comments are wrong + const sa1= 0.6435011087932845; // ~53.13°, projecting to the right side of our pixel + const sa2= 0.4636476090008066; // ~18.43°, projecting to the top/bottom side of our pixel + const dn1 = vec2f(0.8944271909999159, 0.4472135954999579); // normal to the center of the top side of our pixel + const dn0 = vec2f(0.8944271909999159, -0.4472135954999579); // normal to the center of the bottom side of our pixel + fn lpv_kernel(p: vec2i, out: ptr) { let Em = textureLoad(scene, p, 0, 0).xyz; // emitted rgb light as circular harmonics let translucency = textureLoad(scene, p, 1, 0).w; @@ -75,11 +86,6 @@ fn lpv_kernel(p: vec2i, out: ptr) { let dn1: vec2f = normalize(vec2f(x - 0.5, 1.0)); // normal to the center of the top side of our pixel let dn0: vec2f = normalize(vec2f(x - 0.5, -1.0)); // normal to the center of the bottom side of our pixel */ - let sa1: f32 = solid_angle(vec2f(1.5, -0.5), vec2(1.5, 0.5)); // ~53.13°, projecting to the right side of our pixel - let sa2: f32 = solid_angle(vec2f(0.5, 0.5), vec2(1.5, 0.5)); // ~18.43°, projecting to the top/bottom side of our pixel - // note that sa2 = (90° - sa1) / 2 - let dn1: vec2f = normalize(vec2f(2., 1.0)); // normal to the center of the top side of our pixel - let dn0: vec2f = normalize(vec2f(2., -1.0)); // normal to the center of the bottom side of our pixel /* float sa1 = solid_angle(vec2(1.5, -0.5),vec2(1.5,0.5)); // ~53.13°, projecting to the right side of our pixel @@ -98,14 +104,12 @@ float sa1 = solid_angle(vec2(1.5, -0.5),vec2(1.5,0.5)); // ~53.13°, projecting propagate(dn1, sa2, F, E, out); propagate(dn0, sa2, F, E, out); - pn = p + vec2i(1, 0); retrieveConstants(pn, &F, &E); propagate(vec2f(-1., 0.), sa1, F, E, out); propagate(-dn0, sa2, F, E, out); propagate(-dn1, sa2, F, E, out); - pn = p + vec2i(0, -1); retrieveConstants(pn, &F, &E); propagate(vec2f(0., 1.), sa1, F, E, out); diff --git a/src/scripts/light2/scene/scene.ts b/src/scripts/light2/scene/scene.ts index 6a80223..ddecf04 100755 --- a/src/scripts/light2/scene/scene.ts +++ b/src/scripts/light2/scene/scene.ts @@ -43,7 +43,7 @@ export class LightScene { // 0: color emitter circular harmonics, z-component // 1: normal vector of the surface - this.emitter = GPU.CreateStorageTextureArray(this.width, this.height, 2, "rgba16float") + this.emitter = GPU.CreateStorageTextureArray(this.width, this.height, 2, "rgba8unorm") this.raytrace = new Raytrace("fbm.wgsl") try { diff --git a/src/scripts/light2/scene/scene.wgsl b/src/scripts/light2/scene/scene.wgsl index 0e33aeb..7a59d5f 100644 --- a/src/scripts/light2/scene/scene.wgsl +++ b/src/scripts/light2/scene/scene.wgsl @@ -21,7 +21,7 @@ fn sphere(p: vec2, r: f32) -> f32 { return length(p) - r; } -@group(0) @binding(0) var scene : texture_storage_2d_array; +@group(0) @binding(0) var scene : texture_storage_2d_array; @group(0) @binding(1) var staging: StagingBuffer; @group(0) @binding(2) var sdf : texture_2d;