Skip to content
Open
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
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,47 @@

![lights_plus_bloom](base/images/lights_p_bloom.png)

-------------------------------------------------------------------------------
CIS565: Project 6: Deferred Shader
-------------------------------------------------------------------------------

The goal of this project was to explore and learn about deferred shading techniques

For this project I've implemented:
* Bloom
* "Toon" Shading (with basic silhouetting)
* Point light sources

I have a g-buffer slot added, but didn't end up using it for anything, so that
doesn't exactly count.

---
Images:
---
Toon Shading:
![toon_shading](base/images/toon_shading.png)

Toon Shading with Bloom ( just for fun ):
![toon_plus_bloom](base/images/toon_plus_bloom.png)

---
Video:
---
A painfully buggy video attempting to show off various features ( I've gotta redo this one ).
http://youtu.be/yHgk-cvPy9Q

---
Performance Analysis:
---
Mode vs FPS:
* No Bloom: ~59
* Bloom width 10: ~25
* Bloom width 25: ~12
* Bloom width 50: ~5
* Silhouetting: ~40
* ...


Fall 2013
-------------------------------------------------------------------------------
Due Friday 11/15/2013
Expand Down
Binary file added base/PROJ_NIX/565DefferedShader
Binary file not shown.
Binary file added base/images/lights_p_bloom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/images/toon_plus_bloom.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added base/images/toon_shading.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions base/res/cornell/cornell_box.obj
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ v 556.0 548.8 0
#f -1 -2 -3 -4

o green_wall
usemtl green
usemtl red
v 0.0 0.0 559.2
v 0.0 0.0 0.0
v 0.0 548.8 0.0
Expand All @@ -77,7 +77,7 @@ v 556.0 548.8 0.0
f -4 -3 -2 -1

o short_block
usemtl white
usemtl green

v 130.0 165.0 65.0
v 82.0 165.0 225.0
Expand Down
7 changes: 4 additions & 3 deletions base/res/shaders/ambient.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uniform sampler2D u_Depthtex;
uniform sampler2D u_Normaltex;
uniform sampler2D u_Positiontex;
uniform sampler2D u_Colortex;
uniform sampler2D u_idtex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;

Expand All @@ -38,10 +39,9 @@ uniform float u_LightIl;
in vec2 fs_Texcoord;

out vec4 out_Color;
///////////////////////////////////////


out vec4 out_Normal;

///////////////////////////////////////

uniform float zerothresh = 1.0f;
uniform float falloff = 0.1f;
Expand Down Expand Up @@ -110,6 +110,7 @@ void main() {
float diffuse = max(0.0, dot(normalize(light),normal));
out_Color = vec4(color*(strength*diffuse + ambient),1.0f);
}
out_Normal = vec4( normal, 0.0 );
return;
}

8 changes: 6 additions & 2 deletions base/res/shaders/diagnostic.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define DISPLAY_COLOR 3
#define DISPLAY_TOTAL 4
#define DISPLAY_LIGHTS 5
#define DISPLAY_ID 6


/////////////////////////////////////
Expand All @@ -21,6 +22,7 @@ uniform sampler2D u_Depthtex;
uniform sampler2D u_Normaltex;
uniform sampler2D u_Positiontex;
uniform sampler2D u_Colortex;
uniform sampler2D u_idtex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;

Expand All @@ -41,8 +43,6 @@ out vec4 out_Color;
///////////////////////////////////////




uniform float zerothresh = 1.0f;
uniform float falloff = 0.1f;

Expand Down Expand Up @@ -101,6 +101,7 @@ void main() {
vec3 normal = sampleNrm(fs_Texcoord);
vec3 position = samplePos(fs_Texcoord);
vec3 color = sampleCol(fs_Texcoord);
vec3 id = texture(u_idtex,fs_Texcoord).xyz;
vec3 light = u_Light.xyz;
float lightRadius = u_Light.w;

Expand All @@ -118,6 +119,9 @@ void main() {
out_Color = vec4(color, 1.0);
break;
case(DISPLAY_LIGHTS):
case(DISPLAY_ID):
out_Color = vec4(id, 1.0);
break;
case(DISPLAY_TOTAL):
break;
}
Expand Down
2 changes: 2 additions & 0 deletions base/res/shaders/pass.frag
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@ in vec4 fs_Position;
out vec4 out_Normal;
out vec4 out_Position;
out vec4 out_Color;
out vec4 out_Sobel;

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);
out_Sobel = vec4(0.0, 0.0, 0.0, 0.0);
}
3 changes: 3 additions & 0 deletions base/res/shaders/pass.vert
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@ uniform mat4x4 u_InvTrans;

in vec3 Position;
in vec3 Normal;
//in unsigned short id;

out vec3 fs_Normal;
out vec4 fs_Position;
//out unsigned short fs_id;

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;
//fs_id = id;
gl_Position = u_Persp * camera;
}
32 changes: 29 additions & 3 deletions base/res/shaders/point.frag
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ uniform sampler2D u_Depthtex;
uniform sampler2D u_Normaltex;
uniform sampler2D u_Positiontex;
uniform sampler2D u_Colortex;
uniform sampler2D u_idtex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;

Expand All @@ -39,9 +40,6 @@ in vec2 fs_Texcoord;
out vec4 out_Color;
///////////////////////////////////////




uniform float zerothresh = 1.0f;
uniform float falloff = 0.1f;

Expand Down Expand Up @@ -93,6 +91,7 @@ float getRandomScalar(vec2 texcoords) {
//////////////////////////////////
const float occlusion_strength = 1.5f;
void main() {
vec3 lightdir;

float exp_depth = texture(u_Depthtex, fs_Texcoord).r;
float lin_depth = linearizeDepth(exp_depth,u_Near,u_Far);
Expand All @@ -102,14 +101,41 @@ void main() {
vec3 color = sampleCol(fs_Texcoord);
vec3 light = u_Light.xyz;
float lightRadius = u_Light.w;

out_Color = vec4(0,0,0,1.0);

out_Color = vec4(0,0,0,1.0);
if( u_DisplayType == DISPLAY_LIGHTS )
{
//Put some code here to visualize the fragment associated with this point light
// This does something sensible for some reason
out_Color = vec4( 0.0f, 1.0f, 0.0f, 1.0f );
}
else
{
//Put some code here to actually compute the light from the point light
// Start with simple diffuse lighting

// Don't render things pointing away from us
if ( dot(position, normal) > 0.0f )
return;

lightdir = light - position;
// Only render those fragments that are close enough ... doesn't seem to do the right thing :/
float radius = length(lightdir)/lightRadius;
if ( radius > 1.0 )
return;

// Light magnitude with linear falloff
// TODO: better lighting falloff
float mag = u_LightIl*(1.0-radius);

// Diffuse term in light
float diffuse = max(dot( normalize(lightdir.xyz), normal ), 0.0f);
// TODO: Specular term ... do later ...

out_Color = vec4(mag*diffuse*color, 1.0);

}
return;
}
Expand Down
Loading