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
164 changes: 16 additions & 148 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,173 +1,41 @@
-------------------------------------------------------------------------------
CIS565: Project 6: Deferred Shader
-------------------------------------------------------------------------------
Fall 2013
-------------------------------------------------------------------------------
Due Friday 11/15/2013
-------------------------------------------------------------------------------

-------------------------------------------------------------------------------
NOTE:
-------------------------------------------------------------------------------
This project requires any graphics card with support for a modern OpenGL
pipeline. Any AMD, NVIDIA, or Intel card from the past few years should work
fine, and every machine in the SIG Lab and Moore 100 is capable of running
this project.

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

-------------------------------------------------------------------------------
CONTENTS:
-------------------------------------------------------------------------------
The Project6 root directory contains the following subdirectories:

* base/
* PROJ_WIN/ contains the vs2010 project files
* PROJ_NIX/ contains makefile for building (tested on ubuntu 12.04 LTS)
* res/ contains resources including shader source and obj files
* src/ contains the c++ code for the project along with SOIL and tiny_obj_loader
* shared32/ contains freeglut, glm, and glew.

---
BASE CODE TOUR
---

Most of your edits will be confined to the various fragment shader programs and main.cpp.

Some methods worth exploring are:
Yuqin Shao

[initShader](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L223):
This method initializes each shader program from specified source files. Note that the source name is declared inside a `#ifdef WIN32` guard block. This is done to reflect the relative directory structure between the linux and windows versions of the code.

[initFBO](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L360):
This method initializes the framebuffer objects used as render targets for the first and second stage of the pipeline. When you go to add another slot to the G buffer you will need to modify to first FBO accordingly. Try finding all the places where `colorTexture` is used (ctrl+F in windows will be helpful) and look at how textures are created, freed, added to the FBO, and assigned to the appropriate shader programs before adding your own. Also keep in mind that textures can be reused as inputs in other pipeline stages, for instance you might want access to the normals both in the lighting stage and in the post process stage.

[draw_mesh](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L574),
[draw_quad](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L647),
[draw_light](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L657):
These methods render the scene geometry, viewing quad, and point light quad to the screen. The draw_light method in particular is interesting because it will set up the scissor window for efficient rendering of point lights.

[display](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L742):
This is where the graphical work of your program is done. The method is separated into three stages with the majority of work being done in stage 2.

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

Stage 3 renders the post processing
* post.vert
* post.frag

