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
Binary file added 1.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 2.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 3.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 4.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 5.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 6.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 7.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 Performance Evaluation.xlsx
Binary file not shown.
30 changes: 30 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,36 @@ Fall 2013
Due Friday 11/15/2013
-------------------------------------------------------------------------------

Implemented:
- Bloom (Press '8'): applies 13x13 box filter on anything that is white-ish.
First tried with 5x5 Gaussian but was not blurry enough and was slowing down
too much.

![Bloom](6.png)

- Toon (Press '7'): also press '6' to get outline.

![toon](2.png)
![outline](1.png)


- Point light sources

![Point light](3.png)
![Point light 2](4.png)

- Additional G buffer: Specular color (tall blue rectangle has red specular color)

![Specular highlight](5.png)

- Store normal.x and normal.y into color.w and specularColor.w and compute
normal.z by sqrt(1-x*x-y*y). Unfortunately I was not able to observe performance
improvement:

![Bloom](7.png)



-------------------------------------------------------------------------------
NOTE:
-------------------------------------------------------------------------------
Expand Down
5 changes: 5 additions & 0 deletions base/res/cornell/cornell_box.mtl
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ newmtl light
Ka 20 20 20
Kd 1 1 1
Ks 0 0 0

newmtl blue_specular_red
Ka 0 0 0
Kd 0 0 1
Ks 1 0 0
4 changes: 2 additions & 2 deletions base/res/cornell/cornell_box.obj
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,15 @@ v 82.0 0.0 225.0
f -4 -3 -2 -1

o tall_block
usemtl white
usemtl blue_specular_red

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
usemtl blue_specular_red
v 423.0 0.0 247.0
v 423.0 330.0 247.0
v 472.0 330.0 406.0
Expand Down
8 changes: 6 additions & 2 deletions base/res/shaders/pass.frag
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,21 @@

uniform float u_Far;
uniform vec3 u_Color;
uniform vec3 u_SpecularColor;

in vec3 fs_Normal;
in vec4 fs_Position;

out vec4 out_Normal;
out vec4 out_Position;
out vec4 out_Color;
out vec4 out_SpecularColor;

void main(void)
{
out_Normal = vec4(normalize(fs_Normal),0.0f);
vec3 N_unit = normalize(fs_Normal);
out_Normal = vec4(N_unit,0.0f);
out_Position = vec4(fs_Position.xyz,1.0f); //Tuck position into 0 1 range
out_Color = vec4(u_Color,1.0);
out_Color = vec4(u_Color, N_unit.x);
out_SpecularColor = vec4(u_SpecularColor, N_unit.y);
}
44 changes: 42 additions & 2 deletions base/res/shaders/point.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
#define DISPLAY_COLOR 3
#define DISPLAY_TOTAL 4
#define DISPLAY_LIGHTS 5
#define DISPLAY_OUTLINE 6
#define DISPLAY_TOON 7
#define DISPLAY_BLOOM 8


/////////////////////////////////////
Expand All @@ -23,6 +26,7 @@ uniform sampler2D u_Positiontex;
uniform sampler2D u_Colortex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;
uniform sampler2D u_SpecularColortex;

uniform float u_Far;
uniform float u_Near;
Expand Down Expand Up @@ -58,19 +62,30 @@ float linearizeDepth(float exp_depth, float near, float far) {

//Helper function to automatically sample and unpack normals
vec3 sampleNrm(vec2 texcoords) {
return texture(u_Normaltex,texcoords).xyz;
// Original G-buffer.
return texture(u_Normaltex,texcoords).xyz;

// Compact G-buffer.
//float Nx = texture(u_Colortex,texcoords).w;
//float Ny = texture(u_SpecularColortex,texcoords).w;
//return vec3(Nx, Ny, sqrt(1.0 - Nx*Nx - Ny*Ny));
}

//Helper function to automicatlly sample and unpack positions
vec3 samplePos(vec2 texcoords) {
return texture(u_Positiontex,texcoords).xyz;
}

//Helper function to automicatlly sample and unpack positions
//Helper function to automicatlly sample and unpack colors
vec3 sampleCol(vec2 texcoords) {
return texture(u_Colortex,texcoords).xyz;
}

//Helper function to automicatlly sample and unpack specular colors
vec3 sampleSpecCol(vec2 texcoords) {
return texture(u_SpecularColortex,texcoords).xyz;
}

//Get a random normal vector given a screen-space texture coordinate
//Actually accesses a texture of random vectors
vec3 getRandomNormal(vec2 texcoords) {
Expand Down Expand Up @@ -106,10 +121,35 @@ void main() {
if( u_DisplayType == DISPLAY_LIGHTS )
{
//Put some code here to visualize the fragment associated with this point light
out_Color = vec4(1.0, 0.0, 0.0, 1.0);
}
else
{
//Put some code here to actually compute the light from the point light

vec3 N_unit = normalize(normal); // Normal.
vec3 L = light - position; // Fragment to light.
vec3 L_unit = normalize(L);
vec3 E_unit = normalize(-position); // Fragment to eye.
vec3 R_unit = normalize(-reflect(L_unit, N_unit)); // Fragment to reflected light direction.

float lightIntensity = u_LightIl * max(lightRadius-length(L), 0.0) / lightRadius;

// Diffuse term
vec3 diffuseColor = color * max(dot(N_unit, L_unit), 0.0);
diffuseColor = clamp(diffuseColor, 0.0, 1.0);

// Specular term
vec3 specularColor = sampleSpecCol(fs_Texcoord);
{
float specularExponent = 15.0;
float magnitude = max(dot(R_unit, E_unit), 0.0);
specularColor *= pow(magnitude, specularExponent);
}
specularColor = clamp(specularColor, 0.0, 1.0);

out_Color = vec4(lightIntensity * (diffuseColor + specularColor), 1.0);
//out_Color = vec4(clamp(lightIntensity*color*diffuseTerm, 0.0, 1.0), 1.0);
}
return;
}
Expand Down
112 changes: 111 additions & 1 deletion base/res/shaders/post.frag
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@
#define DISPLAY_COLOR 3
#define DISPLAY_TOTAL 4
#define DISPLAY_LIGHTS 5
#define DISPLAY_OUTLINE 6
#define DISPLAY_TOON 7
#define DISPLAY_BLOOM 8


/////////////////////////////////////
// Uniforms, Attributes, and Outputs
////////////////////////////////////
uniform int u_DisplayType;

uniform sampler2D u_Colortex;
uniform sampler2D u_Normaltex;
uniform sampler2D u_Posttex;
uniform sampler2D u_RandomNormaltex;
uniform sampler2D u_RandomScalartex;
Expand Down Expand Up @@ -60,15 +67,118 @@ float getRandomScalar(vec2 texcoords) {
texcoords.t*u_ScreenHeight/sz.y)).r;
}

