Skip to content
This repository was archived by the owner on Apr 26, 2023. It is now read-only.

Submission: Levi Cai #4

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
943f715
GOt the red square to render
arizonat Oct 22, 2015
334e7fc
Merged
arizonat Oct 22, 2015
ea46d96
the first thing workksss
arizonat Oct 23, 2015
2e1219e
Merged
arizonat Oct 23, 2015
5c01b08
Working and toggleable toon shading, just need scissor test now
arizonat Oct 24, 2015
7d2fe79
Merge remote-tracking branch 'upstream/master'
arizonat Oct 24, 2015
6fa5e11
Merge remote-tracking branch 'upstream/master'
arizonat Oct 25, 2015
7287999
Scissor test implemented
arizonat Oct 25, 2015
2ddd696
Bloom effect implemented
arizonat Oct 26, 2015
f37ca14
Initial 2nd pass
arizonat Oct 27, 2015
db0de40
Initial start
arizonat Oct 27, 2015
851c7b5
finished post2
arizonat Oct 27, 2015
c459f47
Merged and fixed naming
arizonat Oct 27, 2015
3ea6b00
SOme crazy spheres...
arizonat Oct 27, 2015
85af9b3
Added some photos and fixed race condition
arizonat Oct 27, 2015
bb993e9
Added setting for scissor test
arizonat Oct 27, 2015
d6c7f3d
Added more images, removed a g_buffer
arizonat Oct 27, 2015
b1f8343
Merge remote-tracking branch 'upstream/master'
arizonat Oct 27, 2015
ec96ee0
Merging with master
arizonat Oct 27, 2015
8dad80e
Fixed some merging issues from before
arizonat Oct 27, 2015
ecae8e4
I think everything is done
arizonat Oct 28, 2015
935cc1d
Update README.md
arizonat Oct 28, 2015
2ba4acc
Update README.md
arizonat Oct 28, 2015
57a765f
Update README.md
arizonat Oct 28, 2015
2001823
Added debug sphere image
arizonat Oct 28, 2015
d4deb7c
Update README.md
arizonat Oct 28, 2015
2e623b8
Update README.md
arizonat Oct 28, 2015
fd97fb9
Update README.md
arizonat Oct 28, 2015
9c7166f
Update README.md
arizonat Oct 28, 2015
12ae00f
Update README.md
arizonat Oct 28, 2015
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
439 changes: 40 additions & 399 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion glsl/clear.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

