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

Submission: Megan Moore #10

Open
wants to merge 27 commits into
base: master
Choose a base branch
from
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
424 changes: 44 additions & 380 deletions README.md

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions 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_material;

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.
gl_FragData[0] = vec4(v_position, 1.0);
vec4 gnorm = vec4(normalize(v_normal), 0.0);
gl_FragData[2] = texture2D(u_colmap, v_uv);
vec4 norm = texture2D(u_normap, v_uv);
gl_FragData[1].xyz = applyNormalMap(vec3(gnorm), vec3(norm));
gl_FragData[1].w = u_material;
}
10 changes: 7 additions & 3 deletions glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,29 @@
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;
float amb = .2;
// TODO: Extract needed properties from the g-buffers into local variables
vec3 pos = gb0.xyz;
vec3 colmap = gb2.xyz;

vec3 nor = gb1.xyz;
if (depth == 1.0) {
gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0
return;
}

gl_FragColor = vec4(0.1, 0.1, 0.1, 1); // TODO: replace this
gl_FragColor = vec4(amb * colmap, 1); // TODO: replace this
}
76 changes: 62 additions & 14 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,86 @@
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 sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;
uniform vec3 u_cameraPos;
uniform float u_toon;
//uniform float u_width;
//uniform float u_height;

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
vec3 pos = gb0.xyz;

vec3 colmap = gb2.xyz;
float spec = gb1.w;


vec3 normal = normalize(gb1.xyz);
vec3 lightDir = normalize((u_lightPos - pos)); // / length(u_lightPos - pos);

// 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);
if (length(u_lightPos - pos) > u_lightRad) {
gl_FragColor = vec4(0, 0, 0, 1.0);
return;
}
float lambertian = min(max(dot(lightDir,normal), 0.0), 1.0);
float specular = 0.0;

vec3 viewDir = normalize(u_cameraPos - pos);
vec3 halfDir = normalize(lightDir + viewDir);
float specAngle = max(dot(halfDir, normal), 0.0);


specular = pow(specAngle, spec);


vec3 color = lambertian * colmap * u_lightCol * (u_lightRad - length(u_lightPos - pos)) + specular*vec3(1.0);

if (u_toon > 0.5) {
//diffuse values
if (lambertian < 0.5) {
lambertian = .2;
}
else {
lambertian = 1.0;
}

//specular highlight
if (specAngle > .75) {
specular = pow(1.0, spec);
}
else {
specular = 0.0;
}

//fade from center of light
float fade;
if (u_lightRad - length(u_lightPos - pos) < .5) fade = .25;
else fade = .75;

//check silhouette

color = lambertian * colmap * u_lightCol * fade + specular*vec3(1.0);
}

gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations


gl_FragColor = vec4(color, 1.0);

}
38 changes: 19 additions & 19 deletions glsl/deferred/debug.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 3

uniform int u_debug;
uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;

uniform mat4 u_prevPM;
varying vec2 v_uv;
uniform vec3 u_cameraPos;

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
vec3 pos;
vec3 geomnor;
vec3 colmap;
vec3 normap;
vec3 nor;
vec3 pos = gb0.xyz;

vec3 colmap = gb2.xyz;

vec3 nor = gb1.xyz;


vec4 H = vec4(v_uv.x*2.0 - 1.0, (v_uv.y) * 2.0 - 1.0, depth, 1.0);
vec4 currentPos = H;
vec4 prevPos = u_prevPM * vec4(pos / gb0.w, 1.0);
prevPos /= prevPos.w;

vec2 velocity = ((currentPos.xy) - prevPos.xy) / 2.0;

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);
gl_FragColor = vec4(abs(velocity), 0.0, 1.0);
} else {
gl_FragColor = vec4(1, 0, 1, 1);
}
Expand Down
23 changes: 23 additions & 0 deletions glsl/post/blend.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#version 100
precision highp float;
precision highp int;


varying vec2 v_uv;

uniform sampler2D scene;
uniform sampler2D bloomBlur;
uniform float exposure;

void main()
{
const float gamma = 2.2;
vec3 hdrColor = texture(scene, v_uv).rgb;
vec3 bloomColor = texture(bloomBlur, v_uv).rgb;
hdrColor += bloomColor; // additive blending
// tone mapping
vec3 result = vec3(1.0) - exp(-hdrColor * exposure);
// also gamma correct while we're at it
result = pow(result, vec3(1.0 / gamma));
gl_FragColor = vec4(result, 1.0f);
}
64 changes: 64 additions & 0 deletions glsl/post/bloom.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_color;
uniform float u_bloom;
varying vec2 v_uv;

