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

Submission: Shuai Shao (Shrek) #3

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
5e75f55
fullscreenquad test pass
shrekshao Oct 23, 2015
a242684
gbuffer naive test
shrekshao Oct 23, 2015
175bf92
blinn phong first add
shrekshao Oct 23, 2015
79b08fb
Merge remote-tracking branch 'upstream/master'
shrekshao Oct 23, 2015
e115e1a
phong try (white)
shrekshao Oct 24, 2015
dd82866
scissor test
shrekshao Oct 24, 2015
f30e8db
Merge remote-tracking branch 'upstream/master'
shrekshao Oct 24, 2015
1e13ea3
light try
shrekshao Oct 24, 2015
4e50106
light attenuate
shrekshao Oct 24, 2015
5378732
toon(contour+step cos)
shrekshao Oct 25, 2015
89d750d
toon picture
shrekshao Oct 25, 2015
2e453c4
toon shading gui
shrekshao Oct 25, 2015
00d93f3
tiny ui fix
shrekshao Oct 25, 2015
81da61f
bloom, error src and des buffer same
shrekshao Oct 25, 2015
c6819fa
trivial
shrekshao Oct 25, 2015
caf878a
manage conflict
shrekshao Oct 25, 2015
aae3f08
ui bloom
shrekshao Oct 25, 2015
7bbaec2
artifact glow
shrekshao Oct 25, 2015
6495289
bloom fix using a intermedia glow buffer in deferred shading step
shrekshao Oct 25, 2015
764e20a
Merge remote-tracking branch 'upstream/master'
shrekshao Oct 26, 2015
8a779a7
delete old bloom else, debug img
shrekshao Oct 26, 2015
946e44b
tiny
shrekshao Oct 26, 2015
fc4f26a
comment float4
shrekshao Oct 26, 2015
8a0ee6d
2 gb, no color compress
shrekshao Oct 26, 2015
be71253
scissor debug view fix blend
shrekshao Oct 26, 2015
275566f
tiny
shrekshao Oct 26, 2015
67c1070
Merge remote-tracking branch 'upstream/master' into gbuffer
shrekshao Oct 26, 2015
549c284
light proxy try (buggy)
shrekshao Oct 27, 2015
ad303a7
debug mode change
shrekshao Oct 27, 2015
243bb51
sphere proxy zone correct
shrekshao Oct 27, 2015
8b36a27
sphere proxy works
shrekshao Oct 27, 2015
9310b5d
images
shrekshao Oct 27, 2015
4adfa06
update README
shrekshao Oct 27, 2015
91f7cba
readme video link
shrekshao Oct 27, 2015
4e96168
thumb images
shrekshao Oct 27, 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -152,3 +152,6 @@ local.properties

# TeXlipse plugin
.texlipse


debug/
41 changes: 41 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"version": "0.1.0",
// List of configurations. Add new configurations or edit existing ones.
"configurations": [
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Launch app.js",
// Type of configuration.
"type": "node",
// Workspace relative or absolute path to the program.
"program": "app.js",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
"args": [],
// Workspace relative or absolute path to the working directory of the program being debugged. Default is the current workspace.
"cwd": ".",
// Workspace relative or absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
"runtimeExecutable": null,
// Optional arguments passed to the runtime executable.
"runtimeArgs": ["--nolazy"],
// Environment variables passed to the program.
"env": {
"NODE_ENV": "development"
},
// Use JavaScript source maps (if they exist).
"sourceMaps": false,
// If JavaScript source maps are enabled, the generated code is expected in this directory.
"outDir": null
},
{
"name": "Attach",
"type": "node",
// TCP/IP address. Default is "localhost".
"address": "localhost",
// Port to attach to.
"port": 5858,
"sourceMaps": false
}
]
}
442 changes: 49 additions & 393 deletions README.md

Large diffs are not rendered by default.

36 changes: 36 additions & 0 deletions glsl/copy.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,42 @@ 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;
}



float DecodeFloatRGBA( vec4 rgba ) {
return dot( rgba, vec4(1.0, 1.0/255.0, 1.0/65025.0, 1.0/160581375.0) );
}



void main() {
// TODO: copy values into gl_FragData[0], [1], etc.


vec3 nor = normalize(applyNormalMap (v_normal, texture2D(u_normap,v_uv).rgb));
vec4 col = texture2D(u_colmap, v_uv);


//gl_FragData[0] = vec4( v_position, DecodeFloatRGBA(col));
//gl_FragData[1] = vec4( nor.xy, 1.0, 1.0);

gl_FragData[0] = vec4( v_position, col.b);
gl_FragData[1] = vec4( nor.xy, col.rg);


/*
// naive 4 gbuffers
gl_FragData[0] = vec4( v_position,1.0 );
gl_FragData[1] = vec4( v_normal.xyz,1.0);
gl_FragData[2] = texture2D(u_colmap, v_uv);
gl_FragData[3] = texture2D(u_normap,v_uv);
*/
}
20 changes: 16 additions & 4 deletions glsl/deferred/ambient.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,37 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 2

uniform sampler2D u_gbufs[NUM_GBUFFERS];
uniform sampler2D u_depth;

varying vec2 v_uv;


