@@ -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