uniform vec2 u_resolution;
uniform vec2 u_dir;

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) {
gl_FragColor = SKY_COLOR;
return;
}


vec4 sum = vec4(0.0);

//the amount to blur, i.e. how far off center to sample from
//1.0 -> blur by one pixel
//2.0 -> blur by two pixels, etc.
float blur = 4.0/u_resolution.x;

//the direction of our blur
//(1.0, 0.0) -> x-axis blur
//(0.0, 1.0) -> y-axis blur
float hstep = u_dir.x;
float vstep = u_dir.y;



//apply blurring, using a 9-tap filter with predefined gaussian weights

sum += texture2D(u_color, vec2(v_uv.x - 4.0*blur*hstep, v_uv.y - 4.0*blur*vstep)) * 0.0162162162;
sum += texture2D(u_color, vec2(v_uv.x - 3.0*blur*hstep, v_uv.y - 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_color, vec2(v_uv.x - 2.0*blur*hstep, v_uv.y - 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_color, vec2(v_uv.x - 1.0*blur*hstep, v_uv.y - 1.0*blur*vstep)) * 0.1945945946;

sum += texture2D(u_color, vec2(v_uv.x, v_uv.y)) * 0.2270270270;

sum += texture2D(u_color, vec2(v_uv.x + 1.0*blur*hstep, v_uv.y + 1.0*blur*vstep)) * 0.1945945946;
sum += texture2D(u_color, vec2(v_uv.x + 2.0*blur*hstep, v_uv.y + 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_color, vec2(v_uv.x + 3.0*blur*hstep, v_uv.y + 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_color, vec2(v_uv.x + 4.0*blur*hstep, v_uv.y + 4.0*blur*vstep)) * 0.0162162162;

//discard alpha for our simple demo, multiply by vertex color and return
gl_FragColor = color + color * sum;



}







63 changes: 63 additions & 0 deletions glsl/post/bloom1.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#version 100
precision highp float;
precision highp int;

uniform sampler2D u_color;
uniform float u_bloom;
varying vec2 v_uv;

uniform vec2 u_resolution;
uniform vec2 u_dir;

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) {
gl_FragColor = SKY_COLOR;
return;
}


vec4 sum = vec4(0.0);

//the amount to blur, i.e. how far off center to sample from
//1.0 -> blur by one pixel
//2.0 -> blur by two pixels, etc.
float blur = 4.0/u_resolution.x;

//the direction of our blur
//(1.0, 0.0) -> x-axis blur
//(0.0, 1.0) -> y-axis blur
float hstep = u_dir.x;
float vstep = u_dir.y;

//apply blurring, using a 9-tap filter with predefined gaussian weights

sum += texture2D(u_color, vec2(v_uv.x - 4.0*blur*hstep, v_uv.y - 4.0*blur*vstep)) * 0.0162162162;
sum += texture2D(u_color, vec2(v_uv.x - 3.0*blur*hstep, v_uv.y - 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_color, vec2(v_uv.x - 2.0*blur*hstep, v_uv.y - 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_color, vec2(v_uv.x - 1.0*blur*hstep, v_uv.y - 1.0*blur*vstep)) * 0.1945945946;

sum += texture2D(u_color, vec2(v_uv.x, v_uv.y)) * 0.2270270270;

sum += texture2D(u_color, vec2(v_uv.x + 1.0*blur*hstep, v_uv.y + 1.0*blur*vstep)) * 0.1945945946;
sum += texture2D(u_color, vec2(v_uv.x + 2.0*blur*hstep, v_uv.y + 2.0*blur*vstep)) * 0.1216216216;
sum += texture2D(u_color, vec2(v_uv.x + 3.0*blur*hstep, v_uv.y + 3.0*blur*vstep)) * 0.0540540541;
sum += texture2D(u_color, vec2(v_uv.x + 4.0*blur*hstep, v_uv.y + 4.0*blur*vstep)) * 0.0162162162;

//discard alpha for our simple demo, multiply by vertex color and return
gl_FragColor = color * vec4(sum.rgb, 1.0);




}







Loading