diff --git a/README.md b/README.md index a903608..2f3ba34 100644 --- a/README.md +++ b/README.md @@ -3,26 +3,34 @@ WebGL Clustered Deferred and Forward+ Shading **University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 5** -* (TODO) YOUR NAME HERE -* Tested on: (TODO) **Google Chrome 222.2** on - Windows 22, i7-2222 @ 2.22GHz 22GB, GTX 222 222MB (Moore 2222 Lab) +* JuYang +* ### Tested on: Windows 7, i7-4710MQ @ 2.50GHz 8GB, GTX 870M 6870MB (Hasee Notebook K770E-i7) -### Live Online +Well after almost 2 weeks, I decided to give up on this project. -[![](img/thumb.png)](http://TODO.github.io/Project5B-WebGL-Deferred-Shading) +The only thing that has the right result is the forward+ glsl. Currently it can extract light clusters in a right way, and I added a "toon" shader which is not toon at all. -### Demo Video/GIF +![result](a.png) -[![](img/video.png)](TODO) +If you wanna see this feature, you can de-comment the "TEST GLSL" part in culster.js, line 193. -### (TODO: Your README) +Other from that, the cluster.js is where the problem is. -*DO NOT* leave the README to the last minute! It is a crucial part of the -project, and we will not be able to grade you without a good README. +What I think is to divide the space using angels instead of positions. -This assignment has a considerable amount of performance analysis compared -to implementation work. Complete the implementation early to leave time! +All positions are world based, and I can calculate which cluster the light is using angles*segments/(2*FOV); +![result](cluster.png) + +Well, in javascript, I don't have something that's as accurate as int, float or vec3, vec4. + +All I have is var or let, which is unstable and unperdictable. + +I have to open the web page and debug each line to see if there's some trouble, for example, passing data from light.position(Float32 Array) into a vec3 or vec4. + +Besides, in webgl, it is not real glsl, we don't have %, and not while (That's necessery for light looping, my way is to give a large int in for loop, and break when we met the condition). Even a basic goto would be better, I think. + +After this bad experience using javascript and webgl, I'm not suprised if people tell me that they don't like webgl, nor do I like it. ### Credits diff --git a/a.png b/a.png new file mode 100644 index 0000000..3982f30 Binary files /dev/null and b/a.png differ diff --git a/cluster.png b/cluster.png new file mode 100644 index 0000000..180f6db Binary files /dev/null and b/cluster.png differ diff --git a/src/renderers/clustered.js b/src/renderers/clustered.js index 9521fbd..2c43dd4 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