diff --git a/Image/AllEffects.gif b/Image/AllEffects.gif
new file mode 100644
index 0000000..43622b3
Binary files /dev/null and b/Image/AllEffects.gif differ
diff --git a/Image/BlinnPhong.png b/Image/BlinnPhong.png
new file mode 100644
index 0000000..0294aa8
Binary files /dev/null and b/Image/BlinnPhong.png differ
diff --git a/Image/BlinnPhongVsUnsharp.gif b/Image/BlinnPhongVsUnsharp.gif
new file mode 100644
index 0000000..fbc32b7
Binary files /dev/null and b/Image/BlinnPhongVsUnsharp.gif differ
diff --git a/Image/Blinn_Phong.gif b/Image/Blinn_Phong.gif
new file mode 100644
index 0000000..da07df9
Binary files /dev/null and b/Image/Blinn_Phong.gif differ
diff --git a/Image/Bloom.png b/Image/Bloom.png
new file mode 100644
index 0000000..c1c260f
Binary files /dev/null and b/Image/Bloom.png differ
diff --git a/Image/Compare.png b/Image/Compare.png
new file mode 100644
index 0000000..a3716f6
Binary files /dev/null and b/Image/Compare.png differ
diff --git a/Image/DebugView.gif b/Image/DebugView.gif
new file mode 100644
index 0000000..e4d746a
Binary files /dev/null and b/Image/DebugView.gif differ
diff --git a/Image/Performance.png b/Image/Performance.png
new file mode 100644
index 0000000..036122a
Binary files /dev/null and b/Image/Performance.png differ
diff --git a/Image/SSAO.png b/Image/SSAO.png
new file mode 100644
index 0000000..fc3a19f
Binary files /dev/null and b/Image/SSAO.png differ
diff --git a/Image/Toon.png b/Image/Toon.png
new file mode 100644
index 0000000..63dd3b3
Binary files /dev/null and b/Image/Toon.png differ
diff --git a/Image/Unsharp.png b/Image/Unsharp.png
new file mode 100644
index 0000000..de0f795
Binary files /dev/null and b/Image/Unsharp.png differ
diff --git a/Image/VisualEffects.gif b/Image/VisualEffects.gif
new file mode 100644
index 0000000..2665d5c
Binary files /dev/null and b/Image/VisualEffects.gif differ
diff --git a/README.md b/README.md
index 5c59b2f..319740c 100644
--- a/README.md
+++ b/README.md
@@ -21,36 +21,36 @@ have issues with Chrome on windows, but Firefox seems to run it fine.
INTRODUCTION:
-------------------------------------------------------------------------------
-In this project, you will get introduced to the basics of deferred shading. You will write GLSL and OpenGL code to perform various tasks in a deferred lighting pipeline such as creating and writing to a G-Buffer.
+In this project, I implemented the basic deferred shader. I write GLSL and OpenGL code to perform various tasks in a deferred lighting pipeline such as creating and writing to a G-Buffer.
-NOTE : The Crytek-Sponza scene is still broken, and I will be pushing a fix for
-it soon.
+The live demo can be found here:
+[Live demo](https://cdn.rawgit.com/chiwsy/Project6-DeferredShader/master/index.html)
--------------------------------------------------------------------------------
-CONTENTS:
--------------------------------------------------------------------------------
-The Project5 root directory contains the following subdirectories:
-
-* js/ contains the javascript files, including external libraries, necessary.
-* assets/ contains the textures that will be used in the second half of the
- assignment.
-* resources/ contains the screenshots found in this readme file.
-
- This Readme file edited as described above in the README section.
+Some of the results from this project:
+
+
+
+
+
+
+
+
+
+
+
-------------------------------------------------------------------------------
OVERVIEW:
-------------------------------------------------------------------------------
-The deferred shader you will write will have the following stages:
+The deferred shader here will have the following stages:
Stage 1 renders the scene geometry to the G-Buffer
* pass.vert
* pass.frag
Stage 2 renders the lighting passes and accumulates to the P-Buffer
-* shade.vert
-* ambient.frag
-* point.frag
+* quad.vert
+* diffuse.frag
* diagnostic.frag
Stage 3 renders the post processing
@@ -59,52 +59,48 @@ Stage 3 renders the post processing
The keyboard controls are as follows:
WASDRF - Movement (along w the arrow keys)
-W - Zoom in
-S - Zoom out
-A - Left
-D - Right
-R - Up
-F - Down
-^ - Up
-v - Down
-< - Left
-> - Right
+* W - Zoom in
+* S - Zoom out
+* A - Left
+* D - Right
+* R - Up
+* F - Down
+* ^ - Up
+* v - Down
+* < - Left
+* > - Right
+* 1 - World Space Position
+* 2 - Normals
+* 3 - Color
+* 4 - Depth
+* 5 - Blinn-Phong
+* 6 - Bloom
+* 7 - Toon
+* 8 - SSAO
+* 9 - Unsharp
+* 0 - Full deferred pipeline
There are also mouse controls for camera rotation.
-------------------------------------------------------------------------------
-REQUIREMENTS:
+Functions:
-------------------------------------------------------------------------------
In this project, you are given code for:
* Loading .obj file
-* Forward shading pipeline
+* Deferred shading pipeline
+* GBuffer pass
-NOTE : The full deferred pipeline will be released on Friday. If you set up
-your deferred pipeline for extra credit, please submit a pull request by Friday.
-If it is partially done, we will give partial extra credit.
+I have implemented:
+* Bloom
+* "Toon" Shading (with basic silhouetting)
+* Screen Space Ambient Occlusion
+* Diffuse and Blinn-Phong shading
-The baseline OpenGL shaders for the rest of the pipeline have been provided to give you
-a sense of what will be neede in subsequent passes.
+And one additional post effect:
+* Unsharp Mask
-You are required to implement:
-* Either of the following effects
- * Bloom
- * "Toon" Shading (with basic silhouetting)
-* Point light sources
-* Screen Space Ambient Occlusion
-**NOTE**: Implementing separable convolution will require another link in your pipeline and will count as an extra feature if you do performance analysis with a standard one-pass 2D convolution. The overhead of rendering and reading from a texture _may_ offset the extra computations for smaller 2D kernels.
-
-You must implement one of the following extras:
-* The effect you did not choose above
-* Compare performance to a normal forward renderer with
- * No optimizations
- * Coarse sort geometry front-to-back for early-z
- * Z-prepass for early-z
-* Optimize g-buffer format, e.g., pack things together, quantize, reconstruct z from normal x and y (because it is normalized), etc.
- * Must be accompanied with a performance analysis to count
-* Additional lighting and pre/post processing effects! (email first please, if they are good you may add multiple).
-------------------------------------------------------------------------------
RUNNING THE CODE:
@@ -147,77 +143,12 @@ a sense of each of the effects:
Article](http://floored.com/blog/2013/ssao-screen-space-ambient-occlusion.html)
-------------------------------------------------------------------------------
-README
--------------------------------------------------------------------------------
-All students must replace or augment the contents of this Readme.md in a clear
-manner with the following:
-
-* A brief description of the project and the specific features you implemented.
-* At least one screenshot of your project running.
-* A 30 second or longer video of your project running. To create the video you
- can use [Open Broadcaster Software](http://obsproject.com)
-* A performance evaluation (described in detail below).
-
--------------------------------------------------------------------------------
-PERFORMANCE EVALUATION
--------------------------------------------------------------------------------
-The performance evaluation is where you will investigate how to make your
-program more efficient using the skills you've learned in class. You must have
-performed at least one experiment on your code to investigate the positive or
-negative effects on performance.
-
-We encourage you to get creative with your tweaks. Consider places in your code
-that could be considered bottlenecks and try to improve them.
-
-Each student should provide no more than a one page summary of their
-optimizations along with tables and or graphs to visually explain any
-performance differences.
-
--------------------------------------------------------------------------------
-THIRD PARTY CODE POLICY
+Performance:
-------------------------------------------------------------------------------
-* Use of any third-party code must be approved by asking on the Google groups.
- 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 ray 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 result in you
- receiving an F for the semester.
-
--------------------------------------------------------------------------------
-SELF-GRADING
--------------------------------------------------------------------------------
-* On the submission date, email your grade, on a scale of 0 to 100, to Liam,
- liamboone@gmail.com, with a one paragraph explanation. Be concise and
- realistic. Recall that we reserve 30 points as a sanity check to adjust your
- grade. Your actual grade will be (0.7 * your grade) + (0.3 * our grade). We
- hope to only use this in extreme cases when your grade does not realistically
- reflect your work - it is either too high or too low. In most cases, we plan
- to give you the exact grade you suggest.
-* Projects are not weighted evenly, e.g., Project 0 doesn't count as much as
- the path tracer. We will determine the weighting at the end of the semester
- based on the size of each project.
+For my browser, I cannot take advantage of the draw buffer. Therefore the program reduced to multi-pass version which is very slow when it comes to the performance part.
+
----
-SUBMISSION
----
-As with the previous projects, you should fork this project and work inside of
-your fork. Upon completion, commit your finished project back to your fork, and
-make a pull request to the master repository. You should include a README.md
-file in the root directory detailing the following
-
-* A brief description of the project and specific features you implemented
-* At least one screenshot of your project running.
-* A link to a video of your project running.
-* Instructions for building and running your project if they differ from the
- base code.
-* A performance writeup as detailed above.
-* A list of all third-party code used.
-* This Readme file edited as described above in the README section.
---
ACKNOWLEDGEMENTS
diff --git a/assets/deferred/colorPass.frag b/assets/deferred/colorPass.frag
new file mode 100644
index 0000000..c151235
--- /dev/null
+++ b/assets/deferred/colorPass.frag
@@ -0,0 +1,7 @@
+precision highp float;
+
+uniform sampler2D u_sampler;
+
+void main(void){
+ gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
+}
diff --git a/assets/deferred/colorPass.vert b/assets/deferred/colorPass.vert
new file mode 100644
index 0000000..9c3901c
--- /dev/null
+++ b/assets/deferred/colorPass.vert
@@ -0,0 +1,9 @@
+precision highp float;
+
+attribute vec3 a_pos;
+
+uniform mat4 u_mvp;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+}
diff --git a/assets/deferred/diagnostic.frag b/assets/deferred/diagnostic.frag
new file mode 100644
index 0000000..d47a5e9
--- /dev/null
+++ b/assets/deferred/diagnostic.frag
@@ -0,0 +1,40 @@
+precision highp float;
+
+#define DISPLAY_POS 1
+#define DISPLAY_NORMAL 2
+#define DISPLAY_COLOR 3
+#define DISPLAY_DEPTH 4
+
+uniform sampler2D u_positionTex;
+uniform sampler2D u_normalTex;
+uniform sampler2D u_colorTex;
+uniform sampler2D u_depthTex;
+
+uniform float u_zFar;
+uniform float u_zNear;
+uniform int u_displayType;
+
+varying vec2 v_texcoord;
+
+float linearizeDepth( float exp_depth, float near, float far ){
+ return ( 2.0 * near ) / ( far + near - exp_depth * ( far - near ) );
+}
+
+void main()
+{
+ vec3 normal = texture2D( u_normalTex, v_texcoord ).xyz;
+ vec3 position = texture2D( u_positionTex, v_texcoord ).xyz;
+ vec4 color = texture2D( u_colorTex, v_texcoord );
+ float depth = texture2D( u_depthTex, v_texcoord ).x;
+
+ depth = linearizeDepth( depth, u_zNear, u_zFar );
+
+ if( u_displayType == DISPLAY_DEPTH )
+ gl_FragColor = vec4( depth, depth, depth, 1 );
+ else if( u_displayType == DISPLAY_COLOR )
+ gl_FragColor = color;
+ else if( u_displayType == DISPLAY_NORMAL )
+ gl_FragColor = vec4( normal, 1 );
+ else
+ gl_FragColor = vec4( position, 1 );
+}
diff --git a/assets/deferred/diffuse.frag b/assets/deferred/diffuse.frag
new file mode 100644
index 0000000..ef0c5fc
--- /dev/null
+++ b/assets/deferred/diffuse.frag
@@ -0,0 +1,23 @@
+precision highp float;
+
+uniform sampler2D u_positionTex;
+uniform sampler2D u_normalTex;
+uniform sampler2D u_colorTex;
+uniform sampler2D u_depthTex;
+
+uniform float u_zFar;
+uniform float u_zNear;
+uniform int u_displayType;
+
+varying vec2 v_texcoord;
+
+float linearizeDepth( float exp_depth, float near, float far ){
+ return ( 2.0 * near ) / ( far + near - exp_depth * ( far - near ) );
+}
+
+void main()
+{
+ // Write a diffuse shader and a Blinn-Phong shader
+ // NOTE : You may need to add your own normals to fulfill the second's requirements
+ gl_FragColor = vec4(texture2D(u_colorTex, v_texcoord).rgb, 1.0);
+}
diff --git a/assets/deferred/normPass.frag b/assets/deferred/normPass.frag
new file mode 100644
index 0000000..b41d6ed
--- /dev/null
+++ b/assets/deferred/normPass.frag
@@ -0,0 +1,7 @@
+precision highp float;
+
+varying vec3 v_normal;
+
+void main(void){
+ gl_FragColor = vec4(v_normal, 1.0);
+}
diff --git a/assets/deferred/normPass.vert b/assets/deferred/normPass.vert
new file mode 100644
index 0000000..9a0b4b4
--- /dev/null
+++ b/assets/deferred/normPass.vert
@@ -0,0 +1,15 @@
+precision highp float;
+
+attribute vec3 a_pos;
+attribute vec3 a_normal;
+
+uniform mat4 u_mvp;
+uniform mat4 u_normalMat;
+
+varying vec3 v_normal;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+
+ v_normal = vec3( u_normalMat * vec4(a_normal, 0.0) );
+}
diff --git a/assets/deferred/pass.frag b/assets/deferred/pass.frag
new file mode 100644
index 0000000..2416199
--- /dev/null
+++ b/assets/deferred/pass.frag
@@ -0,0 +1,16 @@
+#extension GL_EXT_draw_buffers: require
+precision highp float;
+
+uniform sampler2D u_sampler;
+
+varying vec4 v_pos;
+varying vec3 v_normal;
+varying vec2 v_texcoord;
+varying float v_depth;
+
+void main(void){
+ gl_FragData[0] = v_pos;
+ gl_FragData[1] = vec4( normalize(v_normal), 1.0 );
+ gl_FragData[2] = vec4( 1.0, 0.0, 0.0, 1.0 );
+ gl_FragData[3] = vec4( v_depth, 0, 0, 0 );
+}
diff --git a/assets/deferred/pass.vert b/assets/deferred/pass.vert
new file mode 100644
index 0000000..861cb1a
--- /dev/null
+++ b/assets/deferred/pass.vert
@@ -0,0 +1,26 @@
+precision highp float;
+
+attribute vec3 a_pos;
+attribute vec3 a_normal;
+attribute vec2 a_texcoord;
+
+uniform mat4 u_projection;
+uniform mat4 u_modelview;
+uniform mat4 u_mvp;
+uniform mat4 u_normalMat;
+
+varying vec4 v_pos;
+varying vec3 v_normal;
+varying vec2 v_texcoord;
+varying float v_depth;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+
+ v_pos = u_modelview * vec4( a_pos, 1.0 );
+ v_normal = vec3( u_normalMat * vec4(a_normal,0.0) );
+
+ v_texcoord = a_texcoord;
+
+ v_depth = ( gl_Position.z / gl_Position.w + 1.0 ) / 2.0;
+}
diff --git a/assets/deferred/posPass.frag b/assets/deferred/posPass.frag
new file mode 100644
index 0000000..645a521
--- /dev/null
+++ b/assets/deferred/posPass.frag
@@ -0,0 +1,8 @@
+precision highp float;
+
+varying vec4 v_pos;
+varying float v_depth;
+
+void main(void){
+ gl_FragColor = v_pos;
+}
diff --git a/assets/deferred/posPass.vert b/assets/deferred/posPass.vert
new file mode 100644
index 0000000..ece8cc4
--- /dev/null
+++ b/assets/deferred/posPass.vert
@@ -0,0 +1,15 @@
+precision highp float;
+
+attribute vec3 a_pos;
+
+uniform mat4 u_modelview;
+uniform mat4 u_mvp;
+
+varying vec4 v_pos;
+varying float v_depth;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+ v_pos = u_modelview * vec4( a_pos, 1.0 );
+ v_depth = ( gl_Position.z / gl_Position.w + 1.0 ) / 2.0;
+}
diff --git a/assets/deferred/post.frag b/assets/deferred/post.frag
new file mode 100644
index 0000000..18ac4d8
--- /dev/null
+++ b/assets/deferred/post.frag
@@ -0,0 +1,182 @@
+precision highp float;
+#define DISPLAY_TOON 5
+#define DISPLAY_BLOOM 6
+#define DISPLAY_BLINN 7
+#define DISPLAY_SSAO 8
+#define DISPLAY_BLUR 9
+
+#define KERNEL_SIZE 21
+#define SAMPLEKERNEL_SIZE 100
+
+uniform sampler2D u_shadeTex;
+
+varying vec2 v_texcoord;
+
+//Added
+uniform sampler2D u_positionTex;
+uniform sampler2D u_normalTex;
+uniform sampler2D u_colorTex;
+uniform sampler2D u_depthTex;
+
+uniform float u_zFar;
+uniform float u_zNear;
+uniform int u_displayType;
+uniform float u_ScreenWidth;
+uniform float u_ScreenHeight;
+
+uniform mat4 u_projection;
+uniform float u_radius;
+uniform vec3 u_samplekernel[100];
+
+
+float linearizeDepth( float exp_depth, float near, float far ){
+ return ( 2.0 * near ) / ( far + near - exp_depth * ( far - near ) );
+}
+
+
+float gaussian2d(int x,int y,int n) {
+ float sigma = 2.0;
+ float fx = float(x) - (float(n) - 1.0) / 2.0;
+ float fy = float(y) - (float(n) - 1.0) / 2.0;
+ return (exp(-abs(fx*fy)/ (2.0*sigma*sigma)))/ (2.0 * 3.1415926 *sigma*sigma);
+}
+
+vec4 bloomShader() {
+ float offsetw = 1.0 / u_ScreenWidth;
+ float offseth = 1.0 / u_ScreenHeight;
+ float width = (float(KERNEL_SIZE) - 1.0) / 2.0;
+ vec3 c = vec3(0.0,0.0,0.0);
+
+ for(int i=0; i< KERNEL_SIZE; i++){
+ for(int j=0; j< KERNEL_SIZE; j++){
+ vec2 tc = v_texcoord;
+ tc.y += (float(i)-width)*offseth;
+ tc.x += (float(j)-width)*offsetw;
+ c += gaussian2d(i,j,KERNEL_SIZE) * texture2D(u_shadeTex, tc).rgb;
+ }
+ }
+
+ return vec4(c,1.0);
+}
+
+//SSAO
+float rand(float co){
+ return fract(sin(dot(vec2(co,co) ,vec2(12.9898,78.233))) * 43758.5453);
+}
+
+//http://john-chapman-graphics.blogspot.co.uk/2013/01/ssao-tutorial.html
+vec4 SSAO() {
+/*
+ vec3 normal = texture2D(u_normalTex, v_texcoord).xyz;
+ vec3 position = texture2D(u_positionTex, v_texcoord).xyz;
+ float depth = texture2D(u_depthTex, v_texcoord).r;
+ depth = linearizeDepth( depth, u_zNear, u_zFar );
+ float occlusion = 0.0;
+ vec3 origin = vec3(position.x, position.y, depth);
+
+ for(int i = 0; i < SAMPLEKERNEL_SIZE; ++i){
+
+ vec3 rvec = normalize(u_samplekernel[i]);
+ vec3 tangent = normalize(rvec - normal * dot(rvec, normal));
+ vec3 bitangent = cross(normal, tangent);
+ mat3 tbn = mat3(tangent, bitangent, normal);
+
+ vec3 kernelv = vec3(rand(position.x),rand(position.y),(rand(position.z)+1.0) / 2.0);
+ kernelv = normalize(kernelv);
+ float scale = float(i) / float(SAMPLEKERNEL_SIZE);
+ scale = mix(0.1, 1.0, scale * scale);
+ kernelv = kernelv * scale ;
+
+ vec3 sample = tbn * kernelv;
+ float sampleDepth = texture2D(u_depthTex, v_texcoord + vec2(sample.x,sample.y)* u_radius).r;
+ sampleDepth = linearizeDepth( sampleDepth, u_zNear, u_zFar );
+
+ float samplez = origin.z - (sample * u_radius).z / 2.0;
+
+ //rangeCheck helps to prevent erroneous occlusion between large depth discontinuities:
+ float rangeCheck = abs(origin.z - sampleDepth) < u_radius ? 1.0 : 0.0;
+
+ if(sampleDepth <= samplez)
+ occlusion += 1.0 * rangeCheck;
+ }
+
+ occlusion = 1.0 - (occlusion / float(SAMPLEKERNEL_SIZE));
+
+ return vec4(vec3(occlusion,occlusion,occlusion), 1.0);
+ */
+ vec3 nml = texture2D( u_normalTex, v_texcoord ).xyz;
+ vec3 pos = texture2D(u_positionTex, v_texcoord).xyz;
+ float dp = texture2D(u_depthTex, v_texcoord).r;
+ dp = linearizeDepth( dp, u_zNear, u_zFar );
+ float occ=0.0;
+ vec3 ori=vec3(pos.x,pos.y,dp);
+
+ for(int i=0;i.8)
+ outClr=clr0;
+ else if(toonSel>.6)
+ outClr=mix(clr0,clr1,toonSel*2.5-1.0);
+ else if(toonSel>.4)
+ outClr=mix(clr0,clr1,(toonSel)*1.25);
+ else if(toonSel>.2)
+ outClr=mix(clr0,clr1,(toonSel)*.625);
+ else
+ outClr=mix(clr0,clr1,(toonSel)*.3125);
+
+ float mag=0.0;
+
+ for(int i=-1;i<=3;i++){
+ for(int j=-1;j<=3;j++){
+ float x=(float(i)-1.0)/1024.0;
+ float y=(float(j)-1.0)/512.0;
+
+ float Nearby=texture2D(u_depthTex,v_texcoord+vec2(x,y)).x;
+
+ if(Nearby>.99){
+ outClr=vec3(0.0);
+ break;
+ }
+ }
+ }
+ }
+ if(clr.x > .5)
+ gl_FragColor = vec4(outClr, 1.0);
+ else
+ gl_FragColor = vec4(.8,.8,.8,1.0);
+}
diff --git a/assets/shader/deferred/normPass.frag b/assets/shader/deferred/normPass.frag
new file mode 100644
index 0000000..b41d6ed
--- /dev/null
+++ b/assets/shader/deferred/normPass.frag
@@ -0,0 +1,7 @@
+precision highp float;
+
+varying vec3 v_normal;
+
+void main(void){
+ gl_FragColor = vec4(v_normal, 1.0);
+}
diff --git a/assets/shader/deferred/normPass.vert b/assets/shader/deferred/normPass.vert
new file mode 100644
index 0000000..9a0b4b4
--- /dev/null
+++ b/assets/shader/deferred/normPass.vert
@@ -0,0 +1,15 @@
+precision highp float;
+
+attribute vec3 a_pos;
+attribute vec3 a_normal;
+
+uniform mat4 u_mvp;
+uniform mat4 u_normalMat;
+
+varying vec3 v_normal;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+
+ v_normal = vec3( u_normalMat * vec4(a_normal, 0.0) );
+}
diff --git a/assets/shader/deferred/pass.frag b/assets/shader/deferred/pass.frag
index e37dcbf..2416199 100644
--- a/assets/shader/deferred/pass.frag
+++ b/assets/shader/deferred/pass.frag
@@ -1,18 +1,16 @@
-#version 330
+#extension GL_EXT_draw_buffers: require
+precision highp float;
-uniform float u_Far;
-uniform vec3 u_Color;
+uniform sampler2D u_sampler;
-in vec3 fs_Normal;
-in vec4 fs_Position;
+varying vec4 v_pos;
+varying vec3 v_normal;
+varying vec2 v_texcoord;
+varying float v_depth;
-out vec4 out_Normal;
-out vec4 out_Position;
-out vec4 out_Color;
-
-void main(void)
-{
- out_Normal = vec4(normalize(fs_Normal),0.0f);
- out_Position = vec4(fs_Position.xyz,1.0f); //Tuck position into 0 1 range
- out_Color = vec4(u_Color,1.0);
+void main(void){
+ gl_FragData[0] = v_pos;
+ gl_FragData[1] = vec4( normalize(v_normal), 1.0 );
+ gl_FragData[2] = vec4( 1.0, 0.0, 0.0, 1.0 );
+ gl_FragData[3] = vec4( v_depth, 0, 0, 0 );
}
diff --git a/assets/shader/deferred/pass.vert b/assets/shader/deferred/pass.vert
index e36825f..861cb1a 100644
--- a/assets/shader/deferred/pass.vert
+++ b/assets/shader/deferred/pass.vert
@@ -1,21 +1,26 @@
-#version 330
+precision highp float;
+attribute vec3 a_pos;
+attribute vec3 a_normal;
+attribute vec2 a_texcoord;
-uniform mat4x4 u_Model;
-uniform mat4x4 u_View;
-uniform mat4x4 u_Persp;
-uniform mat4x4 u_InvTrans;
+uniform mat4 u_projection;
+uniform mat4 u_modelview;
+uniform mat4 u_mvp;
+uniform mat4 u_normalMat;
-in vec3 Position;
-in vec3 Normal;
+varying vec4 v_pos;
+varying vec3 v_normal;
+varying vec2 v_texcoord;
+varying float v_depth;
-out vec3 fs_Normal;
-out vec4 fs_Position;
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
-void main(void) {
- fs_Normal = (u_InvTrans*vec4(Normal,0.0f)).xyz;
- vec4 world = u_Model * vec4(Position, 1.0);
- vec4 camera = u_View * world;
- fs_Position = camera;
- gl_Position = u_Persp * camera;
+ v_pos = u_modelview * vec4( a_pos, 1.0 );
+ v_normal = vec3( u_normalMat * vec4(a_normal,0.0) );
+
+ v_texcoord = a_texcoord;
+
+ v_depth = ( gl_Position.z / gl_Position.w + 1.0 ) / 2.0;
}
diff --git a/assets/shader/deferred/posPass.frag b/assets/shader/deferred/posPass.frag
new file mode 100644
index 0000000..645a521
--- /dev/null
+++ b/assets/shader/deferred/posPass.frag
@@ -0,0 +1,8 @@
+precision highp float;
+
+varying vec4 v_pos;
+varying float v_depth;
+
+void main(void){
+ gl_FragColor = v_pos;
+}
diff --git a/assets/shader/deferred/posPass.vert b/assets/shader/deferred/posPass.vert
new file mode 100644
index 0000000..ece8cc4
--- /dev/null
+++ b/assets/shader/deferred/posPass.vert
@@ -0,0 +1,15 @@
+precision highp float;
+
+attribute vec3 a_pos;
+
+uniform mat4 u_modelview;
+uniform mat4 u_mvp;
+
+varying vec4 v_pos;
+varying float v_depth;
+
+void main(void){
+ gl_Position = u_mvp * vec4( a_pos, 1.0 );
+ v_pos = u_modelview * vec4( a_pos, 1.0 );
+ v_depth = ( gl_Position.z / gl_Position.w + 1.0 ) / 2.0;
+}
diff --git a/assets/shader/deferred/post.frag b/assets/shader/deferred/post.frag
index 2bf5afc..5eb8c5e 100644
--- a/assets/shader/deferred/post.frag
+++ b/assets/shader/deferred/post.frag
@@ -1,74 +1,150 @@
-#version 330
+precision highp float;
+#define DIFFUSE 5
+#define BLOOM 6
+#define TOON 7
+#define SSAO 8
+#define UNSHARP 9
-////////////////////////////
-// ENUMERATIONS
-////////////////////////////
-#define DISPLAY_DEPTH 0
-#define DISPLAY_NORMAL 1
-#define DISPLAY_POSITION 2
-#define DISPLAY_COLOR 3
-#define DISPLAY_TOTAL 4
-#define DISPLAY_LIGHTS 5
+#define SIZE 31
+#define SAMPLER_SIZE 80
+uniform sampler2D u_positionTex;
+uniform sampler2D u_normalTex;
+uniform sampler2D u_colorTex;
+uniform sampler2D u_depthTex;
-/////////////////////////////////////
-// Uniforms, Attributes, and Outputs
-////////////////////////////////////
-uniform sampler2D u_Posttex;
-uniform sampler2D u_RandomNormaltex;
-uniform sampler2D u_RandomScalartex;
+uniform float u_zFar;
+uniform float u_zNear;
+uniform int u_displayType;
-uniform int u_ScreenWidth;
-uniform int u_ScreenHeight;
+uniform sampler2D u_shadeTex;
-in vec2 fs_Texcoord;
+varying vec2 v_texcoord;
-out vec4 out_Color;
-///////////////////////////////////////
+uniform float u_rad;
+uniform vec3 u_sampler[80];
-uniform float zerothresh = 1.0f;
-uniform float falloff = 0.1f;
+
+float gaussian(int x,int y,int n) {
+ float sigma = 2.0;
+ float fx = float(x) - (float(n) - 1.0) / 2.0;
+ float fy = float(y) - (float(n) - 1.0) / 2.0;
+ return (exp(-abs(fx*fy)/ (2.0*sigma*sigma)))/ (2.0 * 3.1415926 *sigma*sigma);
+}
-/////////////////////////////////////
-// UTILITY FUNCTIONS
-/////////////////////////////////////
+float linearizeDepth( float exp_depth, float near, float far ){
+ return ( 2.0 * near ) / ( far + near - exp_depth * ( far - near ) );
+}
+
+vec4 Bloom(){
+ float x=1.0/1024.0;
+ float y=1.0/512.0;
+
+ float wid=(float(SIZE)-1.0)/2.0;
+ vec3 cc=vec3(0.0);
+
+ for(int i=0;iCIS 565 WebGL Deferred Shader
+ FPS=0