[keyboard](https://github.com/CIS565-Fall-2013/Project6-DeferredShader/blob/master/base/src/main.cpp#L870):
This is a good reference for the key mappings in the program.
WASDQZ - Movement
X - Toggle scissor test
R - Reload shaders
1 - View depth
2 - View eye space normals
3 - View Diffuse color
4 - View eye space positions
5 - View lighting debug mode
0 - Standard view

-------------------------------------------------------------------------------
REQUIREMENTS:
Featurues:
-------------------------------------------------------------------------------

In this project, you are given code for:
* Loading .obj files
* Rendering to a minimal G buffer:
* Depth
* Normal
* Color
* Eye space position
* Rendering simple ambient and directional lighting to texture
* Example post process shader to add a vignette

You are required to implement:
* Either of the following effects
* Bloom (feel free to use [GPU Gems](http://http.developer.nvidia.com/GPUGems/gpugems_ch21.html) as a rough guide)
* "Toon" Shading (with basic silhouetting)
* Bloom Effects
* Toon Shading
* Point light sources
* An additional G buffer slot and some effect showing it off
* Specular map slot added to G buffer
* Separable convolution for bloom effects as well as performance evaluation listed below.
* [Note] press 6 to show bloom effects, press 7 show toon shading, press 8 show specular map

**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.
A vedio demo could be found here http://youtu.be/BtFBi01tdqA

You must implement two of the following extras:
* The effect you did not choose above
* Screen space ambient occlusion
* 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).

-------------------------------------------------------------------------------
README
Screen Shots
-------------------------------------------------------------------------------
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 http://www.microsoft.com/expression/products/Encoder4_Overview.aspx
* A performance evaluation (described in detail below).
![Alt test] (screenshots/Bloom_separable.JPG "Bloom Effects" )

-------------------------------------------------------------------------------
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.
![Alt test] (screenshots/ToonShadingWithSilhoutte.JPG "toon shading")

We encourage you to get creative with your tweaks. Consider places in your code
that could be considered bottlenecks and try to improve them.
![Alt test] (screenshots/specular.JPG "specular")

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.
![Alt test] (screenshots/specularMap.JPG "specular map")

-------------------------------------------------------------------------------
THIRD PARTY CODE POLICY
-------------------------------------------------------------------------------
* 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
PERFORMANCE EVALUATION
-------------------------------------------------------------------------------
* 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.
![Alt test] (screenshots/perform1.png "separable convolution evaluation")

![Alt test] (screenshots/perform2.png "point light radius evaluation")

---
SUBMISSION
Expand Down
6 changes: 5 additions & 1 deletion base/PROJ_WIN/P6/P6/P6.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
<EnableCOMDATFolding>true</EnableCOMDATFolding>
<OptimizeReferences>true</OptimizeReferences>
<AdditionalLibraryDirectories>$(SolutionDir)$(Configuration);..\..\..\..\shared32\glew\lib;..\..\..\..\shared32\freeglut\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>freeglut.lib;glew32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>freeglut.lib;glew32.lib;SOIL.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
Expand All @@ -83,14 +83,18 @@
</ItemGroup>
<ItemGroup>
<None Include="..\..\..\res\shaders\ambient.frag" />
<None Include="..\..\..\res\shaders\bloom.frag" />
<None Include="..\..\..\res\shaders\bloom.vert" />
<None Include="..\..\..\res\shaders\diagnostic.frag" />
<None Include="..\..\..\res\shaders\directional.frag" />
<None Include="..\..\..\res\shaders\horblur.frag" />
<None Include="..\..\..\res\shaders\pass.frag" />
<None Include="..\..\..\res\shaders\pass.vert" />
<None Include="..\..\..\res\shaders\point.frag" />
<None Include="..\..\..\res\shaders\post.frag" />
<None Include="..\..\..\res\shaders\post.vert" />
<None Include="..\..\..\res\shaders\shade.vert" />
<None Include="..\..\..\res\shaders\verblur.frag" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
Expand Down
12 changes: 12 additions & 0 deletions base/PROJ_WIN/P6/P6/P6.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,17 @@
<None Include="..\..\..\res\shaders\shade.vert">
<Filter>Resource Files</Filter>
</None>
<None Include="..\..\..\res\shaders\bloom.frag">
<Filter>Resource Files</Filter>
</None>
<None Include="..\..\..\res\shaders\bloom.vert">
<Filter>Resource Files</Filter>
</None>
<None Include="..\..\..\res\shaders\horblur.frag">
<Filter>Resource Files</Filter>
</None>
<None Include="..\..\..\res\shaders\verblur.frag">
<Filter>Resource Files</Filter>
</None>
</ItemGroup>
</Project>
Binary file added base/PROJ_WIN/P6/SOIL/freeglut.dll
Binary file not shown.
21 changes: 19 additions & 2 deletions base/res/cornell/cornell_box.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,40 @@ newmtl white
Ka 0 0 0
Kd 0.9 0.9 0.9
Ks 0 0 0
Ns 0

newmtl red
Ka 0 0 0
Kd 1 0 0
Ks 0 0 0
Ns 0

newmtl green
Ka 0 0 0
Kd 0 1 0
Ks 0 0 0
Ks 1 1 1
Ns 0

newmtl blue
Ka 0 0 0
Kd 0 0 1
Ks 0 0 0
Ns 0

newmtl yellow
Ka 0 0 0
Kd 1 1 0
Ks 0 0 0
Ns 1.0

newmtl lightblue
Ka 0 0 0
Kd 0 1 1
Ks 1 1 1
Ns 0

newmtl light
Ka 20 20 20
Kd 1 1 1
Kd 1 0 1
Ks 0 0 0
Ns 1.0
13 changes: 6 additions & 7 deletions base/res/cornell/cornell_box.obj
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ f 12 11 10 9

o light
usemtl light
v 343.0 548.0 227.0
v 343.0 548.0 332.0
v 213.0 548.0 332.0
v 213.0 548.0 227.0
v 343.0 548.0 317.0
v 343.0 548.0 422.0
v 213.0 548.0 422.0
v 213.0 548.0 317.0
f -4 -3 -2 -1

o ceiling
Expand Down Expand Up @@ -77,7 +77,7 @@ v 556.0 548.8 0.0
f -4 -3 -2 -1

o short_block
usemtl white
usemtl yellow

v 130.0 165.0 65.0
v 82.0 165.0 225.0
Expand Down Expand Up @@ -110,15 +110,14 @@ v 82.0 0.0 225.0
f -4 -3 -2 -1

o tall_block
usemtl white
usemtl lightblue

v 423.0 330.0 247.0
v 265.0 330.0 296.0
v 314.0 330.0 456.0
v 472.0 330.0 406.0
f -4 -3 -2 -1

usemtl white
v 423.0 0.0 247.0
v 423.0 330.0 247.0
v 472.0 330.0 406.0
Expand Down
15 changes: 15 additions & 0 deletions base/res/quad.obj
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Blender v2.57 (sub 0) OBJ File: ''
# www.blender.org
o Cube_Cube.001
v -1.000000 1.000000 0.000000
v 1.000000 1.000000 0.000000
v -1.000000 -1.000000 0.000000
v 1.000000 -1.000000 0.000000
vt 1.000000 0.000000
vt 0.000000 0.000000
vt 0.000000 1.000000
vt 1.000000 1.000000
usemtl (null)
s off
f 4/4 3/3 1/2
f 2/1 4/4 1/2
19 changes: 13 additions & 6 deletions base/res/shaders/ambient.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
#define DISPLAY_COLOR 3
#define DISPLAY_TOTAL 4
#define DISPLAY_LIGHTS 5

#define DISPLAY_BLOOM 6
#define DISPLAY_SIL 7

/////////////////////////////////////
// Uniforms, Attributes, and Outputs
Expand All @@ -23,7 +24,8 @@ uniform sampler2D u_Positiontex;
uniform sampler2D u_Colortex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;

uniform sampler2D u_Bloomtex;
uniform sampler2D u_Speculartex;
uniform float u_Far;
uniform float u_Near;
uniform int u_OcclusionType;
Expand Down Expand Up @@ -101,15 +103,20 @@ void main() {
vec3 normal = sampleNrm(fs_Texcoord);
vec3 position = samplePos(fs_Texcoord);
vec3 color = sampleCol(fs_Texcoord);
vec4 color4 = texture(u_Colortex,fs_Texcoord).xyzw;
vec3 light = u_Light.xyz;
float strength = u_Light.w;
vec4 ambColor = vec4(0.0);
if (lin_depth > 0.99f) {
out_Color = vec4(vec3(0.0), 1.0);
ambColor = vec4(vec3(0.0), 1.0);
} else {
float ambient = u_LightIl;
float diffuse = max(0.0, dot(normalize(light),normal));
out_Color = vec4(color*(strength*diffuse + ambient),1.0f);
}
float diffuse = max(0.0, dot(normalize(light),normal));
ambColor = vec4(color*(strength*diffuse + ambient),1.0);
}

out_Color = ambColor;

return;
}

Loading