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

Submission: Bradley Crusco #2

Open
wants to merge 63 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
70c7de3
Basic features implemented.
bcrusco Oct 24, 2015
5b403da
Bloom lighting.
bcrusco Oct 24, 2015
b39a733
Renaming to better indicate specific use for bloom.
bcrusco Oct 25, 2015
b2d326b
Toon shading and improved AABB for scissoring test.
bcrusco Oct 25, 2015
b445678
Merge remote-tracking branch 'upstream/master'
bcrusco Oct 25, 2015
1bd1587
Sort of working specular exponent implementation. Some issues with lo…
bcrusco Oct 25, 2015
0658c9d
Update README.md
bcrusco Oct 25, 2015
5785e9d
Update README.md
bcrusco Oct 25, 2015
b6566aa
Update README.md
bcrusco Oct 25, 2015
20ad928
Data images.
bcrusco Oct 25, 2015
684cbe2
Update README.md
bcrusco Oct 25, 2015
d63bd24
Fixed toon chart format.
bcrusco Oct 25, 2015
96db5ad
Merge branch 'master' of https://github.com/bcrusco/Project6-WebGL-De…
bcrusco Oct 25, 2015
2ab82b1
Update README.md
bcrusco Oct 25, 2015
50e7761
Update README.md
bcrusco Oct 25, 2015
7b02f70
Update README.md
bcrusco Oct 25, 2015
27f9967
Effect images
bcrusco Oct 25, 2015
a57d7b4
Update README.md
bcrusco Oct 25, 2015
a6658d4
Update README.md
bcrusco Oct 25, 2015
96dc856
Update README.md
bcrusco Oct 25, 2015
7f777fe
Update README.md
bcrusco Oct 25, 2015
d2ba8e0
Reduce gbuffer count from 4 to 3 by applying the normal map in the co…
bcrusco Oct 25, 2015
7c2ef6a
Update README.md
bcrusco Oct 25, 2015
4c8b13b
Scissor test images.
bcrusco Oct 25, 2015
7288ff8
Merge branch 'master' of https://github.com/bcrusco/Project6-WebGL-De…
bcrusco Oct 25, 2015
bafe272
Update README.md
bcrusco Oct 25, 2015
35e9969
Update README.md
bcrusco Oct 25, 2015
39083aa
Update README.md
bcrusco Oct 25, 2015
7792ea6
Update README.md
bcrusco Oct 25, 2015
2a72250
Update README.md
bcrusco Oct 25, 2015
7102418
Update README.md
bcrusco Oct 25, 2015
1e7823e
Scissor test analysis
bcrusco Oct 25, 2015
cea0713
Update README.md
bcrusco Oct 25, 2015
193f61a
Update README.md
bcrusco Oct 25, 2015
6363059
Update README.md
bcrusco Oct 25, 2015
329e19d
Update README.md
bcrusco Oct 26, 2015
96533c8
Update README.md
bcrusco Oct 26, 2015
eb522a1
Update README.md
bcrusco Oct 26, 2015
c3d60c5
Update README.md
bcrusco Oct 26, 2015
bd095eb
Update README.md
bcrusco Oct 26, 2015
03c266b
Update README.md
bcrusco Oct 26, 2015
947dca9
A previous commit fixed not being able to use the additional model, b…
bcrusco Oct 26, 2015
81a5668
Merge remote-tracking branch 'upstream/master'
bcrusco Oct 26, 2015
20e88d7
Update README.md
bcrusco Oct 26, 2015
5c7d11f
Update README.md
bcrusco Oct 26, 2015
d6e23e7
Update README.md
bcrusco Oct 26, 2015
b424c4d
Update README.md
bcrusco Oct 26, 2015
c87fe2c
Update README.md
bcrusco Oct 26, 2015
af3c066
Update README.md
bcrusco Oct 26, 2015
808eb06
Fake youtube thumbnail image.
bcrusco Oct 26, 2015
c460988
Update README.md
bcrusco Oct 26, 2015
863ca5c
Update README.md
bcrusco Oct 26, 2015
398fc71
Minor shader tweaks.
bcrusco Oct 26, 2015
a42311f
Some code clean up and make it so that only one effect can be activat…
bcrusco Oct 26, 2015
a1401ca
Removed unused UI code. FIxes and tuning for toon.
bcrusco Oct 26, 2015
331696f
Debug images.
bcrusco Oct 26, 2015
a076118
Update README.md
bcrusco Oct 26, 2015
9f2b236
Update README.md
bcrusco Oct 26, 2015
bb6d9ec
Update README.md
bcrusco Oct 26, 2015
cc49689
Update README.md
bcrusco Oct 26, 2015
0822372
Update README.md
bcrusco Oct 26, 2015
397df71
Update README.md
bcrusco Nov 11, 2015
7300a5c
Update README.md
bcrusco Nov 11, 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
458 changes: 54 additions & 404 deletions README.md

Large diffs are not rendered by default.

Binary file added charts/Bloom Analysis.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 charts/Scissor Analysis.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 charts/Toon Analysis.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion glsl/clear.frag.glsl
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#version 100
#extension GL_EXT_draw_buffers: enable

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
19 changes: 18 additions & 1 deletion glsl/copy.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,28 @@ precision highp int;

uniform sampler2D u_colmap;
uniform sampler2D u_normap;
uniform float u_specular_exp;

varying vec3 v_position;
varying vec3 v_normal;
varying vec2 v_uv;

vec3 applyNormalMap(vec3 geomnor, vec3 normap) {
normap = normap * 2.0 - 1.0;
vec3 up = normalize(vec3(0.001, 1, 0.001));
vec3 surftan = normalize(cross(geomnor, up));
vec3 surfbinor = cross(geomnor, surftan);

return normap.y * surftan + normap.x * surfbinor + normap.z * geomnor;
}

void main() {
// TODO: copy values into gl_FragData[0], [1], etc.
// Model view position
gl_FragData[0] = vec4(v_position, 1.0);

// Normal
gl_FragData[1] = vec4(applyNormalMap(v_normal, texture2D(u_normap, v_uv).rgb), u_specular_exp); // Pack specular exponent in the alpha channel

// Color map
gl_FragData[2] = texture2D(u_colmap, v_uv);
}
11 changes: 4 additions & 7 deletions glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,22 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;

varying vec2 v_uv;

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
vec3 color_map = gb2.xyz;

if (depth == 1.0) {
gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0
gl_FragColor = vec4(0.0);
return;
}

gl_FragColor = vec4(0.1, 0.1, 0.1, 1); // TODO: replace this
gl_FragColor = vec4(0.2 * color_map, 1.0);
}
48 changes: 35 additions & 13 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,60 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform vec3 u_lightCol;
uniform vec3 u_lightPos;
uniform float u_lightRad;
uniform vec3 u_cameraPos;
uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;
uniform int u_toon;

varying vec2 v_uv;

vec3 applyNormalMap(vec3 geomnor, vec3 normap) {
normap = normap * 2.0 - 1.0;
vec3 up = normalize(vec3(0.001, 1, 0.001));
vec3 surftan = normalize(cross(geomnor, up));
vec3 surfbinor = cross(geomnor, surftan);
return normap.y * surftan + normap.x * surfbinor + normap.z * geomnor;
}

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
int toon = u_toon;

//Extract needed properties from the g-buffers into local variables
vec3 position = gb0.xyz;
vec3 normal = normalize(gb1.xyz);
vec3 color_map = gb2.xyz;
float specular_exp = gb1.w;

// 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);
return;
}

gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations
vec3 light_difference = u_lightPos - position;
vec3 light_direction = normalize(light_difference);
vec3 camera_direction = normalize(u_cameraPos - position);
float light_distance = length(light_difference);
vec3 half_way = normalize(light_direction + camera_direction);

if (light_distance > u_lightRad){
gl_FragColor = vec4(0.0);
return;
}

float falloff = 1.0 / pow(light_distance, 2.0);
float diffuse = max(0.0, dot(normal, light_direction));
float specular = pow(max(0.0, dot(normal, half_way)), specular_exp);

// Toon ramp shading
if(toon == 1) {
float steps = 5.0;
diffuse = ceil(diffuse * steps) / steps;
specular = ceil(specular * steps) / steps;
falloff = ceil(falloff * steps) / steps;
}

gl_FragColor = falloff * vec4(u_lightCol * diffuse * specular * color_map * max(0.0, u_lightRad - light_distance), 1.0);
}
31 changes: 8 additions & 23 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 @@ -12,41 +12,26 @@ varying vec2 v_uv;

const vec4 SKY_COLOR = vec4(0.66, 0.73, 1.0, 1.0);

vec3 applyNormalMap(vec3 geomnor, vec3 normap) {
normap = normap * 2.0 - 1.0;
vec3 up = normalize(vec3(0.001, 1, 0.001));
vec3 surftan = normalize(cross(geomnor, up));
vec3 surfbinor = cross(geomnor, surftan);
return normap.y * surftan + normap.x * surfbinor + normap.z * geomnor;
}

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)

// Extract needed properties from the g-buffers into local variables
vec3 pos = gb0.xyz; // World-space position
vec3 nor = normalize(gb1.xyz); // Precomputed surface normals
vec3 colmap = gb2.xyz; // The color map - unlit "albedo" (surface color)

