Skip to content

Commit ac8ae14

Browse files
committed
thing added
1 parent accaf8a commit ac8ae14

File tree

11 files changed

+55
-34
lines changed

11 files changed

+55
-34
lines changed

README.md

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,7 @@ WebGL Forward+ and Clustered Deferred Shading
1717

1818
### (TODO: Your README)
1919

20-
*DO NOT* leave the README to the last minute! It is a crucial part of the
21-
project, and we will not be able to grade you without a good README.
22-
23-
This assignment has a considerable amount of performance analysis compared
24-
to implementation work. Complete the implementation early to leave time!
20+
hi gamers
2521

2622
### Credits
2723

src/main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ function setRenderer(mode: string) {
5050
}
5151

5252
const renderModes = { naive: 'naive', forwardPlus: 'forward+', clusteredDeferred: 'clustered deferred' };
53-
let renderModeController = gui.add({ mode: renderModes.clusteredDeferred }, 'mode', renderModes);
53+
let renderModeController = gui.add({ mode: renderModes.forwardPlus }, 'mode', renderModes);
5454
renderModeController.onChange(setRenderer);
5555

5656
setRenderer(renderModeController.getValue());

src/renderer.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ export abstract class Renderer {
127127
protected abstract draw(): void;
128128

129129
// CHECKITOUT: this is the main rendering loop
130-
private onFrame(time: number) {
130+
private async onFrame(time: number) {
131131
if (this.prevTime == 0) {
132132
this.prevTime = time;
133133
}
@@ -139,6 +139,11 @@ export abstract class Renderer {
139139
this.stats.begin();
140140

141141
this.draw();
142+
143+
if (true)
144+
{
145+
await device.queue.onSubmittedWorkDone();
146+
}
142147

143148
this.stats.end();
144149

src/renderers/clustered_deferred.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import * as renderer from '../renderer';
22
import * as shaders from '../shaders/shaders';
3-
import * as lights from '../stage/lights';
43

54
import { Stage } from '../stage/stage';
65

src/shaders/clustered_deferred.fs.wgsl

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,15 @@ fn main(in: FragmentInput) -> FragmentOutput
2626
{
2727
var output: FragmentOutput;
2828

29-
output.normal = vec4f(in.nor, 1f);
30-
output.albedo = textureSample(diffuseTex, diffuseTexSampler, in.uv);
29+
let sampledAlbedo = textureSample(diffuseTex, diffuseTexSampler, in.uv);
3130

31+
if (sampledAlbedo.a < 0.5f)
32+
{
33+
discard;
34+
}
35+
36+
output.normal = vec4f(in.nor, 1f);
37+
output.albedo= sampledAlbedo;
38+
3239
return output;
3340
}

src/shaders/clustered_deferred_fullscreen.fs.wgsl

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,9 @@ fn main(@builtin(position) fragPos : vec4f) -> @location(0) vec4f {
3434

3535
let clusterID = clusterX + (clusterY * clusterSet.numClustersX) + (clusterZ * (clusterSet.numClustersX * clusterSet.numClustersY));
3636

37-
let cluster: Cluster = clusterSet.clusters[clusterID];
38-
let numLights: u32 = cluster.numLights;
39-
4037
var totalLightContrib = vec3f(0, 0, 0);
41-
for (var clusterLightIdx = 0u; clusterLightIdx < numLights; clusterLightIdx++) {
42-
let lightIdx = cluster.lightIndices[clusterLightIdx];
38+
for (var clusterLightIdx = 0u; clusterLightIdx < clusterSet.clusters[clusterID].numLights; clusterLightIdx++) {
39+
let lightIdx = clusterSet.clusters[clusterID].lightIndices[clusterLightIdx];
4340
let light = lightSet.lights[lightIdx];
4441
totalLightContrib += calculateLightContrib(light, position, normalize(normal));
4542
}

src/shaders/clustered_deferred_fullscreen.vs.wgsl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
@vertex
66
fn main( @builtin(vertex_index) VertexIndex : u32 ) -> @builtin(position) vec4f {
7+
// https://webgpu.github.io/webgpu-samples/?sample=deferredRendering#fragmentDeferredRendering.wgsl
78
const pos = array(
89
vec2(-1.0, -1.0), vec2(1.0, -1.0), vec2(-1.0, 1.0),
910
vec2(-1.0, 1.0), vec2(1.0, -1.0), vec2(1.0, 1.0),

src/shaders/clustering.cs.wgsl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,20 +49,25 @@ fn lineIntersectionToZPlane(a: vec3f, b: vec3f, distance: f32) -> vec3f {
4949

5050

5151
@compute
52-
@workgroup_size(1, 1, 1)
53-
fn getClusterBounds(@builtin(global_invocation_id) globalIdx: vec3u) {
52+
@workgroup_size(${clusterLightsWorkgroupX}, ${clusterLightsWorkgroupY}, ${clusterLightsWorkgroupZ})
53+
fn getClusterBounds(@builtin(global_invocation_id) globalIdx: vec3u){
5454
let numClustersX = clusterSet.numClustersX;
5555
let numClustersY = clusterSet.numClustersY;
5656
let numClustersZ = clusterSet.numClustersZ;
5757
let numClusters = numClustersX * numClustersY * numClustersZ;
5858

59-
let clusterID = globalIdx.x + (globalIdx.y * numClustersX) + (globalIdx.z * (numClustersX * numClustersY));
59+
let clusterX = globalIdx.x;
60+
let clusterY = globalIdx.y;
61+
let clusterZ = globalIdx.z;
6062

61-
if (clusterID >= numClusters)
63+
if ( (clusterX >= numClustersX) || (clusterY >= numClustersY) || (clusterZ >= numClustersZ) )
6264
{
6365
return;
6466
}
6567

68+
let clusterID = (clusterX) + (clusterY * numClustersX) + (clusterZ * (numClustersX * numClustersY));
69+
70+
6671
let uniformSliceLength: f32 = ${sliceLength};
6772
var minZ: f32 = -uniformSliceLength * f32(globalIdx.z);
6873
var maxZ: f32 = -uniformSliceLength * f32(globalIdx.z + 1);
@@ -87,14 +92,14 @@ fn getClusterBounds(@builtin(global_invocation_id) globalIdx: vec3u) {
8792
var clusterLightArrayIdx: u32 = 0;
8893
let maxLightsPerCluster: u32 = ${maxLightsPerCluster};
8994

90-
for (var lightIdx = 0u; lightIdx < lightSet.numLights; lightIdx++) {
95+
for (var lightIdx = 0u; lightIdx < lightSet.numLights && clusterLightArrayIdx < maxLightsPerCluster; lightIdx++) {
9196
let light = lightSet.lights[lightIdx];
9297

9398
// Need to transform lightZ to the view Z to match the cluster's Z sapce
9499
var viewLightPos: vec4f = cameraUniforms.viewMat * vec4f(light.pos, 1f);
95100

96101
var isIntersected: bool = testAABBSphereIntersection(minPointAABB, maxPointAABB, viewLightPos.xyz, ${lightRadius});
97-
if (isIntersected && clusterLightArrayIdx < maxLightsPerCluster)
102+
if (isIntersected)
98103
{
99104
// Is there a way to use references for this assignment?
100105
clusterSet.clusters[clusterID].lightIndices[clusterLightArrayIdx] = lightIdx;

src/shaders/forward_plus.fs.wgsl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ struct FragmentInput
1717
fn main(in: FragmentInput) -> @location(0) vec4f
1818
{
1919
let diffuseColor = textureSample(diffuseTex, diffuseTexSampler, in.uv);
20+
if (diffuseColor.a < 0.5f) {
21+
discard;
22+
}
2023

2124
// Copy the light logic from naive, but just use the light indices from the accessed cluster for that
2225
let fragPos: vec4f = in.fragPos;
@@ -31,12 +34,9 @@ fn main(in: FragmentInput) -> @location(0) vec4f
3134

3235
let clusterID = clusterX + (clusterY * clusterSet.numClustersX) + (clusterZ * (clusterSet.numClustersX * clusterSet.numClustersY));
3336

34-
let cluster: Cluster = clusterSet.clusters[clusterID];
35-
let numLights: u32 = cluster.numLights;
36-
3737
var totalLightContrib = vec3f(0, 0, 0);
38-
for (var clusterLightIdx = 0u; clusterLightIdx < numLights; clusterLightIdx++) {
39-
let lightIdx = cluster.lightIndices[clusterLightIdx];
38+
for (var clusterLightIdx = 0u; clusterLightIdx < clusterSet.clusters[clusterID].numLights; clusterLightIdx++) {
39+
let lightIdx = clusterSet.clusters[clusterID].lightIndices[clusterLightIdx];
4040
let light = lightSet.lights[lightIdx];
4141
totalLightContrib += calculateLightContrib(light, in.pos, normalize(in.nor));
4242
}

src/shaders/shaders.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,14 @@ export const constants = {
2929
bindGroup_material: 2,
3030
moveLightsWorkgroupSize: 128,
3131

32+
clusterLightsWorkgroupX: 16,
33+
clusterLightsWorkgroupY: 16,
34+
clusterLightsWorkgroupZ: 1,
35+
3236
numSlices: 32,
3337
sliceLength: 1,
34-
tileSize: 128,
35-
maxLightsPerCluster: 128,
38+
tileSize: 64,
39+
maxLightsPerCluster: 256,
3640

3741
near: 0.1,
3842
far: 5000,

0 commit comments

Comments
 (0)