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

Submission: Sanchit Garg #11

Open
wants to merge 20 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
441 changes: 29 additions & 412 deletions README.md

Large diffs are not rendered by default.

Binary file added analysis/ImpactOfNumLight.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 analysis/analysisTable.numbers
Binary file not shown.
Binary file added analysis/scissorTest.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 23 additions & 1 deletion glsl/copy.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ 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);
gl_FragData[1] = vec4(normalize(v_normal), 0.0);
gl_FragData[2] = texture2D(u_colmap, v_uv);
gl_FragData[3] = texture2D(u_normap, v_uv);

/*
gl_FragData[0] = vec4(v_position, 1.0);

vec3 geomnor = normalize(gb1.xyz);
vec3 normap = texture2D(u_normap, v_uv);
gl_FragData[1] = applyNormalMap(geomnor, normap);

gl_FragData[2] = texture2D(u_colmap, v_uv);
*/
}
4 changes: 3 additions & 1 deletion glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,14 @@ void main() {
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 colmap = gb2.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(0.15 * colmap, 1.0);
}
66 changes: 61 additions & 5 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,16 @@ precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define WIDTH 600
#define HEIGHT 800

uniform vec3 u_lightCol;
uniform vec3 u_lightPos;
uniform float u_lightRad;
uniform vec3 u_camPos;

uniform float u_mode;

uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;

Expand All @@ -26,14 +32,64 @@ void main() {
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

// If nothing was rendered to this pixel, set alpha to 0 so that the
// postprocessing step can render the sky color.

vec3 pos = gb0.xyz;
vec3 geomnor = normalize(gb1.xyz);
vec3 colmap = gb2.xyz;
vec3 normap = gb3.xyz;
vec3 nor = applyNormalMap(geomnor, normap);

if (depth == 1.0) {
gl_FragColor = vec4(0, 0, 0, 0);
return;
}

vec3 lightVector = u_lightPos - pos;
float attenuation = max (0.0, u_lightRad- length(lightVector));
//float attenuation = clamp (0.0, u_lightRad - length(lightVector));

lightVector = normalize(lightVector);
vec3 lightReflectVector = reflect(-lightVector, nor);
vec3 camVector = normalize(u_camPos - pos);

if(u_mode == 1.0 && (dot(nor, camVector) < 0.1 && dot(nor, camVector) > -0.1))
{
//Make silhouettes pop
gl_FragColor = vec4(vec3(0.0), 1.0);
return;
}

gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations
vec3 H = normalize(lightVector + camVector);

//Assuming Kspec = 0.01 and shininess = 0.01
float spec = 0.001 * pow(clamp(dot(nor, H), 0.0, 1.0), 0.01);
float diff = max(0.0,dot(nor, lightVector));

if(u_mode == 1.0)
{
//toon shading

if(diff > 0.6)
diff = 1.0;
else if(diff > 0.58)
{
gl_FragColor = vec4(vec3(0.0), 1.0);
return;
}
else if(diff > 0.2)
diff = 0.2;
else if(diff > 0.18)
{
gl_FragColor = vec4(vec3(0.0), 1.0);
return;
}
else diff = 0.0;
}

else if(u_mode == 2.0)
{
//Bloom filtering
}

gl_FragColor = vec4(attenuation * colmap * u_lightCol * (diff + spec), 1.0);
}
12 changes: 7 additions & 5 deletions glsl/deferred/debug.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ void main() {
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;
vec3 geomnor = normalize(gb1.xyz); // Normals of the geometry as defined, without normal mapping
vec3 colmap = gb2.xyz; // The color map - unlit "albedo" (surface color)
vec3 normap = gb3.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
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.2, 0.2, 0.2, 1.0);
}
19 changes: 19 additions & 0 deletions glsl/sphere.vert.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 100
precision highp float;
precision highp int;

attribute vec3 a_position;

uniform mat4 u_cameraMatrix;

uniform float u_scale;
uniform vec3 u_pos;

varying vec2 v_uv;

void main() {

gl_Position = u_cameraMatrix * vec4(a_position * u_scale + u_pos, 1.0);

v_uv = gl_Position.xy * 0.5 + 0.5;
}
Binary file added images/basicImage.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 images/blinnPhong.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 images/blinnPhong2.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 images/colormap.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 images/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 images/geomNorm.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 images/normalMap.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 images/points.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 images/scissorDebug.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 images/sphereDebug.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 images/surfaceNormals.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 images/toonShader.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading