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

Submission: Ziye Zhou #6

Open
wants to merge 8 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
440 changes: 43 additions & 397 deletions README.md

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions bin_new/deferred_shader/deferred_shader.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2013
VisualStudioVersion = 12.0.31101.0
MinimumVisualStudioVersion = 10.0.40219.1
Global
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
EndGlobal
18 changes: 18 additions & 0 deletions glsl/copy.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ 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); //pos
gl_FragData[2] = texture2D(u_colmap, v_uv); // colormap


vec3 surface_nor = applyNormalMap(v_normal, vec3(texture2D(u_normap, v_uv)));
gl_FragData[1] = vec4(surface_nor,1.0);

//gl_FragData[1] = vec4(v_normal,1.0); //geonormal
//gl_FragData[3] = texture2D(u_normap, v_uv); //normal map
}
17 changes: 10 additions & 7 deletions glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,20 @@ 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;
//vec4 gb0 = texture2D(u_gbufs[0], v_uv); //pos
//vec4 gb1 = texture2D(u_gbufs[1], v_uv); //geomnor
vec4 gb2 = texture2D(u_gbufs[2], v_uv); //colormap
//vec4 gb3 = texture2D(u_gbufs[3], v_uv); //normap
float depth = texture2D(u_depth, v_uv).x; //depth
// TODO: Extract needed properties from the g-buffers into local variables




if (depth == 1.0) {
gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0
gl_FragColor = vec4(0, 0, 0, 0); // set alpha to 0 used for post processing
return;
}

gl_FragColor = vec4(0.1, 0.1, 0.1, 1); // TODO: replace this
gl_FragColor = vec4(0.8*(1.0-depth)*vec3(gb2),1.0);//vec4(0.1, 0.1, 0.1, 1); // TODO: replace this
}
63 changes: 61 additions & 2 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ uniform sampler2D u_depth;

varying vec2 v_uv;

const float shininess = 20.0;
const vec3 specular_col = vec3 (1.0,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));
Expand All @@ -24,16 +28,71 @@ 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);
//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(gb0);

vec3 colmap = vec3(gb2);

//vec3 geomnor = vec3(gb1);
//vec3 normap = vec3(gb3);
// vec3 nor = applyNormalMap(geomnor, normap);
vec3 nor = vec3(gb1);

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

gl_FragColor = vec4(0, 0, 1, 1); // TODO: perform lighting calculations
float attenuation = max(0.0, u_lightRad - distance(u_lightPos ,pos))/u_lightRad;

if(attenuation == 0.0)
{
//gl_FragColor = vec4(0, 0, 0, 1);
return;
}





vec3 lightDir = normalize(u_lightPos - pos);




vec3 diffuse_col = vec3( colmap[0] * u_lightCol[0],colmap[1] * u_lightCol[1],colmap[2] * u_lightCol[2]);

//vec3 diffuse_col = vec3(colmap[0],0.0,0.0);


float lambertian = max(dot(lightDir,nor), 0.0);
float specular = 0.0;

if(lambertian > 0.0)
{

vec3 viewDir = normalize(-pos);

// this is blinn phong
vec3 halfDir = normalize(lightDir + viewDir);
float specAngle = max(dot(halfDir, nor), 0.0);
specular = pow(specAngle, shininess);

}




vec3 final_col = attenuation*lambertian*diffuse_col + attenuation*specular*specular_col ; // TODO: perform lighting calculations

// vec3 final_col = lambertian*diffuse_col + specular*specular_col;

// gl_FragColor = vec4(0.5,0.5,0.5,1.0);
gl_FragColor = vec4(final_col,1.0);
}
10 changes: 5 additions & 5 deletions glsl/deferred/debug.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ void main() {
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 = vec3(gb0);
vec3 geomnor = vec3(gb1);
vec3 colmap = vec3(gb2);
vec3 normap = vec3(gb3);
vec3 nor = applyNormalMap(geomnor, normap);

if (u_debug == 0) {
gl_FragColor = vec4(vec3(depth), 1.0);
Expand Down
35 changes: 35 additions & 0 deletions glsl/post/bloom.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;

uniform float u_width;
uniform float u_height;

varying vec2 v_uv;


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



if(color.a > 1.0)
{
//blur along x
float dx = 1.0/u_width;
vec4 color_1 = texture2D(u_color, vec2(v_uv.x -dx,v_uv.y));
vec4 color_2 = texture2D(u_color, vec2(v_uv.x +dx,v_uv.y));
vec4 color_3 = texture2D(u_color, vec2(v_uv.x -dx-dx,v_uv.y));
vec4 color_4 = texture2D(u_color, vec2(v_uv.x +dx+dx ,v_uv.y));

gl_FragColor = (color_3 + color_4 + color_1*3.0 + color_2*3.0 + color*7.0 )/15.0;


return;
}


gl_FragColor = color;
}
35 changes: 35 additions & 0 deletions glsl/post/bloom2.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;

uniform float u_width;
uniform float u_height;

varying vec2 v_uv;


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



if(color.a > 1.0)
{
//blur along x
float dy = 1.0/u_height;
vec4 color_1 = texture2D(u_color, vec2(v_uv.x ,v_uv.y-dy));
vec4 color_2 = texture2D(u_color, vec2(v_uv.x ,v_uv.y+dy));
vec4 color_3 = texture2D(u_color, vec2(v_uv.x ,v_uv.y-dy-dy));
vec4 color_4 = texture2D(u_color, vec2(v_uv.x ,v_uv.y+dy+dy));

gl_FragColor = (color_3 + color_4 + color_1*3.0 + color_2*3.0 + color*7.0 )/15.0;


return;
}


gl_FragColor = color;
}
14 changes: 12 additions & 2 deletions glsl/post/one.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,27 @@ precision highp int;

uniform sampler2D u_color;

uniform float u_width;
uniform float u_height;

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) {



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





gl_FragColor = color;
}
19 changes: 19 additions & 0 deletions glsl/post/scdebug.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#version 100
precision highp float;
precision highp int;

uniform float u_xmin;
uniform float u_xmax;
uniform float u_ymin;
uniform float u_ymax;

varying vec2 v_uv;

void main() {

if(v_uv.x<=u_xmax && v_uv.x>=u_xmin && v_uv.y<=u_ymax && v_uv.y>=u_ymin)
{
gl_FragColor = vec4(1, 0, 0, 0.1);
}

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

uniform sampler2D u_color;

uniform float u_width;
uniform float u_height;

varying vec2 v_uv;


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


if(color.r > 0.5)
{
color.r = 0.75;
}
else
{
color.r = 0.25;
}

if(color.g > 0.5)
{
color.g = 0.75;
}
else
{
color.g = 0.25;
}

if(color.b > 0.5)
{
color.b = 0.75;
}
else
{
color.b = 0.25;
}



gl_FragColor = color;
}
Binary file added img/debug_img/Sc_debug.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_img/colormap_1025.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_img/depth_1025.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_img/geonormal_1025.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_img/normap_1025.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_img/position_1025.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_img/surfacenormal_1025.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/light/ambient_1025.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/light/blinnphong_1025.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/light/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/light/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/light/wo_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/profile/w_g_buffer_optimization.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/profile/wo_g_buffer_optimization.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/video.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading