diff --git a/README.md b/README.md index ab5c236..2df897d 100644 --- a/README.md +++ b/README.md @@ -3,424 +3,70 @@ WebGL Deferred Shading **University of Pennsylvania, CIS 565: GPU Programming and Architecture, Project 6** -* (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) +* Ziye +* Tested on: Google Chrome 41.0.2272.89 m on Windows 10, i7-4710MQ @ 2.50GHz 32GB, AMD HD8970M (Personal Laptop) -### Live Online - -[![](img/thumb.png)](http://TODO.github.io/Project6-WebGL-Deferred-Shading) ### Demo Video -[![](img/video.png)](TODO) - -### (TODO: Your README) - -*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. - -This assignment has a considerable amount of performance analysis compared -to implementation work. Complete the implementation early to leave time! - - -Instructions (delete me) -======================== - -This is due at midnight on the evening of Sunday, October 25. - -**Summary:** In this project, you'll be introduced to the basics of deferred -shading and WebGL. You'll use GLSL and WebGL to implement a deferred shading -pipeline and various lighting and visual effects. - -**Recommendations:** -Take screenshots as you go. Use them to document your progress in your README! - -Read (or at least skim) the full README before you begin, so that you know what -to expect and what to prepare for. - -### Running the code - -If you have Python, you should be able to run `server.py` to start a server. -Then, open [`http://localhost:10565/`](http://localhost:10565/) in your browser. - -This project requires a WebGL-capable web browser with support for -`WEBGL_draw_buffers`. You can check for support on -[WebGL Report](http://webglreport.com/). - -Google Chrome seems to work best on all platforms. If you have problems running -the starter code, use Chrome or Chromium, and make sure you have updated your -browser and video drivers. - -In Moore 100C, both Chrome and Firefox work. -See below for notes on profiling/debugging tools. - -Use the screenshot button to save a screenshot. - -## Requirements - -**Ask on the mailing list for any clarifications.** - -In this project, you are given code for: - -* Loading OBJ files and color/normal map textures -* Camera control -* Partial implementation of deferred shading including many helper functions - -### Required Tasks - -**Before doing performance analysis,** you must disable debug mode by changing -`debugMode` to `false` in `framework.js`. Keep it enabled when developing - it -helps find WebGL errors *much* more easily. - -You will need to perform the following tasks: - -* Complete the deferred shading pipeline so that the Blinn-Phong and Post1 - shaders recieve the correct input. Go through the Starter Code Tour **before - continuing!** - -**Effects:** - -* Implement deferred Blinn-Phong shading (diffuse + specular) - * With normal mapping (code provided) - -* Implement one of the following effects: - * Bloom using post-process blur (box or Gaussian) [1] - * Toon shading (with ramp shading + simple depth-edge detection for outlines) - -**Optimizations:** - -* Scissor test optimization: when accumulating shading from each point - light source, only render in a rectangle around the light. - * Show a debug view for this (showing scissor masks clearly), e.g. by - modifying and using `red.frag.glsl` with additive blending and alpha = 0.1. - * Code is provided to compute this rectangle for you, and there are - comments at the relevant place in `deferredRender.js` with more guidance. - -* Optimized g-buffer format - reduce the number and size of g-buffers: - * Ideas: - * Pack values together into vec4s - * Use 2-component normals - * Quantize values by using smaller texture types instead of gl.FLOAT - * Reduce number of properties passed via g-buffer, e.g. by: - * Applying the normal map in the `copy` shader pass instead of - copying both geometry normals and normal maps - * Reconstructing world space position using camera matrices and X/Y/depth - * For credit, you must show a good optimization effort and record the - performance of each version you test, in a simple table. - * It is expected that you won't need all 4 provided g-buffers for a basic - pipeline - make sure you disable the unused ones. - * See mainly: `copy.frag.glsl`, `deferred/*.glsl`, `deferredSetup.js` - -### Extra Tasks - -You must do at least **10 points** worth of extra features (effects or -optimizations/analysis). - -**Effects:** - -* (3pts) The effect you didn't choose above (bloom or toon shading) - -* (3pts) Screen-space motion blur (blur along velocity direction) [3] - -* (2pts) Allow variability in additional material properties - * Include other properties (e.g. specular coeff/exponent) in g-buffers - * Use this to render objects with different material properties - * These may be uniform across one model draw call, but you'll have to show - multiple models - -**Optimizations/Analysis:** - -* (2pts) Improved screen-space AABB for scissor test - (smaller/more accurate than provided - but beware of CPU/GPU tradeoffs) - -* (3pts) Two-pass **Gaussian** blur using separable convolution (using a second - postprocess render pass) to improve bloom or other 2D blur performance - -* (4-6pts) Light proxies - * (4pts) Instead of rendering a scissored full-screen quad for every light, - render some proxy geometry which covers the part of the screen affected by - the light (e.g. a sphere, for an attenuated point light). - * A model called `sphereModel` is provided which can be drawn in the same - way as the code in `drawScene`. (Must be drawn with a vertex shader which - scales it to the light radius and translates it to the light position.) - * (+2pts) To avoid lighting geometry far behind the light, render the proxy - geometry (e.g. sphere) using an inverted depth test - (`gl.depthFunc(gl.GREATER)`) with depth writing disabled (`gl.depthMask`). - This test will pass only for parts of the screen for which the backside of - the sphere appears behind parts of the scene. - * Note that the copy pass's depth buffer must be bound to the FBO during - this operation! - * Show a debug view for this (showing light proxies) - * Compare performance of this, naive, and scissoring. - -* (8pts) Tile-based deferred shading with detailed performance comparison - * On the CPU, check which lights overlap which tiles. Then, render each tile - just once for all lights (instead of once for each light), applying only - the overlapping lights. - * The method is described very well in - [Yuqin & Sijie's README](https://github.com/YuqinShao/Tile_Based_WebGL_DeferredShader/blob/master/README.md#algorithm-details). - * This feature requires allocating the global light list and tile light - index lists as shown at this link. These can be implemented as textures. - * Show a debug view for this (number of lights per tile) +[![](img/video.png)](https://youtu.be/maYqPVo_w_U) -* (6pts) Deferred shading without multiple render targets - (i.e. without WEBGL_draw_buffers). - * Render the scene once for each target g-buffer, each time into a different - framebuffer object. - * Include a detailed performance analysis, comparing with/without - WEBGL_draw_buffers (like in the - [Mozilla blog article](https://hacks.mozilla.org/2014/01/webgl-deferred-shading/)). - -* (2-6pts) Compare performance to equivalently-lit forward-rendering: - * (2pts) With no forward-rendering optimizations - * (+2pts) Coarse, per-object back-to-front sorting of geometry for early-z - * (Of course) must render many objects to test - * (+2pts) Z-prepass for early-z - -This extra feature list is not comprehensive. If you have a particular idea -that you would like to implement, please **contact us first** (preferably on -the mailing list). - -**Where possible, all features should be switchable using the GUI panel in -`ui.js`.** - -### Performance & Analysis - -**Before doing performance analysis,** you must disable debug mode by changing -`debugMode` to `false` in `framework.js`. Keep it enabled when developing - it -helps find WebGL errors *much* more easily. - -Optimize your JavaScript and/or GLSL code. Web Tracing Framework -and Chrome/Firefox's profiling tools (see Resources section) will -be useful for this. For each change -that improves performance, show the before and after render times. - -For each new *effect* feature (required or extra), please -provide the following analysis: - -* Concise overview write-up of the feature. -* Performance change due to adding the feature. - * If applicable, how do parameters (such as number of lights, etc.) - affect performance? Show data with simple graphs. -* If you did something to accelerate the feature, what did you do and why? -* How might this feature be optimized beyond your current implementation? - -For each *performance* feature (required or extra), please provide: - -* Concise overview write-up of the feature. -* Detailed performance improvement analysis of adding the feature - * What is the best case scenario for your performance improvement? What is - the worst? Explain briefly. - * Are there tradeoffs to this performance feature? Explain briefly. - * How do parameters (such as number of lights, tile size, etc.) affect - performance? Show data with graphs. - * Show debug views when possible. - * If the debug view correlates with performance, explain how. - -Note: Be aware that stats.js may give 0 millisecond frame timings in Chrome on -occasion - if this happens, you can use the FPS counter. - -### Starter Code Tour - -You'll be working mainly in `deferredRender.js` using raw WebGL. Three.js is -included in the project for various reasons. You won't use it for much, but its -matrix/vector types may come in handy. - -It's highly recommended that you use the browser debugger to inspect variables -to get familiar with the code. At any point, you can also -`console.log(some_var);` to show it in the console and inspect it. - -The setup in `deferredSetup` is already done for you, for many of the features. -If you want to add uniforms (textures or values), you'll change them here. -Therefore, it is recommended that you review the comments to understand the -process, BEFORE starting work in `deferredRender`. - -In `deferredRender`, start at the **START HERE!** comment. -Work through the appropriate `TODO`s as you go - most of them are very -small. Test incrementally (after implementing each part, instead of testing -all at once). -* (The first thing you should be doing is implementing the fullscreen quad!) - -Your first goal should be to get the debug views working. -Add code in `debug.frag.glsl` to examine your g-buffers before trying to -render them. (Set the debugView in the UI to show them.) - -For editing JavaScript, you can use a simple editor with syntax highlighting -such as Sublime, Vim, Emacs, etc., or the editor built into Chrome. - -* `js/`: JavaScript files for this project. - * `main.js`: Handles initialization of other parts of the program. - * `framework.js`: Loads the scene, camera, etc., and calls your setup/render - functions. Hopefully, you won't need to change anything here. - * `deferredSetup.js`: Deferred shading pipeline setup code. - * `createAndBind(Depth/Color)TargetTexture`: Creates empty textures for - binding to frame buffer objects as render targets. - * `deferredRender.js`: Your deferred shading pipeline execution code. - * `renderFullScreenQuad`: Renders a full-screen quad with the given shader - program. - * `ui.js`: Defines the UI using - [dat.GUI](https://workshop.chromeexperiments.com/examples/gui/). - * The global variable `cfg` can be accessed anywhere in the code to read - configuration values. - * `utils.js`: Utilities for JavaScript and WebGL. - * `abort`: Aborts the program and shows an error. - * `loadTexture`: Loads a texture from a URL into WebGL. - * `loadShaderProgram`: Loads shaders from URLs into a WebGL shader program. - * `loadModel`: Loads a model into WebGL buffers. - * `readyModelForDraw`: Configures the WebGL state to draw a model. - * `drawReadyModel`: Draws a model which has been readied. - * `getScissorForLight`: Computes an approximate scissor rectangle for a - light in world space. -* `glsl/`: GLSL code for each part of the pipeline: - * `clear.*.glsl`: Clears each of the `NUM_GBUFFERS` g-buffers. - * `copy.*.glsl`: Performs standard rendering without any fragment shading, - storing all of the resulting values into the `NUM_GBUFFERS` g-buffers. - * `quad.vert.glsl`: Minimal vertex shader for rendering a single quad. - * `deferred.frag.glsl`: Deferred shading pass (for lighting calculations). - Reads from each of the `NUM_GBUFFERS` g-buffers. - * `post1.frag.glsl`: First post-processing pass. -* `lib/`: JavaScript libraries. -* `models/`: OBJ models for testing. Sponza is the default. -* `index.html`: Main HTML page. -* `server.bat` (Windows) or `server.py` (OS X/Linux): - Runs a web server at `localhost:10565`. - -### The Deferred Shading Pipeline - -See the comments in `deferredSetup.js`/`deferredRender.js` for low-level guidance. - -In order to enable and disable effects using the GUI, upload a vec4 uniform -where each component is an enable/disable flag. In JavaScript, the state of the -UI is accessible anywhere as `cfg.enableEffect0`, etc. - -**Pass 1:** Renders the scene geometry and its properties to the g-buffers. -* `copy.vert.glsl`, `copy.frag.glsl` -* The framebuffer object `pass_copy.fbo` must be bound during this pass. -* Renders into `pass_copy.depthTex` and `pass_copy.gbufs[i]`, which need to be - attached to the framebuffer. - -**Pass 2:** Performs lighting and shading into the color buffer. -* `quad.vert.glsl`, `deferred/blinnphong-pointlight.frag.glsl` -* Takes the g-buffers `pass_copy.gbufs`/`depthTex` as texture inputs to the - fragment shader, on uniforms `u_gbufs` and `u_depth`. -* `pass_deferred.fbo` must be bound. -* Renders into `pass_deferred.colorTex`. - -**Pass 3:** Performs post-processing. -* `quad.vert.glsl`, `post/one.frag.glsl` -* Takes `pass_BlinnPhong_PointLight.colorTex` as a texture input `u_color`. -* Renders directly to the screen if there are no additional passes. - -More passes may be added for additional effects (e.g. combining bloom with -motion blur) or optimizations (e.g. two-pass Gaussian blur for bloom) - -#### Debugging - -If there is a WebGL error, it will be displayed on the developer console and -the renderer will be aborted. To find out where the error came from, look at -the backtrace of the error (you may need to click the triangle to expand the -message). The line right below `wrapper @ webgl-debug.js` will point to the -WebGL call that failed. - -#### Changing the number of g-buffers - -Note that the g-buffers are just `vec4`s - you can put any values you want into -them. However, if you want to change the total number of g-buffers (add more -for additional effects or remove some for performance), you will need to make -changes in a number of places: - -* `deferredSetup.js`/`deferredRender.js`: search for `NUM_GBUFFERS` -* `copy.frag.glsl` -* `deferred.frag.glsl` -* `clear.frag.glsl` - - -## Resources - -* [1] Bloom: - [GPU Gems, Ch. 21](http://http.developer.nvidia.com/GPUGems/gpugems_ch21.html) -* [2] Screen-Space Ambient Occlusion: - [Floored Article](http://floored.com/blog/2013/ssao-screen-space-ambient-occlusion.html) -* [3] Post-Process Motion Blur: - [GPU Gems 3, Ch. 27](http://http.developer.nvidia.com/GPUGems3/gpugems3_ch27.html) - -**Also see:** The articles linked in the course schedule. - -### Profiling and debugging tools - -Built into Firefox: -* Canvas inspector -* Shader Editor -* JavaScript debugger and profiler - -Built into Chrome: -* JavaScript debugger and profiler - -Plug-ins: -* (Chrome/Firefox) [Web Tracing Framework](http://google.github.io/tracing-framework/) -* (Chrome) [Shader Editor](https://chrome.google.com/webstore/detail/shader-editor/ggeaidddejpbakgafapihjbgdlbbbpob) +##Progress +====================== +###Debug View -Firefox can also be useful - it has a canvas inspector, WebGL profiling and a -shader editor built in. +Here I generate the simple debug view by visualize the data pass from the copy shader, which use different properties (depth, color, position, normal, etc.) as different texture to pass for later processing. +* Depth Map +![](img/debug_img/depth_1025.png) +* Color Map +![](img/debug_img/colormap_1025.png) +* Position Map +![](img/debug_img/position_1025.png) +* Normal Map +![](img/debug_img/normap_1025.png) +* Geometry Normal +![](img/debug_img/geonormal_1025.png) +* Surface Normal Map +![](img/debug_img/surfacenormal_1025.png) -## README +### Lightning +* Ambient Light -Replace the contents of this README.md in a clear manner with the following: +I am using the global light with distance attenuation to generate the ambient light effect. As can be seen from the image below, the farther the distance, the darker it is. -* A brief description of the project and the specific features you implemented. -* At least one screenshot of your project running. -* A 30+ second video of your project running showing all features. - [Open Broadcaster Software](http://obsproject.com) is recommended. - (Even though your demo can be seen online, using multiple render targets - means it won't run on many computers. A video will work everywhere.) -* A performance analysis (described below). +![](img/light/ambient_1025.png) +* Bling Phong + +For Bling Phong Lightning, I am using the standard method to compute the color on the surface. Also, in order to let each light influence a certain distance of area. I compare the distance from the surface to the position of the light, if it is beyond the influence region, I simply just ignore this light. Besides, I also introduce the attennuation of light according to the distance. -### Performance Analysis +![](img/light/blinnphong_1025.png) -See above. +### Special Effects +* Bloom -### GitHub Pages +For the Bloom Effect, I am using the Gaussian Blur to generate it. First I tried it with the standard 2D convolution, which is time comsuming and need to get more data. (O(m*n)) Then I tried the Two-pass Gaussian blur using separable convolution to improve the performance, this method has the complexity of O(m+n). If the m and n are very large, this improvement will be quite obvious. -Since this assignment is in WebGL, you can make your project easily viewable by -taking advantage of GitHub's project pages feature. +![](img/light/bloom.png) -Once you are done with the assignment, create a new branch: +* Toon -`git branch gh-pages` +For the Toon Effect, I am using the simple 2 Tone method, which just compare the color with some threshold to get the final result. -Push the branch to GitHub: +![](img/light/toon.png) -`git push origin gh-pages` +### Optimization +* Without G-Buffer Optimization (Rendering takes 22.3% valid time) +![](img/profile/wo_g_buffer_optimization.png) -Now, you can go to `.github.io/` to see your -renderer online from anywhere. Add this link to your README. +* With G-Buffer Optimization (Rendering takes 21.5% valid time) +![](img/profile/w_g_buffer_optimization.png) -## Submit +Previously, I am using all the g-buffer to generate the result. This require a lot of data passing and can impact the performance. So I tried to reduce number of properties passed via g-buffer. Basically, I just applying the normal map in the copy shader pass instead of copying both geometry normals and normal maps.This improvement is kind of small according to the compare above. -1. Open a GitHub pull request so that we can see that you have finished. - The title should be "Submission: YOUR NAME". - * **ADDITIONALLY:** - In the body of the pull request, include a link to your repository. -2. Send an email to the TA (gmail: kainino1+cis565@) with: - * **Subject**: in the form of `[CIS565] Project N: PENNKEY`. - * Direct link to your pull request on GitHub. - * Estimate the amount of time you spent on the project. - * If there were any outstanding problems, briefly explain. - * **List the extra features you did.** - * Feedback on the project itself, if any. +*Scissor test +![](img/debug_img/Sc_debug.png) -### Third-Party Code Policy +Using the getScissor code provided, I generate the debug view of Scissor test above. Although it is not very close bounded, we can already see that it reduce the amount of compute and render work by quite a lot. -* Use of any third-party code must be approved by asking on our mailing list. -* If it is approved, all students are welcome to use it. Generally, we approve - use of third-party code that is not a core part of the project. For example, - for the path tracer, we would approve using a third-party library for loading - models, but would not approve copying and pasting a CUDA function for doing - refraction. -* Third-party code **MUST** be credited in README.md. -* Using third-party code without its approval, including using another - student's code, is an academic integrity violation, and will, at minimum, - result in you receiving an F for the semester. diff --git a/bin_new/deferred_shader/deferred_shader.sln b/bin_new/deferred_shader/deferred_shader.sln new file mode 100644 index 0000000..62081f9 --- /dev/null +++ b/bin_new/deferred_shader/deferred_shader.sln @@ -0,0 +1,10 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio 2013 +VisualStudioVersion = 12.0.31101.0 +MinimumVisualStudioVersion = 10.0.40219.1 +Global + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection +EndGlobal diff --git a/glsl/copy.frag.glsl b/glsl/copy.frag.glsl index 0f5f8f7..8c58a36 100644 --- a/glsl/copy.frag.glsl +++ b/glsl/copy.frag.glsl @@ -10,6 +10,24 @@ varying vec3 v_position; varying vec3 v_normal; varying vec2 v_uv; +vec3 applyNormalMap(vec3 geomnor, vec3 normap) { + normap = normap * 2.0 - 1.0; + vec3 up = normalize(vec3(0.001, 1, 0.001)); + vec3 surftan = normalize(cross(geomnor, up)); + vec3 surfbinor = cross(geomnor, surftan); + return normap.y * surftan + normap.x * surfbinor + normap.z * geomnor; +} + + void main() { // TODO: copy values into gl_FragData[0], [1], etc. + gl_FragData[0] = vec4(v_position,1.0); //pos + gl_FragData[2] = texture2D(u_colmap, v_uv); // colormap + + + vec3 surface_nor = applyNormalMap(v_normal, vec3(texture2D(u_normap, v_uv))); + gl_FragData[1] = vec4(surface_nor,1.0); + + //gl_FragData[1] = vec4(v_normal,1.0); //geonormal + //gl_FragData[3] = texture2D(u_normap, v_uv); //normal map } diff --git a/glsl/deferred/ambient.frag.glsl b/glsl/deferred/ambient.frag.glsl index 1fd4647..2128796 100644 --- a/glsl/deferred/ambient.frag.glsl +++ b/glsl/deferred/ambient.frag.glsl @@ -11,17 +11,20 @@ uniform sampler2D u_depth; varying vec2 v_uv; void main() { - vec4 gb0 = texture2D(u_gbufs[0], v_uv); - vec4 gb1 = texture2D(u_gbufs[1], v_uv); - vec4 gb2 = texture2D(u_gbufs[2], v_uv); - vec4 gb3 = texture2D(u_gbufs[3], v_uv); - float depth = texture2D(u_depth, v_uv).x; + //vec4 gb0 = texture2D(u_gbufs[0], v_uv); //pos + //vec4 gb1 = texture2D(u_gbufs[1], v_uv); //geomnor + vec4 gb2 = texture2D(u_gbufs[2], v_uv); //colormap + //vec4 gb3 = texture2D(u_gbufs[3], v_uv); //normap + float depth = texture2D(u_depth, v_uv).x; //depth // TODO: Extract needed properties from the g-buffers into local variables + + + if (depth == 1.0) { - gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0 + gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0 used for post processing return; } - gl_FragColor = vec4(0.1, 0.1, 0.1, 1); // TODO: replace this + gl_FragColor = vec4(0.8*(1.0-depth)*vec3(gb2),1.0);//vec4(0.1, 0.1, 0.1, 1); // TODO: replace this } diff --git a/glsl/deferred/blinnphong-pointlight.frag.glsl b/glsl/deferred/blinnphong-pointlight.frag.glsl index b24a54a..1ad3c8a 100644 --- a/glsl/deferred/blinnphong-pointlight.frag.glsl +++ b/glsl/deferred/blinnphong-pointlight.frag.glsl @@ -12,6 +12,10 @@ uniform sampler2D u_depth; varying vec2 v_uv; +const float shininess = 20.0; +const vec3 specular_col = vec3 (1.0,1.0,1.0); + + vec3 applyNormalMap(vec3 geomnor, vec3 normap) { normap = normap * 2.0 - 1.0; vec3 up = normalize(vec3(0.001, 1, 0.001)); @@ -24,10 +28,20 @@ void main() { vec4 gb0 = texture2D(u_gbufs[0], v_uv); vec4 gb1 = texture2D(u_gbufs[1], v_uv); vec4 gb2 = texture2D(u_gbufs[2], v_uv); - vec4 gb3 = texture2D(u_gbufs[3], v_uv); + //vec4 gb3 = texture2D(u_gbufs[3], v_uv); float depth = texture2D(u_depth, v_uv).x; // TODO: Extract needed properties from the g-buffers into local variables + + vec3 pos = vec3(gb0); + + vec3 colmap = vec3(gb2); + + //vec3 geomnor = vec3(gb1); + //vec3 normap = vec3(gb3); + // vec3 nor = applyNormalMap(geomnor, normap); + vec3 nor = vec3(gb1); + // If nothing was rendered to this pixel, set alpha to 0 so that the // postprocessing step can render the sky color. if (depth == 1.0) { @@ -35,5 +49,50 @@ void main() { return; } - gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations + float attenuation = max(0.0, u_lightRad - distance(u_lightPos ,pos))/u_lightRad; + + if(attenuation == 0.0) + { + //gl_FragColor = vec4(0, 0, 0, 1); + return; + } + + + + + + vec3 lightDir = normalize(u_lightPos - pos); + + + + + vec3 diffuse_col = vec3( colmap[0] * u_lightCol[0],colmap[1] * u_lightCol[1],colmap[2] * u_lightCol[2]); + + //vec3 diffuse_col = vec3(colmap[0],0.0,0.0); + + + float lambertian = max(dot(lightDir,nor), 0.0); + float specular = 0.0; + + if(lambertian > 0.0) + { + + vec3 viewDir = normalize(-pos); + + // this is blinn phong + vec3 halfDir = normalize(lightDir + viewDir); + float specAngle = max(dot(halfDir, nor), 0.0); + specular = pow(specAngle, shininess); + + } + + + + + vec3 final_col = attenuation*lambertian*diffuse_col + attenuation*specular*specular_col ; // TODO: perform lighting calculations + + // vec3 final_col = lambertian*diffuse_col + specular*specular_col; + + // gl_FragColor = vec4(0.5,0.5,0.5,1.0); + gl_FragColor = vec4(final_col,1.0); } diff --git a/glsl/deferred/debug.frag.glsl b/glsl/deferred/debug.frag.glsl index d05638c..ff8ccee 100644 --- a/glsl/deferred/debug.frag.glsl +++ b/glsl/deferred/debug.frag.glsl @@ -27,11 +27,11 @@ void main() { vec4 gb3 = texture2D(u_gbufs[3], v_uv); float depth = texture2D(u_depth, v_uv).x; // TODO: Extract needed properties from the g-buffers into local variables - vec3 pos; - vec3 geomnor; - vec3 colmap; - vec3 normap; - vec3 nor; + vec3 pos = vec3(gb0); + vec3 geomnor = vec3(gb1); + vec3 colmap = vec3(gb2); + vec3 normap = vec3(gb3); + vec3 nor = applyNormalMap(geomnor, normap); if (u_debug == 0) { gl_FragColor = vec4(vec3(depth), 1.0); diff --git a/glsl/post/bloom.frag.glsl b/glsl/post/bloom.frag.glsl new file mode 100644 index 0000000..402f8d0 --- /dev/null +++ b/glsl/post/bloom.frag.glsl @@ -0,0 +1,35 @@ +#version 100 +precision highp float; +precision highp int; + +uniform sampler2D u_color; + +uniform float u_width; +uniform float u_height; + +varying vec2 v_uv; + + +void main() { + vec4 color = texture2D(u_color, v_uv); + + + + if(color.a > 1.0) + { + //blur along x + float dx = 1.0/u_width; + vec4 color_1 = texture2D(u_color, vec2(v_uv.x -dx,v_uv.y)); + vec4 color_2 = texture2D(u_color, vec2(v_uv.x +dx,v_uv.y)); + vec4 color_3 = texture2D(u_color, vec2(v_uv.x -dx-dx,v_uv.y)); + vec4 color_4 = texture2D(u_color, vec2(v_uv.x +dx+dx ,v_uv.y)); + + gl_FragColor = (color_3 + color_4 + color_1*3.0 + color_2*3.0 + color*7.0 )/15.0; + + + return; + } + + + gl_FragColor = color; +} diff --git a/glsl/post/bloom2.frag.glsl b/glsl/post/bloom2.frag.glsl new file mode 100644 index 0000000..5538505 --- /dev/null +++ b/glsl/post/bloom2.frag.glsl @@ -0,0 +1,35 @@ +#version 100 +precision highp float; +precision highp int; + +uniform sampler2D u_color; + +uniform float u_width; +uniform float u_height; + +varying vec2 v_uv; + + +void main() { + vec4 color = texture2D(u_color, v_uv); + + + + if(color.a > 1.0) + { + //blur along x + float dy = 1.0/u_height; + vec4 color_1 = texture2D(u_color, vec2(v_uv.x ,v_uv.y-dy)); + vec4 color_2 = texture2D(u_color, vec2(v_uv.x ,v_uv.y+dy)); + vec4 color_3 = texture2D(u_color, vec2(v_uv.x ,v_uv.y-dy-dy)); + vec4 color_4 = texture2D(u_color, vec2(v_uv.x ,v_uv.y+dy+dy)); + + gl_FragColor = (color_3 + color_4 + color_1*3.0 + color_2*3.0 + color*7.0 )/15.0; + + + return; + } + + + gl_FragColor = color; +} diff --git a/glsl/post/one.frag.glsl b/glsl/post/one.frag.glsl index 94191cd..50b3044 100644 --- a/glsl/post/one.frag.glsl +++ b/glsl/post/one.frag.glsl @@ -4,17 +4,27 @@ precision highp int; uniform sampler2D u_color; +uniform float u_width; +uniform float u_height; + varying vec2 v_uv; const vec4 SKY_COLOR = vec4(0.01, 0.14, 0.42, 1.0); + void main() { vec4 color = texture2D(u_color, v_uv); - - if (color.a == 0.0) { + + + + if (color.a == 0.0) { gl_FragColor = SKY_COLOR; return; } + + + + gl_FragColor = color; } diff --git a/glsl/post/scdebug.frag.glsl b/glsl/post/scdebug.frag.glsl new file mode 100644 index 0000000..818d914 --- /dev/null +++ b/glsl/post/scdebug.frag.glsl @@ -0,0 +1,19 @@ +#version 100 +precision highp float; +precision highp int; + +uniform float u_xmin; +uniform float u_xmax; +uniform float u_ymin; +uniform float u_ymax; + +varying vec2 v_uv; + +void main() { + + if(v_uv.x<=u_xmax && v_uv.x>=u_xmin && v_uv.y<=u_ymax && v_uv.y>=u_ymin) + { + gl_FragColor = vec4(1, 0, 0, 0.1); + } + +} diff --git a/glsl/post/toon.frag.glsl b/glsl/post/toon.frag.glsl new file mode 100644 index 0000000..185d072 --- /dev/null +++ b/glsl/post/toon.frag.glsl @@ -0,0 +1,47 @@ +#version 100 +precision highp float; +precision highp int; + +uniform sampler2D u_color; + +uniform float u_width; +uniform float u_height; + +varying vec2 v_uv; + + +void main() { + vec4 color = texture2D(u_color, v_uv); + + + if(color.r > 0.5) + { + color.r = 0.75; + } + else + { + color.r = 0.25; + } + + if(color.g > 0.5) + { + color.g = 0.75; + } + else + { + color.g = 0.25; + } + + if(color.b > 0.5) + { + color.b = 0.75; + } + else + { + color.b = 0.25; + } + + + + gl_FragColor = color; +} diff --git a/img/debug_img/Sc_debug.png b/img/debug_img/Sc_debug.png new file mode 100644 index 0000000..2bc08d9 Binary files /dev/null and b/img/debug_img/Sc_debug.png differ diff --git a/img/debug_img/colormap_1025.png b/img/debug_img/colormap_1025.png new file mode 100644 index 0000000..e2a6317 Binary files /dev/null and b/img/debug_img/colormap_1025.png differ diff --git a/img/debug_img/depth_1025.png b/img/debug_img/depth_1025.png new file mode 100644 index 0000000..5860333 Binary files /dev/null and b/img/debug_img/depth_1025.png differ diff --git a/img/debug_img/geonormal_1025.png b/img/debug_img/geonormal_1025.png new file mode 100644 index 0000000..b814938 Binary files /dev/null and b/img/debug_img/geonormal_1025.png differ diff --git a/img/debug_img/normap_1025.png b/img/debug_img/normap_1025.png new file mode 100644 index 0000000..3eb6062 Binary files /dev/null and b/img/debug_img/normap_1025.png differ diff --git a/img/debug_img/position_1025.png b/img/debug_img/position_1025.png new file mode 100644 index 0000000..b7671f9 Binary files /dev/null and b/img/debug_img/position_1025.png differ diff --git a/img/debug_img/surfacenormal_1025.png b/img/debug_img/surfacenormal_1025.png new file mode 100644 index 0000000..8229e4a Binary files /dev/null and b/img/debug_img/surfacenormal_1025.png differ diff --git a/img/light/ambient_1025.png b/img/light/ambient_1025.png new file mode 100644 index 0000000..7890733 Binary files /dev/null and b/img/light/ambient_1025.png differ diff --git a/img/light/blinnphong_1025.png b/img/light/blinnphong_1025.png new file mode 100644 index 0000000..705fab9 Binary files /dev/null and b/img/light/blinnphong_1025.png differ diff --git a/img/light/bloom.png b/img/light/bloom.png new file mode 100644 index 0000000..a7dde4b Binary files /dev/null and b/img/light/bloom.png differ diff --git a/img/light/toon.png b/img/light/toon.png new file mode 100644 index 0000000..bd13e3a Binary files /dev/null and b/img/light/toon.png differ diff --git a/img/light/wo_bloom.png b/img/light/wo_bloom.png new file mode 100644 index 0000000..10472fe Binary files /dev/null and b/img/light/wo_bloom.png differ diff --git a/img/profile/w_g_buffer_optimization.png b/img/profile/w_g_buffer_optimization.png new file mode 100644 index 0000000..efc7874 Binary files /dev/null and b/img/profile/w_g_buffer_optimization.png differ diff --git a/img/profile/wo_g_buffer_optimization.png b/img/profile/wo_g_buffer_optimization.png new file mode 100644 index 0000000..495c600 Binary files /dev/null and b/img/profile/wo_g_buffer_optimization.png differ diff --git a/img/video.png b/img/video.png index 9ec8ed0..10472fe 100644 Binary files a/img/video.png and b/img/video.png differ diff --git a/js/deferredRender.js b/js/deferredRender.js index b1f238b..ccbd6ea 100644 --- a/js/deferredRender.js +++ b/js/deferredRender.js @@ -10,7 +10,7 @@ !R.prog_Ambient || !R.prog_BlinnPhong_PointLight || !R.prog_Debug || - !R.progPost1)) { + !R.progPost1 || !R.progPost_bloom || !R.progPost_bloom2 || !R.progToon)) { console.log('waiting for programs to load...'); return; } @@ -28,12 +28,12 @@ // CHECKITOUT: START HERE! You can even uncomment this: //debugger; - { // TODO: this block should be removed after testing renderFullScreenQuad - gl.bindFramebuffer(gl.FRAMEBUFFER, null); - // TODO: Implement/test renderFullScreenQuad first - renderFullScreenQuad(R.progRed); - return; - } + //{ // TODO: this block should be removed after testing renderFullScreenQuad + // gl.bindFramebuffer(gl.FRAMEBUFFER, null); + // // TODO: Implement/test renderFullScreenQuad first + // renderFullScreenQuad(R.progRed); + // return; + //} R.pass_copy.render(state); @@ -44,34 +44,55 @@ } else { // * Deferred pass and postprocessing pass(es) // TODO: uncomment these - //R.pass_deferred.render(state); - //R.pass_post1.render(state); + R.pass_deferred.render(state); + R.pass_post1.render(state); + + if (cfg.Bloom) + { + R.pass_post2.render(state); //bloom 1 + R.pass_post3.render(state); //bloom 2 + } + else if (cfg.Toon) + { + R.pass_post4.render(state); //toon + } + + + // OPTIONAL TODO: call more postprocessing passes, if any } }; - + //===================================================== /** * 'copy' pass: Render into g-buffers */ R.pass_copy.render = function(state) { // * Bind the framebuffer R.pass_copy.fbo // TODO: ^ + gl.bindFramebuffer(gl.FRAMEBUFFER, R.pass_copy.fbo); // * Clear screen using R.progClear TODO: renderFullScreenQuad(R.progClear); // * Clear depth buffer to value 1.0 using gl.clearDepth and gl.clear // TODO: ^ // TODO: ^ + gl.clearDepth(1.0); + gl.clear(gl.DEPTH_BUFFER_BIT); + // * "Use" the program R.progCopy.prog // TODO: ^ + gl.useProgram(R.progCopy.prog); + // TODO: Write glsl/copy.frag.glsl + var m = state.cameraMat.elements; // * Upload the camera matrix m to the uniform R.progCopy.u_cameraMat // using gl.uniformMatrix4fv // TODO: ^ + gl.uniformMatrix4fv(R.progCopy.u_cameraMat,false,m); // * Draw the scene drawScene(state); @@ -108,6 +129,7 @@ R.pass_deferred.render = function(state) { // * Bind R.pass_deferred.fbo to write into for later postprocessing gl.bindFramebuffer(gl.FRAMEBUFFER, R.pass_deferred.fbo); + //gl.bindFramebuffer(gl.FRAMEBUFFER, null); //without postprocessing comment out if postprocessing // * Clear depth to 1.0 and color to black gl.clearColor(0.0, 0.0, 0.0, 0.0); @@ -119,6 +141,9 @@ // Enable blending and use gl.blendFunc to blend with: // color = 1 * src_color + 1 * dst_color // TODO: ^ + gl.enable(gl.BLEND); + //gl.blendEquation(gl.FUNC_ADD); + gl.blendFunc(gl.ONE, gl.ONE); // * Bind/setup the ambient pass, and render using fullscreen quad bindTexturesForLightPass(R.prog_Ambient); @@ -139,6 +164,50 @@ // // var sc = getScissorForLight(state.viewMat, state.projMat, light); + // Enables depth testing + gl.enable(gl.SCISSOR_TEST); + + for (var i = 0; i < R.lights.length; i++) + { + + var sc = getScissorForLight(state.viewMat, state.projMat, R.lights[i]); + gl.uniform3fv(R.prog_BlinnPhong_PointLight.u_lightPos, R.lights[i].pos); + gl.uniform3fv(R.prog_BlinnPhong_PointLight.u_lightCol, R.lights[i].col); + gl.uniform1f(R.prog_BlinnPhong_PointLight.u_lightRad, R.LIGHT_RADIUS); + + var xmin = 0; + var xmax = 0; + var ymin = 0; + var ymax = 0; + + + if (sc != null) + { + gl.scissor(sc[0], sc[1], sc[2], sc[3]); + xmin = sc[0]/width; + xmax = (sc[0] + sc[2])/width; + ymin = sc[1]/height; + ymax = (sc[1] + sc[3])/height; + } + else + { gl.scissor(0, 0, 0, 0); } + + if (!cfg.debugScissor) + renderFullScreenQuad(R.prog_BlinnPhong_PointLight); + else + { + gl.uniform1f(R.progScdebug.u_xmin, xmin); + gl.uniform1f(R.progScdebug.u_xmax, xmax); + gl.uniform1f(R.progScdebug.u_ymin, ymin); + gl.uniform1f(R.progScdebug.u_ymax, ymax); + + gl.blendFunc(gl.SRC_ALPHA, gl.ONE_MINUS_SRC_ALPHA); + + renderFullScreenQuad(R.progScdebug); + } + } + + gl.disable(gl.SCISSOR_TEST); // Disable blending so that it doesn't affect other code gl.disable(gl.BLEND); }; @@ -163,7 +232,14 @@ */ R.pass_post1.render = function(state) { // * Unbind any existing framebuffer (if there are no more passes) - gl.bindFramebuffer(gl.FRAMEBUFFER, null); + if (cfg.Bloom || cfg.Toon) + { + gl.bindFramebuffer(gl.FRAMEBUFFER, R.pass_post1.fbo); + } + else + { + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + } // * Clear the framebuffer depth to 1.0 gl.clearDepth(1.0); @@ -175,15 +251,113 @@ // * Bind the deferred pass's color output as a texture input // Set gl.TEXTURE0 as the gl.activeTexture unit // TODO: ^ + gl.activeTexture(gl.TEXTURE0); // Bind the TEXTURE_2D, R.pass_deferred.colorTex to the active texture unit // TODO: ^ + gl.bindTexture(gl.TEXTURE_2D, R.pass_deferred.colorTex); + // Configure the R.progPost1.u_color uniform to point at texture unit 0 gl.uniform1i(R.progPost1.u_color, 0); + gl.uniform1f(R.progPost1.u_width, width); + gl.uniform1f(R.progPost1.u_height, height); + // * Render a fullscreen quad to perform shading on renderFullScreenQuad(R.progPost1); }; + + R.pass_post2.render = function (state) { + // * Unbind any existing framebuffer (if there are no more passes) + gl.bindFramebuffer(gl.FRAMEBUFFER, R.pass_post2.fbo); + + // * Clear the framebuffer depth to 1.0 + gl.clearDepth(1.0); + gl.clear(gl.DEPTH_BUFFER_BIT); + + // * Bind the postprocessing shader program + gl.useProgram(R.progPost_bloom.prog); + + // * Bind the deferred pass's color output as a texture input + // Set gl.TEXTURE0 as the gl.activeTexture unit + // TODO: ^ + gl.activeTexture(gl.TEXTURE0); + // Bind the TEXTURE_2D, R.pass_deferred.colorTex to the active texture unit + // TODO: ^ + gl.bindTexture(gl.TEXTURE_2D, R.pass_post1.colorTex); + + // Configure the R.progPost_bloom.u_color uniform to point at texture unit 0 + gl.uniform1i(R.progPost_bloom.u_color, 0); + + gl.uniform1f(R.progPost_bloom.u_width, width); + gl.uniform1f(R.progPost_bloom.u_height, height); + + // * Render a fullscreen quad to perform shading on + renderFullScreenQuad(R.progPost_bloom); + }; + + R.pass_post3.render = function (state) { + // * Unbind any existing framebuffer (if there are no more passes) + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + // * Clear the framebuffer depth to 1.0 + gl.clearDepth(1.0); + gl.clear(gl.DEPTH_BUFFER_BIT); + + // * Bind the postprocessing shader program + gl.useProgram(R.progPost_bloom2.prog); + + // * Bind the deferred pass's color output as a texture input + // Set gl.TEXTURE0 as the gl.activeTexture unit + // TODO: ^ + gl.activeTexture(gl.TEXTURE0); + // Bind the TEXTURE_2D, R.pass_deferred.colorTex to the active texture unit + // TODO: ^ + gl.bindTexture(gl.TEXTURE_2D, R.pass_post2.colorTex); + + // Configure the R.progPost_bloom.u_color uniform to point at texture unit 0 + gl.uniform1i(R.progPost_bloom2.u_color, 0); + + gl.uniform1f(R.progPost_bloom2.u_width, width); + gl.uniform1f(R.progPost_bloom2.u_height, height); + + // * Render a fullscreen quad to perform shading on + renderFullScreenQuad(R.progPost_bloom2); + }; + + + + R.pass_post4.render = function (state) { + // * Unbind any existing framebuffer (if there are no more passes) + gl.bindFramebuffer(gl.FRAMEBUFFER, null); + + // * Clear the framebuffer depth to 1.0 + gl.clearDepth(1.0); + gl.clear(gl.DEPTH_BUFFER_BIT); + + // * Bind the postprocessing shader program + gl.useProgram(R.progToon.prog); + + // * Bind the deferred pass's color output as a texture input + // Set gl.TEXTURE0 as the gl.activeTexture unit + // TODO: ^ + gl.activeTexture(gl.TEXTURE0); + // Bind the TEXTURE_2D, R.pass_deferred.colorTex to the active texture unit + // TODO: ^ + gl.bindTexture(gl.TEXTURE_2D, R.pass_post1.colorTex); + + // Configure the R.progPost_bloom.u_color uniform to point at texture unit 0 + gl.uniform1i(R.progToon.u_color, 0); + + + + // * Render a fullscreen quad to perform shading on + renderFullScreenQuad(R.progToon); + }; + + + + var renderFullScreenQuad = (function() { // The variables in this function are private to the implementation of // renderFullScreenQuad. They work like static local variables in C++. @@ -194,9 +368,11 @@ // triangles which cover the screen over x = -1..1 and y = -1..1. // This array is set up to use gl.drawArrays with gl.TRIANGLE_STRIP. var positions = new Float32Array([ - -1.0, -1.0, 0.0, + -1.0, -1.0, 0.0, 1.0, -1.0, 0.0, - -1.0, 1.0, 0.0, + -1.0, 1.0, 0.0, + -1.0, 1.0, 0.0, + 1.0, -1.0, 0.0, 1.0, 1.0, 0.0 ]); @@ -205,12 +381,16 @@ var init = function() { // Create a new buffer with gl.createBuffer, and save it as vbo. // TODO: ^ - // Bind the VBO as the gl.ARRAY_BUFFER // TODO: ^ // Upload the positions array to the currently-bound array buffer // using gl.bufferData in static draw mode. // TODO: ^ + + vbo = gl.createBuffer(); + gl.bindBuffer(gl.ARRAY_BUFFER, vbo); + gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW); + }; return function(prog) { @@ -224,15 +404,20 @@ // Bind the VBO as the gl.ARRAY_BUFFER // TODO: ^ + gl.bindBuffer(gl.ARRAY_BUFFER, vbo); // Enable the bound buffer as the vertex attrib array for // prog.a_position, using gl.enableVertexAttribArray // TODO: ^ + gl.enableVertexAttribArray(prog.a_position); + // Use gl.vertexAttribPointer to tell WebGL the type/layout for // prog.a_position's access pattern. // TODO: ^ + gl.vertexAttribPointer(prog.a_position, 3, gl.FLOAT, false, 0, 0); // Use gl.drawArrays (or gl.drawElements) to draw your quad. // TODO: ^ + gl.drawArrays(gl.TRIANGLES, 0, 6); // Unbind the array buffer. gl.bindBuffer(gl.ARRAY_BUFFER, null); diff --git a/js/deferredSetup.js b/js/deferredSetup.js index ca6baec..9a29ca8 100644 --- a/js/deferredSetup.js +++ b/js/deferredSetup.js @@ -6,6 +6,9 @@ R.pass_debug = {}; R.pass_deferred = {}; R.pass_post1 = {}; + R.pass_post2 = {}; // bloom1 + R.pass_post3 = {}; //bloom2 + R.pass_post4 = {}; // toon R.lights = []; R.NUM_GBUFFERS = 4; @@ -18,6 +21,8 @@ loadAllShaderPrograms(); R.pass_copy.setup(); R.pass_deferred.setup(); + R.pass_post1.setup(); + R.pass_post2.setup(); }; // TODO: Edit if you want to change the light initial positions @@ -94,6 +99,38 @@ gl_draw_buffers.drawBuffersWEBGL([gl_draw_buffers.COLOR_ATTACHMENT0_WEBGL]); }; + R.pass_post1.setup = function () { + // * Create the FBO + R.pass_post1.fbo = gl.createFramebuffer(); + // * Create, bind, and store a single color target texture for the FBO + R.pass_post1.colorTex = createAndBindColorTargetTexture( + R.pass_post1.fbo, gl_draw_buffers.COLOR_ATTACHMENT0_WEBGL); + + // * Check for framebuffer errors + abortIfFramebufferIncomplete(R.pass_post1.fbo); + // * Tell the WEBGL_draw_buffers extension which FBO attachments are + // being used. (This extension allows for multiple render targets.) + gl_draw_buffers.drawBuffersWEBGL([gl_draw_buffers.COLOR_ATTACHMENT0_WEBGL]); + }; + + + R.pass_post2.setup = function () { + // * Create the FBO + R.pass_post2.fbo = gl.createFramebuffer(); + // * Create, bind, and store a single color target texture for the FBO + R.pass_post2.colorTex = createAndBindColorTargetTexture( + R.pass_post2.fbo, gl_draw_buffers.COLOR_ATTACHMENT0_WEBGL); + + // * Check for framebuffer errors + abortIfFramebufferIncomplete(R.pass_post2.fbo); + // * Tell the WEBGL_draw_buffers extension which FBO attachments are + // being used. (This extension allows for multiple render targets.) + gl_draw_buffers.drawBuffersWEBGL([gl_draw_buffers.COLOR_ATTACHMENT0_WEBGL]); + }; + + + + /** * Loads all of the shader programs used in the pipeline. */ @@ -147,12 +184,45 @@ }); loadPostProgram('one', function(p) { - p.u_color = gl.getUniformLocation(p.prog, 'u_color'); + p.u_color = gl.getUniformLocation(p.prog, 'u_color'); + p.u_width = gl.getUniformLocation(p.prog, 'u_width'); + p.u_height = gl.getUniformLocation(p.prog, 'u_height'); // Save the object into this variable for access later R.progPost1 = p; }); - // TODO: If you add more passes, load and set up their shader programs. + loadPostProgram('bloom', function (p) { + p.u_color = gl.getUniformLocation(p.prog, 'u_color'); + p.u_width = gl.getUniformLocation(p.prog, 'u_width'); + p.u_height = gl.getUniformLocation(p.prog, 'u_height'); + // Save the object into this variable for access later + R.progPost_bloom = p; + }); + + loadPostProgram('bloom2', function (p) { + p.u_color = gl.getUniformLocation(p.prog, 'u_color'); + p.u_width = gl.getUniformLocation(p.prog, 'u_width'); + p.u_height = gl.getUniformLocation(p.prog, 'u_height'); + // Save the object into this variable for access later + R.progPost_bloom2 = p; + }); + + + loadPostProgram('scdebug', function (p) { + p.u_xmin = gl.getUniformLocation(p.prog, 'u_xmin'); + p.u_xmax = gl.getUniformLocation(p.prog, 'u_xmax'); + p.u_ymin = gl.getUniformLocation(p.prog, 'u_ymin'); + p.u_ymax = gl.getUniformLocation(p.prog, 'u_ymax'); + // Save the object into this variable for access later + R.progScdebug = p; + }); + + loadPostProgram('toon', function (p) { + p.u_color = gl.getUniformLocation(p.prog, 'u_color'); + // Save the object into this variable for access later + R.progToon = p; + }); + }; var loadDeferredProgram = function(name, callback) { diff --git a/js/ui.js b/js/ui.js index 05c1852..93ea1b6 100644 --- a/js/ui.js +++ b/js/ui.js @@ -7,7 +7,8 @@ var cfg; // TODO: Define config fields and defaults here this.debugView = -1; this.debugScissor = false; - this.enableEffect0 = false; + this.Bloom = false; + this.Toon = false; }; var init = function() { @@ -27,7 +28,8 @@ var cfg; gui.add(cfg, 'debugScissor'); var eff0 = gui.addFolder('EFFECT NAME HERE'); - eff0.add(cfg, 'enableEffect0'); + eff0.add(cfg, 'Bloom'); + eff0.add(cfg, 'Toon'); // TODO: add more effects toggles and parameters here };