vec4 EncodeFloatRGBA( float v ) {
vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;
enc = fract(enc);
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);
return enc;

}


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 colmap = EncodeFloatRGBA(gb0.w).rgb;
vec3 colmap = vec3(gb1.z,gb1.w,gb0.w);

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.2*colmap, 1.0); // TODO: replace this
}
81 changes: 75 additions & 6 deletions glsl/deferred/blinnphong-pointlight.frag.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@
precision highp float;
precision highp int;

#define NUM_GBUFFERS 4
#define NUM_GBUFFERS 2

#define TOON_STEP 0.2
#define TOON_DEPTH_THRESHOLD 1.0

uniform bool u_toonShading;

uniform vec3 u_cameraPos;

uniform vec3 u_lightCol;
uniform vec3 u_lightPos;
Expand All @@ -12,28 +19,90 @@ uniform sampler2D u_depth;

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;
}
*/

vec4 EncodeFloatRGBA( float v ) {
vec4 enc = vec4(1.0, 255.0, 65025.0, 160581375.0) * v;
enc = fract(enc);
enc -= enc.yzww * vec4(1.0/255.0,1.0/255.0,1.0/255.0,0.0);
return enc;

}


void main() {

vec2 uv = vec2(gl_FragCoord.x / 800.0, gl_FragCoord.y / 600.0);

vec4 gb0 = texture2D(u_gbufs[0], uv);
vec4 gb1 = texture2D(u_gbufs[1], uv);

float depth = texture2D(u_depth, uv).x;



/*
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


//TODO:optimize gbuffer structure
vec3 pos = gb0.xyz;
vec3 geomnor = gb1.xyz;
//vec3 colmap = EncodeFloatRGBA(gb0.w).rgb;
vec3 colmap = vec3(gb1.z,gb1.w,gb0.w);

vec3 nor = gb1.xyy;
nor.z = sqrt(1.0 - nor.x*nor.x - nor.y*nor.y);

// 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



vec3 l = u_lightPos - pos;

float dist = length(l);

l = l / dist;

float attenuation = clamp(1.0 - dist/u_lightRad, 0.0, 1.0);

float diffuse_cos = max(dot(l,nor),0.0);
if(u_toonShading)
{
diffuse_cos = TOON_STEP * float(floor(diffuse_cos/TOON_STEP));
}


vec3 diffuse = diffuse_cos * u_lightCol * colmap;

vec3 v = normalize(u_cameraPos - pos);
vec3 r = -l + 2.0 * dot(l,nor) * nor;
float specular_cos = max(dot(r,v),0.0);
if(u_toonShading)
{
specular_cos = TOON_STEP * float(floor(specular_cos/TOON_STEP));
}

vec3 specular = pow( specular_cos, 32.0) * u_lightCol * colmap;

gl_FragColor = vec4 ( attenuation * (diffuse + specular) , 1.0);

//gl_FragColor = vec4(v_uv,0.0,1.0);
}
56 changes: 56 additions & 0 deletions glsl/deferred/bloom.frag.glsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#version 100
precision highp float;
precision highp int;

#define BLOOM_THRESHOLD 0.8

#define GAUSSIAN_R 3

uniform float u_width;
uniform float u_height;

uniform int u_axis;

uniform sampler2D u_color;

varying vec2 v_uv;




//float weight[3] = float[3]( 0.33333333, 0.33333333, 0.33333333 );

void main() {

vec2 offset = vec2( u_axis==0 ? 1.0/u_width : 0.0
, u_axis==1 ? 1.0/u_height : 0.0);
vec4 color = texture2D(u_color, v_uv).rgba;

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

vec3 bloom = vec3(0.0);



for(int i = -10 ; i <= 10; i++)
{

vec3 cur_color = texture2D(u_color, v_uv + float(i) * offset ).rgb;

//bloom += weight[i+1] * ( cur_color - vec3(BLOOM_THRESHOLD) );
bloom += 0.2 * ( max(cur_color - vec3(BLOOM_THRESHOLD),0.0) );
}




gl_FragColor = vec4(bloom,1.0);

//gl_FragColor = vec4(1.0);


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



#define TOON_DEPTH_THRESHOLD 0.02

uniform float u_width;
uniform float u_height;


uniform sampler2D u_depth;

varying vec2 v_uv;


float unpack_depth(const in vec4 rgba_depth){
/*
const vec4 bit_shift =
vec4(1.0/(256.0*256.0*256.0)
, 1.0/(256.0*256.0)
, 1.0/256.0
, 1.0);
float depth = dot(rgba_depth, bit_shift);
return depth;
*/
return rgba_depth.x;
}

void main() {
float depth = texture2D(u_depth, v_uv).x;

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




vec2 x_offset = vec2(1.0/u_width, 0.0);
vec2 y_offset = vec2(0.0, 1.0/u_height);

//float laplacian = depth;


float laplacian = abs(texture2D(u_depth, v_uv + x_offset).x
+ texture2D(u_depth, v_uv - x_offset).x
+ texture2D(u_depth, v_uv + y_offset).x
+ texture2D(u_depth, v_uv - y_offset).x
- 4.0 * depth);


if(laplacian > TOON_DEPTH_THRESHOLD)
{
//contour
//use black
gl_FragColor = vec4(0, 0, 0, 1);
return;
}


gl_FragColor = vec4(0,0,0,0);

}
Loading