vec3 multiplyNormal(int x, int y, float n)
{
vec2 xy = fs_Texcoord + vec2(float(x)/u_ScreenWidth, float(y)/u_ScreenHeight);
return texture(u_Normaltex, xy).xyz * n;
}

vec3 convolve3x3(float i11, float i12, float i13, float i21, float i22, float i23,
float i31, float i32, float i33)
{
vec3 v11 = multiplyNormal(-1, 1, i11);
vec3 v12 = multiplyNormal(0, 1, i12);
vec3 v13 = multiplyNormal(1, 1, i13);
vec3 v21 = multiplyNormal(-1, 0, i21);
vec3 v22 = multiplyNormal(0, 0, i22);
vec3 v23 = multiplyNormal(1, 0, i23);
vec3 v31 = multiplyNormal(-1, -1, i31);
vec3 v32 = multiplyNormal(0, -1, i32);
vec3 v33 = multiplyNormal(1, -1, i33);
return v11+v12+v13+v21+v22+v23+v31+v32+v33;
}

float sobel()
{
vec3 gx = convolve3x3(1.0, 0.0, -1.0, 2.0, 0.0, -2.0, 1.0, 0.0, -1.0);
vec3 gy = convolve3x3(1.0, 2.0, 1.0, 0.0, 0.0, 0.0, -1.0, -2.0, -1.0);
float gxGray = (gx.x + gx.y + gx.z) / 3.0;
float gyGray = (gy.x + gy.y + gy.z) / 3.0;
return sqrt(gxGray*gxGray + gyGray*gyGray);
}

vec3 discretize(vec3 value, int numBins)
{
float t = numBins;
return floor(value * t) / t;
}

vec3 multiplyBrightColor(int x, int y, float n)
{
vec2 offset = vec2(float(x)/u_ScreenWidth, float(y)/u_ScreenHeight);
vec3 value = texture(u_Colortex, fs_Texcoord + offset).xyz;
return value * n * float(value.x + value.y + value.z > 2.6);
}

// Gaussian blur is too slow.
/*
uniform float kernel[25] = float[](
1, 4, 7, 4, 1,
4, 16, 26, 16, 4,
7, 26, 41, 26, 7,
4, 16, 26, 16, 4,
1, 4, 7, 4, 1);
*/

vec3 getBlurColor()
{
vec3 color = vec3(0.0);
// Box blur 13x13
for (int i = -6; i < 7; ++i)
{
for (int j = -6; j < 7; ++j)
{
vec2 offset = vec2(float(i)/u_ScreenWidth, float(j)/u_ScreenHeight);
vec3 value = texture(u_Colortex, fs_Texcoord + offset).xyz;
if (value.x + value.y + value.z > 2.6) color += value;
}
}
color /= 169.0;
/*
// Gaussian blur 5x5
for (int i = -2; i < 3; ++i)
{
for (int j = -2; j < 3; ++j)
{
int idx = (i+2)*5 + (j+2);
color += multiplyBrightColor(i, j, kernel[idx] / 273.0);
}
}
*/
return color;
}

///////////////////////////////////
// MAIN
//////////////////////////////////
const float occlusion_strength = 1.5f;
void main() {
vec3 color = sampleCol(fs_Texcoord);
float gray = dot(color, vec3(0.2125, 0.7154, 0.0721));
vec3 outlineColor = vec3(sobel() < 0.1);
vec3 discretizedColor = discretize(color, 10);

if (u_DisplayType == DISPLAY_OUTLINE)
{
out_Color = vec4(outlineColor, 1.0);
return;
}

if (u_DisplayType == DISPLAY_TOON)
{
out_Color = vec4(outlineColor * discretizedColor, 1.0);
return;
}

if (u_DisplayType == DISPLAY_BLOOM)
{
out_Color = vec4(color + getBlurColor() * 0.7, 1.0);
return;
}

float gray = dot(color, vec3(0.2125, 0.7154, 0.0721));
float vin = min(2*distance(vec2(0.5), fs_Texcoord), 1.0);
out_Color = vec4(mix(pow(color,vec3(1.0/1.8)),vec3(gray),vin), 1.0);

return;
}

Loading