Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,15 @@ REQUIREMENTS:

In this project, you are given code for:
* Loading .obj file
* Forward shading pipeline

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.

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.
* Deferred shading pipeline
* GBuffer pass

You are required to implement:
* Either of the following effects
* Bloom
* "Toon" Shading (with basic silhouetting)
* Screen Space Ambient Occlusion
* Screen Space Ambient Occlusion
* Diffuse and Blinn-Phong shading

**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.

Expand Down
7 changes: 7 additions & 0 deletions assets/deferred/colorPass.frag
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions assets/deferred/colorPass.vert
Original file line number Diff line number Diff line change
@@ -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 );
}
40 changes: 40 additions & 0 deletions assets/deferred/diagnostic.frag
Original file line number Diff line number Diff line change
@@ -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 );
}
23 changes: 23 additions & 0 deletions assets/deferred/diffuse.frag
Original file line number Diff line number Diff line change
@@ -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);
}
7 changes: 7 additions & 0 deletions assets/deferred/normPass.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
precision highp float;

varying vec3 v_normal;

void main(void){
gl_FragColor = vec4(v_normal, 1.0);
}
15 changes: 15 additions & 0 deletions assets/deferred/normPass.vert
Original file line number Diff line number Diff line change
@@ -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) );
}
16 changes: 16 additions & 0 deletions assets/deferred/pass.frag
Original file line number Diff line number Diff line change
@@ -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 );
}
26 changes: 26 additions & 0 deletions assets/deferred/pass.vert
Original file line number Diff line number Diff line change
@@ -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;
}
8 changes: 8 additions & 0 deletions assets/deferred/posPass.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
precision highp float;

varying vec4 v_pos;
varying float v_depth;

void main(void){
gl_FragColor = v_pos;
}
15 changes: 15 additions & 0 deletions assets/deferred/posPass.vert
Original file line number Diff line number Diff line change
@@ -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;
}
17 changes: 17 additions & 0 deletions assets/deferred/post.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
precision highp float;

uniform sampler2D u_shadeTex;

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()
{
// Currently acts as a pass filter that immmediately renders the shaded texture
// Fill in post-processing as necessary HERE
// NOTE : You may choose to use a key-controlled switch system to display one feature at a time
gl_FragColor = vec4(texture2D( u_shadeTex, v_texcoord).rgb, 1.0);
}
11 changes: 11 additions & 0 deletions assets/deferred/quad.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
precision highp float;

attribute vec3 a_pos;
attribute vec2 a_texcoord;

varying vec2 v_texcoord;

void main(void){
v_texcoord = a_texcoord;
gl_Position = vec4( a_pos, 1.0 );
}
12 changes: 12 additions & 0 deletions assets/forward.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
precision highp float;

varying vec3 fs_normal;

void main (void) {
// Using directional light
vec3 dirLight = vec3(0.5, 0.5, 0.5);

gl_FragColor = vec4(vec3(dot(dirLight, fs_normal)), 1.0);

//gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
}
14 changes: 14 additions & 0 deletions assets/forward.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
precision highp float;

uniform mat4 u_persp;
uniform mat4 u_modelView;

attribute vec3 v_position;
attribute vec3 v_normal;

varying vec3 fs_normal;

void main (void) {
fs_normal = v_normal;
gl_Position = u_persp * u_modelView * vec4(v_position, 1.0);
}
Binary file not shown.
10 changes: 10 additions & 0 deletions assets/pass.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
precision highp float;

uniform sampler2D u_texture;

varying vec2 fs_texcoord;

void main(void) {
float color = texture2D(u_texture, fs_texcoord).x;
gl_FragColor = vec4(color, 0.0, 0.0, 1.0);
}
11 changes: 11 additions & 0 deletions assets/pass.vert
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
precision highp float;

attribute vec3 v_position;
attribute vec2 v_texcoord;

varying vec2 fs_texcoord;

void main (void) {
fs_texcoord = v_texcoord;
gl_Position = vec4(v_position, 1.0);
}
7 changes: 7 additions & 0 deletions assets/shader/deferred/colorPass.frag
Original file line number Diff line number Diff line change
@@ -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);
}
9 changes: 9 additions & 0 deletions assets/shader/deferred/colorPass.vert
Original file line number Diff line number Diff line change
@@ -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 );
}
3 changes: 1 addition & 2 deletions assets/shader/deferred/diffuse.frag
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
#extension GL_EXT_draw_buffers: require
precision highp float;

uniform sampler2D u_positionTex;
Expand All @@ -20,5 +19,5 @@ 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_FragData[0] = vec4(texture2D(u_colorTex, v_texcoord).rgb, 1.0);
gl_FragColor = vec4(texture2D(u_colorTex, v_texcoord).rgb, 1.0);
}
7 changes: 7 additions & 0 deletions assets/shader/deferred/normPass.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
precision highp float;

varying vec3 v_normal;

void main(void){
gl_FragColor = vec4(v_normal, 1.0);
}
15 changes: 15 additions & 0 deletions assets/shader/deferred/normPass.vert
Original file line number Diff line number Diff line change
@@ -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) );
}
8 changes: 8 additions & 0 deletions assets/shader/deferred/posPass.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
precision highp float;

varying vec4 v_pos;
varying float v_depth;

void main(void){
gl_FragColor = v_pos;
}
15 changes: 15 additions & 0 deletions assets/shader/deferred/posPass.vert
Original file line number Diff line number Diff line change
@@ -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;
}
4 changes: 2 additions & 2 deletions assets/shader/deferred/quad.vert
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ attribute vec2 a_texcoord;
varying vec2 v_texcoord;

void main(void){
v_texcoord = a_texcoord * 0.5 + vec2(0.5);
v_texcoord = a_texcoord;
gl_Position = vec4( a_pos, 1.0 );
}
}
7 changes: 5 additions & 2 deletions assets/shader/pass.frag
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
precision highp float;

varying vec3 fs_texcoord;
uniform sampler2D u_texture;

varying vec2 fs_texcoord;

void main(void) {
gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0);
float color = texture2D(u_texture, fs_texcoord).x;
gl_FragColor = vec4(color, 0.0, 0.0, 1.0);
}
6 changes: 3 additions & 3 deletions assets/shader/pass.vert
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
precision highp float;

attribute v_position;
attribute v_texcoord;
attribute vec3 v_position;
attribute vec2 v_texcoord;

varying fs_texcoord;
varying vec2 fs_texcoord;

void main (void) {
fs_texcoord = v_texcoord;
Expand Down
Loading