border
This commit is contained in:
parent
7ebba10385
commit
ab4a1b8d5a
1 changed files with 38 additions and 26 deletions
|
@ -14,7 +14,27 @@ uniform bool u_init;
|
|||
|
||||
varying vec2 v_texcoord;
|
||||
|
||||
float depthToSilhouette(float depth) {
|
||||
if(depth < 0.005) return 0;
|
||||
if(depth > 0.1) return 0;
|
||||
else return 1;
|
||||
}
|
||||
|
||||
void main() {
|
||||
vec2 pixel = 1./u_resolution;
|
||||
vec2 offset[9];
|
||||
offset[0] = pixel * vec2(-1.0,-1.0);
|
||||
offset[1] = pixel * vec2( 0.0,-1.0);
|
||||
offset[2] = pixel * vec2( 1.0,-1.0);
|
||||
|
||||
offset[3] = pixel * vec2(-1.0,0.0);
|
||||
offset[4] = pixel * vec2( 0.0,0.0);
|
||||
offset[5] = pixel * vec2( 1.0,0.0);
|
||||
|
||||
offset[6] = pixel * vec2(-1.0,1.0);
|
||||
offset[7] = pixel * vec2( 0.0,1.0);
|
||||
offset[8] = pixel * vec2( 1.0,1.0);
|
||||
|
||||
vec2 st = v_texcoord;
|
||||
// st.y = 1.0 - st.y;
|
||||
|
||||
|
@ -28,12 +48,9 @@ void main() {
|
|||
vec4 color = vec4(0,0,0,1);
|
||||
if(u_init) {
|
||||
float tmp = texture2D(u_depth, st).r;
|
||||
if(tmp > 0.005) {
|
||||
color.rgb = vec3(1);
|
||||
}
|
||||
color.rgb = vec3(depthToSilhouette(tmp));
|
||||
}
|
||||
else {
|
||||
vec2 pixel = 1./u_resolution;
|
||||
|
||||
float kernel[9];
|
||||
kernel[0] = 0.125;
|
||||
|
@ -46,28 +63,13 @@ void main() {
|
|||
kernel[7] = 0.25;
|
||||
kernel[8] = 0.125;
|
||||
|
||||
vec2 offset[9];
|
||||
offset[0] = pixel * vec2(-1.0,-1.0);
|
||||
offset[1] = pixel * vec2( 0.0,-1.0);
|
||||
offset[2] = pixel * vec2( 1.0,-1.0);
|
||||
|
||||
offset[3] = pixel * vec2(-1.0,0.0);
|
||||
offset[4] = pixel * vec2( 0.0,0.0);
|
||||
offset[5] = pixel * vec2( 1.0,0.0);
|
||||
|
||||
offset[6] = pixel * vec2(-1.0,1.0);
|
||||
offset[7] = pixel * vec2( 0.0,1.0);
|
||||
offset[8] = pixel * vec2( 1.0,1.0);
|
||||
|
||||
float lap = 0;
|
||||
|
||||
for (int i=0; i < 9; i++){
|
||||
float tmp = texture2D(u_buffer1, st + offset[i]).r;
|
||||
// lap += tmp * kernel[i] / 2.5;
|
||||
if(tmp > 0.005) {
|
||||
color.rgb = vec3(1);
|
||||
}
|
||||
lap += tmp * kernel[i] / 2.5;
|
||||
}
|
||||
color = vec4(vec3(lap * 2.0), 1.0);
|
||||
}
|
||||
|
||||
gl_FragColor = color;
|
||||
|
@ -81,14 +83,24 @@ void main() {
|
|||
gl_FragColor = texture2D(u_buffer0, st);
|
||||
#else
|
||||
// Main Buffer
|
||||
float buf1 = texture2D(u_buffer1, st).r;
|
||||
vec3 dispColor = vec3(0, 0, 1);
|
||||
dispColor.r = texture2D(u_depth, st).r > 0.005 ? 1 : 0;
|
||||
dispColor.g = texture2D(u_buffer1, st).r;
|
||||
dispColor.rgb = vec3(depthToSilhouette(texture2D(u_depth, st).r));
|
||||
|
||||
float maxVal = buf1;
|
||||
float minVal = buf1;
|
||||
for (int i=0; i < 9; i++){
|
||||
float tmp = texture2D(u_buffer1, st + offset[i]).r;
|
||||
maxVal = max(maxVal, tmp);
|
||||
minVal = min(minVal, tmp);
|
||||
}
|
||||
|
||||
if(maxVal - minVal > 0.1) {
|
||||
dispColor.rgb = vec3(1);
|
||||
}
|
||||
|
||||
// color.r = 1.;
|
||||
gl_FragColor = vec4(dispColor, 1.0);
|
||||
|
||||
|
||||
// gl_FragColor = color;
|
||||
#endif
|
||||
|
||||
}
|
Loading…
Reference in a new issue