From 7638e354b101c984a75851f38304e12e7997edfc Mon Sep 17 00:00:00 2001 From: 0v0v0 <0v0v0@users.noreply.github.com> Date: Fri, 27 Oct 2017 22:09:22 -0400 Subject: [PATCH 1/6] Add files via upload --- src/renderers/clustered.js | 217 +++++++++++++++++++++- src/renderers/clusteredForwardPlus.js | 14 +- src/scene.js | 2 +- src/shaders/clusteredForward.frag.glsl.js | 119 +++++++++++- 4 files changed, 331 insertions(+), 21 deletions(-) diff --git a/src/renderers/clustered.js b/src/renderers/clustered.js index 9521fbd..4779bb6 100644 --- a/src/renderers/clustered.js +++ b/src/renderers/clustered.js @@ -1,9 +1,13 @@ import { mat4, vec4, vec3 } from 'gl-matrix'; import { NUM_LIGHTS } from '../scene'; import TextureBuffer from './textureBuffer'; +import {camera} from "../init"; export const MAX_LIGHTS_PER_CLUSTER = 100; +const pos=vec3.create(); +const light_pos4=vec4.create(); + export default class ClusteredRenderer { constructor(xSlices, ySlices, zSlices) { // Create a texture to store cluster data. Each cluster stores the number of lights followed by the light indices @@ -17,16 +21,213 @@ export default class ClusteredRenderer { // TODO: Update the cluster texture with the count and indices of the lights in each cluster // This will take some time. The math is nontrivial... - for (let z = 0; z < this._zSlices; ++z) { - for (let y = 0; y < this._ySlices; ++y) { - for (let x = 0; x < this._xSlices; ++x) { - let i = x + y * this._xSlices + z * this._xSlices * this._ySlices; - // Reset the light count to 0 for every cluster - this._clusterTexture.buffer[this._clusterTexture.bufferIndex(i, 0)] = 0; - } + for (let z = 0; z < this._zSlices; ++z) { + for (let y = 0; y < this._ySlices; ++y) { + for (let x = 0; x < this._xSlices; ++x) { + let index = x + y * this._xSlices + z * this._xSlices * this._ySlices; + // Reset the light count to 0 for every cluster + this._clusterTexture.buffer[this._clusterTexture.bufferIndex(index, 0)] = 0;}}} + + // WHY LOOP CLUSTERS????? + + //Get camera angles in X,Y axis + let yFOV=camera.fov; + let xFOV=camera.aspect*yFOV; + //Get degrees for each segment + let ysegment=yFOV*2.0/this._ySlices; + let xsegment=xFOV*2.0/this._xSlices; + + let totallights=0; + let lightnumtotalinscene=scene.lights.length; + //Camera position + let cam_pos=camera.position; + //Get camera direction XY + /* + let cam_dir_x=vec3.create(); + let cam_q=vec4.create(); + cam_q[0]=camera.quaternion.w; + cam_q[1]=camera.quaternion.x; + cam_q[2]=0; + cam_q[3]=0; + vec3.transformQuat(cam_dir_x,vec3.fromValues(0,0,1),cam_q); + + let cam_dir_y=vec3.create(); + cam_q[0]=camera.quaternion.w; + cam_q[1]=0; + cam_q[2]=camera.quaternion.y; + cam_q[3]=0; + vec3.transformQuat(cam_dir_y,vec3.fromValues(0,0,1),cam_q); + */ + let cam_dir_x=vec3.fromValues(0,0,1); + //vec3.rotateY(cam_dir_x,cam_dir_x,vec3.create(),camera.rotation.y*180.0/Math.PI); + + let cam_dir_y=vec3.fromValues(0,0,1); + //vec3.rotateX(cam_dir_y,cam_dir_y,vec3.create(),camera.rotation.x*180.0/Math.PI); + + + + //Loop Lights + for(let L=0;L