void main() {
for (int i = 0; i < NUM_GBUFFERS; i++) {
Expand Down
8 changes: 7 additions & 1 deletion glsl/copy.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_uv;

#define NUM_GBUFFERS 3

void main() {
// TODO: copy values into gl_FragData[0], [1], etc.
vec3 normap = texture2D(u_normap, v_uv).xyz;
vec3 colmap = texture2D(u_colmap, v_uv).xyz;
gl_FragData[0] = vec4(v_position, colmap.x);
gl_FragData[1] = vec4(v_normal, colmap.y);
gl_FragData[2] = vec4(normap, colmap.z);
}
3 changes: 1 addition & 2 deletions glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;
Expand All @@ -14,7 +14,6 @@ void main() {
vec4 gb0 = texture2D(u_gbufs[0], v_uv);
vec4 gb1 = texture2D(u_gbufs[1], v_uv);
vec4 gb2 = texture2D(u_gbufs[2], v_uv);
vec4 gb3 = texture2D(u_gbufs[3], v_uv);
float depth = texture2D(u_depth, v_uv).x;
// TODO: Extract needed properties from the g-buffers into local variables

Expand Down
81 changes: 76 additions & 5 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,17 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform vec4 u_settings;

uniform vec3 u_cameraPos;
uniform vec3 u_lightCol;
uniform vec3 u_lightPos;

uniform float u_camera_width;
uniform float u_camera_height;

uniform float u_lightRad;
uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;
Expand All @@ -21,19 +28,83 @@ vec3 applyNormalMap(vec3 geomnor, vec3 normap) {
}

void main() {
/*
vec4 gb0 = texture2D(u_gbufs[0], v_uv);
vec4 gb1 = texture2D(u_gbufs[1], v_uv);
vec4 gb2 = texture2D(u_gbufs[2], v_uv);
vec4 gb3 = texture2D(u_gbufs[3], v_uv);
float depth = texture2D(u_depth, v_uv).x;
// TODO: Extract needed properties from the g-buffers into local variables
*/

vec2 guv = gl_FragCoord.xy / vec2(u_camera_width, u_camera_height);

vec4 gb0 = texture2D(u_gbufs[0], guv);
vec4 gb1 = texture2D(u_gbufs[1], guv);
vec4 gb2 = texture2D(u_gbufs[2], guv);
float depth = texture2D(u_depth, guv).x;

vec3 pos = gb0.xyz; // World-space position
vec3 geomnor = gb1.xyz; // Normals of the geometry as defined, without normal mapping
vec3 color = vec3(gb0.w,gb1.w,gb2.w); // The color map - unlit "albedo" (surface color)
vec3 normap = gb2.xyz; // The raw normal map (normals relative to the surface they're on)
vec3 nor = applyNormalMap(geomnor, normap); // The true normals as we want to light them - with the normal map applied to the geometry normals (applyNormalMap above)

float toonShading = u_settings[0];
float rampShading = u_settings[1];

// If nothing was rendered to this pixel, set alpha to 0 so that the
// postprocessing step can render the sky color.
if (depth == 1.0) {
gl_FragColor = vec4(0, 0, 0, 0);
gl_FragColor = vec4(0, 0, 0, 1);
return;
}

gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations
if (toonShading == 1.0){
float thresh = 0.005;
float neighbor;

for (int i = -1; i <= 1; i++){
for (int j = -1; j <= 1; j++){
if (i == 0 && j == 0) continue;
neighbor = texture2D(u_depth, guv + vec2(float(i)/u_camera_width, float(j)/u_camera_height)).x;

if (abs(depth - neighbor) > thresh){
gl_FragColor = vec4(1.0);
return;
}
}
}
}

float dist = length(u_lightPos - pos);

// Diffuse
vec3 lightDir = normalize(u_lightPos - pos);
float diffuse = dot(nor, lightDir);

// Specular
vec3 cameraDir = normalize(u_cameraPos - pos);
vec3 halfVector = normalize(lightDir + cameraDir);
float specular = dot(nor, halfVector);

vec3 fragColor = color.rgb * u_lightCol;

// Toon shading
if (toonShading == 1.0){
if (diffuse > 0.6){
fragColor *= 0.6;
} else if (diffuse > 0.3) {
fragColor *= 0.3;
} else {
//fragColor *= 0.1;
fragColor *= (1.0-rampShading)*0.1 + (rampShading)*diffuse;
}
fragColor *= max(0.0,(u_lightRad - dist)) * 0.3;

// Normal shading
} else {
fragColor *= diffuse * max(0.0,(u_lightRad - dist)) * 0.3;
fragColor += color.rgb * specular * max(0.0,(u_lightRad - dist)) * 0.3;
}

gl_FragColor = vec4(fragColor, 1.0);
}
16 changes: 7 additions & 9 deletions glsl/deferred/debug.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform int u_debug;
uniform sampler2D u_gbufs[NUM_GBUFFERS];
Expand All @@ -24,15 +24,13 @@ void main() {
vec4 gb0 = texture2D(u_gbufs[0], v_uv);
vec4 gb1 = texture2D(u_gbufs[1], v_uv);
vec4 gb2 = texture2D(u_gbufs[2], v_uv);
vec4 gb3 = texture2D(u_gbufs[3], v_uv);
float depth = texture2D(u_depth, v_uv).x;
// TODO: Extract needed properties from the g-buffers into local variables
// These definitions are suggested for starting out, but you will probably want to change them.
vec3 pos; // World-space position
vec3 geomnor; // Normals of the geometry as defined, without normal mapping
vec3 colmap; // The color map - unlit "albedo" (surface color)
vec3 normap; // The raw normal map (normals relative to the surface they're on)
vec3 nor; // The true normals as we want to light them - with the normal map applied to the geometry normals (applyNormalMap above)

vec3 pos = gb0.xyz; // World-space position
vec3 geomnor = gb1.xyz; // Normals of the geometry as defined, without normal mapping
vec3 colmap = vec3(gb0.w,gb1.w,gb2.w); // The color map - unlit "albedo" (surface color)
vec3 normap = gb2.xyz; // The raw normal map (normals relative to the surface they're on)
vec3 nor = applyNormalMap(geomnor, normap); // The true normals as we want to light them - with the normal map applied to the geometry normals (applyNormalMap above)

if (u_debug == 0) {
gl_FragColor = vec4(vec3(depth), 1.0);
Expand Down
39 changes: 37 additions & 2 deletions glsl/post/one.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,48 @@ varying vec2 v_uv;

const vec4 SKY_COLOR = vec4(0.01, 0.14, 0.42, 1.0);

uniform float u_width;
uniform float u_height;
uniform vec4 u_settings;

uniform float u_block_kernel[25];
uniform float u_kernel[5];

void main() {
vec4 color = texture2D(u_color, v_uv);
vec2 guv = gl_FragCoord.xy / vec2(u_width,u_height);
vec4 color = texture2D(u_color, guv);

if (color.a == 0.0) {
gl_FragColor = SKY_COLOR;
return;
}

gl_FragColor = color;
// Naive 1-pass bloom filter
if (u_settings.x == 1.0){
vec2 n_uv;
vec4 n_color;
float k;

for (int i=-2; i <= 2; i++){
for (int j=-2; j <= 2; j++){
n_uv = guv + vec2(float(i)/800.0, float(j)/600.0);
n_color = texture2D(u_color, n_uv);
k = u_block_kernel[(i+2)+(j+2)*5];
color += k*n_color;
}
}

// 2-pass separable filter (vertical first)
} else if (u_settings.y == 1.0) {
vec2 n_uv;
vec4 n_color;

for (int i=-2; i <= 2; i++){
n_uv = guv + vec2(0.0, float(i)/600.0);
n_color = texture2D(u_color, n_uv);
color += u_kernel[i+2]*n_color;
}
}

gl_FragColor = clamp(color, 0.0, 1.0);
}
35 changes: 35 additions & 0 deletions glsl/post/two.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_color;

varying vec2 v_uv;

const vec4 SKY_COLOR = vec4(0.01, 0.14, 0.42, 1.0);

uniform float u_width;
uniform float u_height;
uniform vec4 u_settings;

uniform float u_kernel[5];

void main() {
vec4 color = texture2D(u_color, v_uv);

// Separable filter
if (u_settings[1] == 1.0){
vec2 n_uv;
vec4 n_color;

for (int i=-2; i <= 2; i++){
n_uv = v_uv + vec2(float(i)/800.0, 0.0);
n_color = texture2D(u_color, n_uv);
color.r += u_kernel[i+2]*n_color.r;
color.g += u_kernel[i+2]*n_color.g;
color.b += u_kernel[i+2]*n_color.b;
}
}

gl_FragColor = clamp(color, 0.0, 1.0);
}
4 changes: 2 additions & 2 deletions glsl/red.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ precision highp float;
precision highp int;

void main() {
gl_FragColor = vec4(1, 0, 0, 1);
}
gl_FragColor = vec4(1.0, 0.0, 0.0, 0.1);
}
22 changes: 22 additions & 0 deletions glsl/sphere.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#version 100
precision highp float;
precision highp int;

attribute vec3 a_position;

uniform mat4 u_cameraMat;
uniform vec4 u_lightTrans; // [pos, radius]

varying vec2 v_uv;

void main() {

float scale = u_lightTrans.w;
vec3 translation = u_lightTrans.xyz;

vec4 position = vec4( (a_position * scale) + translation, 1.0);

gl_Position = u_cameraMat * position; // gl_Position should be in NDC coordinates

v_uv = gl_Position.xy * 0.5 + 0.5;
}
Binary file added img/all.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 img/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 img/bloom_post2.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 img/chrome_profiler.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 img/color.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 img/debug_scissor.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 img/debug_spheres.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 img/depth.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 img/fps_lights.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 img/fps_scissor_fragments.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 img/fps_scissor_lights.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 img/geometry.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 img/initial_spheres.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 img/position.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 img/surface_normal.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 modified img/thumb.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 img/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.
Binary file added img/toon_shading_ramp.PNG
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading