Skip to content

Commit 71960fe

Browse files
author
Hannah Bollar
committed
fixed - wasnt working because didnt include vec4 mat4 header
1 parent 86e788b commit 71960fe

File tree

1 file changed

+16
-14
lines changed

1 file changed

+16
-14
lines changed

src/renderers/base.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import { mat4, vec4, vec3 } from 'gl-matrix';
12
import { NUM_LIGHTS } from '../scene';
3+
import { LIGHT_RADIUS } from '../scene';
24
import TextureBuffer from './textureBuffer';
35

46
export const MAX_LIGHTS_PER_CLUSTER = 100;
@@ -34,8 +36,9 @@ export default class BaseRenderer {
3436
let frustum_width = Math.abs(camera.aspect * frustum_height);
3537
// total depth and z stride are unaffected by depth of light
3638
let frustum_total_depth = camera.far - camera.near;
37-
let stride_step_z = frustum_total_depth / this._zSlices;
39+
let stride_z = this._zSlices / frustum_total_depth;
3840

41+
let light_position = vec4.create();
3942
// Loop through lights counting number of lights at each buffer index
4043
// and placing light in appropr loc in buffer for calcs
4144
for (let on_light = 0; on_light < NUM_LIGHTS; ++on_light) {
@@ -51,8 +54,8 @@ export default class BaseRenderer {
5154
// frustum dimensions and values affected by light's depth
5255
let frustum_height_at_depth = frustum_height * light_position[2];
5356
let frustum_width_at_depth = frustum_width * light_position[2];
54-
let stride_step_y = frustum_height_at_depth / this._ySlices;
55-
let stride_step_x = frustum_width_at_depth / this._xSlices;
57+
let stride_y = this._ySlices / frustum_height_at_depth;
58+
let stride_x = this._xSlices / frustum_width_at_depth;
5659

5760
// check which cluster slices would actually be influenced by this light
5861
let cluster_z_min = Math.floor((light_position[2] - light_radius - camera.near) * stride_z);
@@ -72,12 +75,9 @@ export default class BaseRenderer {
7275
// cluster ranges can go outside bounds as long as overlapping with in-bounds locations
7376
// clamp cluster range to 0 -> slice bounds for each dimension
7477
// using sliceCount - 1, because indexing domain is [0, length - 1]
75-
cluster_x_min = Math.max(cluster_x_min, 0);
76-
cluster_x_max = Math.min(cluster_x_max, this._xSlices - 1);
77-
cluster_y_min = Math.max(cluster_y_min, 0);
78-
cluster_y_max = Math.min(cluster_y_max, this._ySlices - 1);
79-
cluster_z_min = Math.max(cluster_z_min, 0);
80-
cluster_z_max = Math.min(cluster_z_max, this._zSlices - 1);
78+
cluster_x_min = Math.max(cluster_x_min, 0); cluster_x_max = Math.min(cluster_x_max, this._xSlices - 1);
79+
cluster_y_min = Math.max(cluster_y_min, 0); cluster_y_max = Math.min(cluster_y_max, this._ySlices - 1);
80+
cluster_z_min = Math.max(cluster_z_min, 0); cluster_z_max = Math.min(cluster_z_max, this._zSlices - 1);
8181

8282
// fill in buffer locations where this light's influence should be included
8383
for (let z = cluster_z_min; z <= cluster_z_max; ++z) {
@@ -95,14 +95,16 @@ export default class BaseRenderer {
9595

9696
let row = Math.floor(num_lights_in_cluster * 0.25);
9797
let distance_to_pixel_baseline = num_lights_in_cluster - 4 * row;
98-
let index_to_fill = this._clusterTexture.bufferIndex(index_1D, row) + distance_pixel_baseline;
98+
let index_to_fill = this._clusterTexture.bufferIndex(index_1D, row) + distance_to_pixel_baseline;
9999
this._clusterTexture.buffer[index_to_fill] = on_light;
100100
this._clusterTexture.buffer[index_light_count] = num_lights_in_cluster;
101101
}
102-
}
103-
}
104-
}
105-
}
102+
103+
}//end: x iter
104+
}//end: y iter
105+
}//end: z iter*/
106+
107+
}//end: for each light
106108

107109
this._clusterTexture.update();
108110
}

0 commit comments

Comments
 (0)