Skip to content

Commit 05b33ca

Browse files
author
Hannah Bollar
committed
fix - blocky rendering due to forward plus frag
1 parent 71960fe commit 05b33ca

File tree

2 files changed

+19
-18
lines changed

2 files changed

+19
-18
lines changed

src/renderers/base.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ export default class BaseRenderer {
6666
let cluster_x_max = Math.floor((light_position[0] + light_radius + frustum_width_at_depth * 0.5) * stride_x);
6767

6868
// check if valid index locations for cluster structure dimensions - if not, then not visible so ignore
69-
/*if ( (cluster_x_min >= this._xSlices || cluster_x_max < 0)
69+
if ( (cluster_x_min >= this._xSlices || cluster_x_max < 0)
7070
|| (cluster_y_min >= this._ySlices || cluster_y_max < 0)
7171
|| (cluster_z_min >= this._zSlices || cluster_z_max < 0) ) {
7272
continue;
73-
}*/
73+
}
7474

7575
// cluster ranges can go outside bounds as long as overlapping with in-bounds locations
7676
// clamp cluster range to 0 -> slice bounds for each dimension
@@ -102,7 +102,7 @@ export default class BaseRenderer {
102102

103103
}//end: x iter
104104
}//end: y iter
105-
}//end: z iter*/
105+
}//end: z iter
106106

107107
}//end: for each light
108108

src/shaders/forwardPlus.frag.glsl.js

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -91,46 +91,47 @@ export default function(params) {
9191
// locate fragment's cluster
9292
vec3 loc = vec3(floor(gl_FragCoord.x * u_slice_dimensions.x / u_resolution.x),
9393
floor(gl_FragCoord.y * u_slice_dimensions.y / u_resolution.y),
94-
floor(-pos.z - u_nearclip) * u_slice_dimensions.z / (u_farclip - u_nearclip));
94+
floor((-pos.z - u_near_clip) * u_slice_dimensions.z / (u_far_clip - u_near_clip))
95+
);
9596
9697
// get rest of cluster information - left as floats for math ease
97-
float index_of_cluster =
98+
float index_of_cluster =
9899
loc.x + loc.y * u_slice_dimensions.x + loc.z * u_slice_dimensions.x * u_slice_dimensions.y;
99100
float num_clusters = u_slice_dimensions.x * u_slice_dimensions.y * u_slice_dimensions.z;
100101
101102
// offset by 1 for both bc indexing in [0, length - 1]
102-
float row = (index_of_cluster + 1) / (num_clusters + 1);
103+
float row = (index_of_cluster + 1.0) / (num_clusters + 1.0);
103104
104-
int light_count = floor(texture2D(u_clusterbuffer, vec2(row, 0))[0]);
105+
int light_count = int(texture2D(u_clusterbuffer, vec2(row, 0))[0]);
105106
106107
// begin color calculation based on cluster information
107108
vec3 fragColor = vec3(0.0);
108-
for (int i = 0; i < ${params.numLights}; ++i) {
109+
for (int i = 0; i < ${params.numLights_perCluster}; ++i) {
109110
// check
110111
if (i >= light_count) {
111112
break;
112113
}
113114
114115
float light_index = ExtractFloat( u_clusterbuffer,
115-
(int)num_clusters,
116-
${Math.floor((params.numLights_perCluster + 1) / 4)},
117-
(int)index_of_cluster,
118-
i + 1);
119-
Light light = UnpackLight((int)light_index);
116+
int(num_clusters),
117+
${Math.floor((params.numLights_perCluster + 1) / 4)},
118+
int(index_of_cluster),
119+
int(i + 1) );
120+
Light light = UnpackLight(int(light_index));
120121
float lightDistance = distance(light.position, v_position);
121122
vec3 L = (light.position - v_position) / lightDistance;
122123
123124
float lightIntensity = cubicGaussian(2.0 * lightDistance / light.radius);
124125
float lambertTerm = max(dot(L, normal), 0.0);
125126
126127
// regular shading
127-
fragColor += albedo * lambertTerm * light.color * vec3(lightIntensity);
128+
//fragColor += albedo * lambertTerm * light.color * vec3(lightIntensity);
128129
129130
// blinn-phong
130-
//vec3 view_dir = normalize(u_camera_position - v_position);
131-
//vec3 half_vec_for_calc = normalize(L + viewDir);
132-
//float specularTerm = pow(max(dot(normal, half_vec_for_calc), 0), 100);
133-
//fragColor += (albedo + vec3(specularTerm)) * lambertTerm * light.color lightIntensity;
131+
vec3 view_dir = normalize(u_camera_position - v_position);
132+
vec3 half_vec_for_calc = normalize(L + view_dir);
133+
float specularTerm = pow(max(dot(normal, half_vec_for_calc), 0.0), 50.0);
134+
fragColor += (albedo + vec3(specularTerm)) * lambertTerm * light.color * lightIntensity;
134135
}
135136
136137
const vec3 ambientLight = vec3(0.025);

0 commit comments

Comments
 (0)