if (u_debug == 0) {
gl_FragColor = vec4(vec3(depth), 1.0);
} else if (u_debug == 1) {
gl_FragColor = vec4(abs(pos) * 0.1, 1.0);
} else if (u_debug == 2) {
gl_FragColor = vec4(abs(geomnor), 1.0);
gl_FragColor = vec4(abs(nor), 1.0);
} else if (u_debug == 3) {
gl_FragColor = vec4(colmap, 1.0);
} else if (u_debug == 4) {
gl_FragColor = vec4(normap, 1.0);
} else if (u_debug == 5) {
gl_FragColor = vec4(abs(nor), 1.0);
} else {
gl_FragColor = vec4(1, 0, 1, 1);
gl_FragColor = vec4(1.0, 0, 1.0, 1.0);
}
}
33 changes: 33 additions & 0 deletions glsl/post/bloom.one.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_color;
uniform vec2 u_screen_inv;

varying vec2 v_uv;

const vec4 SKY_COLOR = vec4(0.01, 0.14, 0.42, 1.0);
const vec3 gauss = vec3(0.4, 0.25, 0.05);

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

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

vec4 left0_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y));
left0_color *= left0_color.a;
vec4 left1_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x * 2.0, v_uv.y));
left1_color *= left1_color.a;
vec4 right0_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y));
right0_color *= right0_color.a;
vec4 right1_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x * 2.0, v_uv.y));
right1_color *= right1_color.a;

color *= color.a;

gl_FragColor = left1_color * gauss.z + left0_color * gauss.y + color * gauss.x
+ right0_color * gauss.y + right1_color * gauss.z;
}
29 changes: 29 additions & 0 deletions glsl/post/bloom.two.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_orig_color;
uniform sampler2D u_color;
uniform vec2 u_screen_inv;

varying vec2 v_uv;

const vec4 SKY_COLOR = vec4(0.01, 0.14, 0.42, 1.0);
const vec3 gauss = vec3(0.4, 0.25, 0.05);

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

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

vec4 top0_color = texture2D(u_color, vec2(v_uv.x, v_uv.y - u_screen_inv.y));
vec4 top1_color = texture2D(u_color, vec2(v_uv.x, v_uv.y - u_screen_inv.y * 2.0));
vec4 bottom0_color = texture2D(u_color, vec2(v_uv.x, v_uv.y + u_screen_inv.y));
vec4 bottom1_color = texture2D(u_color, vec2(v_uv.x, v_uv.y + u_screen_inv.y * 2.0));

gl_FragColor = 0.65 * (orig_color + top1_color * gauss.z + top0_color * gauss.y + color * gauss.x
+ bottom0_color * gauss.y + bottom1_color * gauss.z);
}
27 changes: 27 additions & 0 deletions glsl/post/toon.one.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_color;
uniform vec2 u_screen_inv;

varying vec2 v_uv;

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

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

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

vec4 left_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y));
vec4 top_left_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y - u_screen_inv.y));
vec4 bottom_left_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y + u_screen_inv.y));
vec4 right_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y));
vec4 top_right_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y - u_screen_inv.y));
vec4 bottom_right_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y + u_screen_inv.y));

gl_FragColor = -left_color - top_left_color - bottom_left_color + right_color + top_right_color + bottom_right_color;
}
39 changes: 39 additions & 0 deletions glsl/post/toon.two.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_orig_color;
uniform sampler2D u_color;
uniform vec2 u_screen_inv;

varying vec2 v_uv;

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

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

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

vec4 top_color = texture2D(u_color, vec2(v_uv.x, v_uv.y - u_screen_inv.y));
vec4 top_left_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y - u_screen_inv.y));
vec4 top_right_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y - u_screen_inv.y));
vec4 bottom_color = texture2D(u_color, vec2(v_uv.x, v_uv.y + u_screen_inv.y));
vec4 bottom_left_color = texture2D(u_color, vec2(v_uv.x - u_screen_inv.x, v_uv.y + u_screen_inv.y));
vec4 bottom_right_color = texture2D(u_color, vec2(v_uv.x + u_screen_inv.x, v_uv.y + u_screen_inv.y));

// Blend and perform edge ramping
vec4 blend = -top_color - top_left_color - top_right_color + bottom_color + bottom_left_color + bottom_right_color;
blend = vec4(vec3(max(max(blend.x, blend.y), blend.z)), 1.0);
if(blend.x <= 0.2) {
blend = vec4(0.0, 0.0, 0.0, 1.0);
}
else {
blend = vec4(1.0);
}

gl_FragColor = (1.0 - blend) * orig_color;
}
File renamed without changes.
2 changes: 1 addition & 1 deletion 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(0.05, 0.05, 0.05, 1.0);
}
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/Fake Youtube.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/No Effect.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 added img/Toon.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 map.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/cow.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/default 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/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/improved 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/position.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading