Format shaders (#654)

This commit is contained in:
Gustl22 2019-02-10 23:34:28 +01:00 committed by Emux
parent 48a5c36c31
commit fc452a76e7
No known key found for this signature in database
GPG Key ID: 64ED9980896038C3
17 changed files with 449 additions and 468 deletions

View File

@ -5,7 +5,7 @@ uniform mat4 u_mvp;
attribute vec4 a_pos;
void main() {
gl_Position = u_mvp * a_pos;
gl_Position = u_mvp * a_pos;
}
$$
@ -16,6 +16,5 @@ precision highp float;
uniform vec4 u_color;
void main() {
gl_FragColor = u_color;
gl_FragColor = u_color;
}

View File

@ -14,60 +14,59 @@ varying vec4 color;
const float ff = 255.0;
/**
* The diffuse of surface dependent on the light position
* The diffuse of surface dependent on the light position.
*
* @param r_norm - the normal vector of vertex's face
* @param r_norm the normal vector of vertex's face
*/
float diffuse(in vec3 r_norm) {
float l = dot(normalize(r_norm), normalize(u_light));
l = clamp((1.0 + l) / 2.0, 0.0, 1.0);
return(0.8 + l * 0.2);
float l = dot(normalize(r_norm), normalize(u_light));
l = clamp((1.0 + l) / 2.0, 0.0, 1.0);
return(0.8 + l * 0.2);
}
void main() {
// change height by u_alpha
float height = a_pos.z * u_alpha;
if (height > u_zlimit) {
height = u_zlimit;
}
gl_Position = u_mvp * vec4(a_pos.xy, height, 1.0);
//depth = gl_Position.z;
if (u_mode == -1) {
;
} else if(u_mode >= 0 && u_mode <= 2) {
vec3 r_norm;
if (u_mode == 0) {
// roof / depth pass
r_norm = vec3(0.0, 0.0, 1.0);
color = u_color[0] * u_alpha;
color.rgb *= diffuse(r_norm);
} else {
float lightX = u_mode == 1 ? a_normal.y : a_normal.x;
r_norm.x = (lightX / ff) * 2.0 - 1.0;
// normal points y left or right (1 or -1)
float dir = - 1.0 + (2.0 * abs(mod(lightX, 2.0)));
// recreate y vector
r_norm.y = dir * sqrt(clamp(1.0 - (r_norm.x * r_norm.x), 0.0, 1.0));
r_norm.z = 0.0;
float z = (0.98 + gl_Position.z * 0.02);
float h = 0.9 + clamp(a_pos.z / 2000.0, 0.0, 0.1);
if (u_mode == 1) {
// sides 1 - use 0xff00
color = u_color[1];
} else {
// sides 2 - use 0x00ff
color = u_color[2];
}
color.rgb *= diffuse(r_norm) * z * h;
// change height by u_alpha
float height = a_pos.z * u_alpha;
if (height > u_zlimit) {
height = u_zlimit;
}
gl_Position = u_mvp * vec4(a_pos.xy, height, 1.0);
//depth = gl_Position.z;
if (u_mode == -1) {
;
} else if (u_mode >= 0 && u_mode <= 2) {
vec3 r_norm;
if (u_mode == 0) {
// roof / depth pass
r_norm = vec3(0.0, 0.0, 1.0);
color = u_color[0] * u_alpha;
color.rgb *= diffuse(r_norm);
} else {
float lightX = u_mode == 1 ? a_normal.y : a_normal.x;
r_norm.x = (lightX / ff) * 2.0 - 1.0;
// normal points y left or right (1 or -1)
float dir = -1.0 + (2.0 * abs(mod(lightX, 2.0)));
// recreate y vector
r_norm.y = dir * sqrt(clamp(1.0 - (r_norm.x * r_norm.x), 0.0, 1.0));
r_norm.z = 0.0;
float z = (0.98 + gl_Position.z * 0.02);
float h = 0.9 + clamp(a_pos.z / 2000.0, 0.0, 0.1);
if (u_mode == 1) {
// sides 1 - use 0xff00
color = u_color[1];
} else {
// sides 2 - use 0x00ff
color = u_color[2];
}
color.rgb *= diffuse(r_norm) * z * h;
}
color *= u_alpha;
} else if (u_mode == 3) {
// outline
float z = (0.98 - gl_Position.z * 0.02);
color = u_color[3] * z;
}
color *= u_alpha;
}
else if (u_mode == 3) {
// outline
float z = (0.98 - gl_Position.z * 0.02);
color = u_color[3] * z;
}
}
$$
@ -78,5 +77,5 @@ precision highp float;
varying vec4 color;
void main() {
gl_FragColor = color;
gl_FragColor = color;
}

View File

@ -10,36 +10,36 @@ attribute vec2 a_normal;
varying vec4 color;
void main() {
// change height by u_alpha
vec4 pos = a_pos;
pos.z *= u_alpha;
gl_Position = u_mvp * pos;
// normalize face x/y direction
vec2 enc = (a_normal / 255.0);
// change height by u_alpha
vec4 pos = a_pos;
pos.z *= u_alpha;
gl_Position = u_mvp * pos;
// normalize face x/y direction
vec2 enc = (a_normal / 255.0);
vec3 r_norm;
// 1² - |xy|² = |z|²
r_norm.xy = enc * 2.0 - 1.0;
// normal points up or down (1,-1)
float dir = - 1.0 + (2.0 * abs(mod(a_normal.x, 2.0)));
// recreate z vector
r_norm.z = dir * sqrt(clamp(1.0 - (r_norm.x * r_norm.x + r_norm.y * r_norm.y), 0.0, 1.0));
r_norm = normalize(r_norm);
vec3 r_norm;
// 1² - |xy|² = |z|²
r_norm.xy = enc * 2.0 - 1.0;
// normal points up or down (1,-1)
float dir = -1.0 + (2.0 * abs(mod(a_normal.x, 2.0)));
// recreate z vector
r_norm.z = dir * sqrt(clamp(1.0 - (r_norm.x * r_norm.x + r_norm.y * r_norm.y), 0.0, 1.0));
r_norm = normalize(r_norm);
float l = dot(r_norm, normalize(u_light));
float l = dot(r_norm, normalize(u_light));
//l *= 0.8
//vec3 opp_light_dir = normalize(vec3(-u_light.xy, u_light.z));
//l += dot(r_norm, opp_light_dir) * 0.2;
//l *= 0.8
//vec3 opp_light_dir = normalize(vec3(-u_light.xy, u_light.z));
//l += dot(r_norm, opp_light_dir) * 0.2;
// [-1,1] to range [0,1]
l = (1.0 + l) / 2.0;
// [-1,1] to range [0,1]
l = (1.0 + l) / 2.0;
l = 0.75 + l * 0.25;
l = 0.75 + l * 0.25;
// extreme fake-ssao by height
l += (clamp(a_pos.z / 2048.0, 0.0, 0.1) - 0.05);
color = vec4(u_color.rgb * (clamp(l, 0.0, 1.0)), u_color.a) * u_alpha;
// extreme fake-ssao by height
l += (clamp(a_pos.z / 2048.0, 0.0, 0.1) - 0.05);
color = vec4(u_color.rgb * (clamp(l, 0.0, 1.0)), u_color.a) * u_alpha;
}
$$
@ -50,5 +50,5 @@ precision highp float;
varying vec4 color;
void main() {
gl_FragColor = color;
gl_FragColor = color;
}

View File

@ -13,9 +13,9 @@ varying vec4 v_pos;
varying vec2 s_pos;
void main() {
v_pos = u_mvp * vec4(a_pos, 0.0, 1.0);
s_pos = v_pos.xy / v_pos.w;
gl_Position = v_pos;
v_pos = u_mvp * vec4(a_pos, 0.0, 1.0);
s_pos = v_pos.xy / v_pos.w;
gl_Position = v_pos;
}
$$
@ -30,10 +30,10 @@ varying vec4 v_pos;
varying vec2 s_pos;
void main() {
vec2 pos = (v_pos.xy) / v_pos.w * u_screen;
float l = length(gl_FragCoord.xy - u_screen - pos.xy);
float z = clamp(0.6, 1.0, 1.2 - (v_pos.z/ v_pos.w));
vec2 pos = (v_pos.xy) / v_pos.w * u_screen;
gl_FragColor = u_color * (smoothstep(1.0, 0.0, l / u_width) * z);
float l = length(gl_FragCoord.xy - u_screen - pos.xy);
float z = clamp(0.6, 1.0, 1.2 - (v_pos.z / v_pos.w));
gl_FragColor = u_color * (smoothstep(1.0, 0.0, l / u_width) * z);
}

View File

@ -12,14 +12,13 @@ uniform float u_height;
varying vec2 v_st;
void main() {
// scale extrusion to u_width pixel
// just ignore the two most insignificant bits.
vec2 dir = a_pos.zw;
gl_Position = u_mvp * vec4(a_pos.xy + (u_width * dir), u_height, 1.0);
// scale extrusion to u_width pixel
// just ignore the two most insignificant bits.
vec2 dir = a_pos.zw;
gl_Position = u_mvp * vec4(a_pos.xy + (u_width * dir), u_height, 1.0);
// last two bits hold the texture coordinates.
v_st = abs(mod(dir, 4.0)) - 1.0;
// last two bits hold the texture coordinates.
v_st = abs(mod(dir, 4.0)) - 1.0;
}
$$
@ -34,30 +33,29 @@ uniform vec4 u_color;
varying vec2 v_st;
void main() {
float len;
if (u_mode == 2) {
// round cap line
float len;
if (u_mode == 2) {
// round cap line
#ifdef DESKTOP_QUIRKS
len = length(v_st);
len = length(v_st);
#else
len = texture2D(tex, v_st).a;
len = texture2D(tex, v_st).a;
#endif
}
else {
// flat cap line
len = abs(v_st.s);
}
// Antialias line-edges:
// - 'len' is 0 at center of line. -> (1.0 - len) is 0 at the
// edges
// - 'u_fade' is 'pixel' / 'width', i.e. the inverse width of
// the
// line in pixel on screen.
// - 'pixel' is 1.5 / relativeScale
// - '(1.0 - len) / u_fade' interpolates the 'pixel' on
// line-edge
// between 0 and 1 (it is greater 1 for all inner pixel).
gl_FragColor = u_color * clamp((1.0 - len) / u_fade, 0.0, 1.0);
// -> nicer for thin lines
// gl_FragColor = u_color * clamp((1.0 - (len * len)) / u_fade, 0.0, 1.0);
} else {
// flat cap line
len = abs(v_st.s);
}
// Antialias line-edges:
// - 'len' is 0 at center of line. -> (1.0 - len) is 0 at the
// edges
// - 'u_fade' is 'pixel' / 'width', i.e. the inverse width of
// the
// line in pixel on screen.
// - 'pixel' is 1.5 / relativeScale
// - '(1.0 - len) / u_fade' interpolates the 'pixel' on
// line-edge
// between 0 and 1 (it is greater 1 for all inner pixel).
gl_FragColor = u_color * clamp((1.0 - len) / u_fade, 0.0, 1.0);
// -> nicer for thin lines
//gl_FragColor = u_color * clamp((1.0 - (len * len)) / u_fade, 0.0, 1.0);
}

View File

@ -12,14 +12,13 @@ uniform float u_height;
varying vec2 v_st;
void main() {
// scale extrusion to u_width pixel
// just ignore the two most insignificant bits.
vec2 dir = a_pos.zw;
gl_Position = u_mvp * vec4(a_pos.xy + (u_width * dir), u_height, 1.0);
// scale extrusion to u_width pixel
// just ignore the two most insignificant bits.
vec2 dir = a_pos.zw;
gl_Position = u_mvp * vec4(a_pos.xy + (u_width * dir), u_height, 1.0);
// last two bits hold the texture coordinates.
v_st = abs(mod(dir, 4.0)) - 1.0;
// last two bits hold the texture coordinates.
v_st = abs(mod(dir, 4.0)) - 1.0;
}
$$
@ -37,28 +36,27 @@ uniform float u_fade;
varying vec2 v_st;
void main() {
float len;
float fuzz;
if (u_mode == 2) {
/* round cap line */
float len;
float fuzz;
if (u_mode == 2) {
/* round cap line */
#ifdef DESKTOP_QUIRKS
len = length(v_st);
len = length(v_st);
#else
len = texture2D(tex, v_st).a;
len = texture2D(tex, v_st).a;
#endif
vec2 st_width = fwidth(v_st);
fuzz = max(st_width.s, st_width.t);
}
else {
/* flat cap line */
len = abs(v_st.s);
fuzz = fwidth(v_st.s);
}
// u_mode == 0 -> thin line
// len = len * clamp(float(u_mode), len, 1.0);
if (fuzz > 2.0)
gl_FragColor = u_color * 0.5;
else
gl_FragColor = u_color * clamp((1.0 - len) / max(u_fade, fuzz), 0.0, 1.0);
// gl_FragColor = u_color * clamp((1.0 - len), 0.0, 1.0);
vec2 st_width = fwidth(v_st);
fuzz = max(st_width.s, st_width.t);
} else {
/* flat cap line */
len = abs(v_st.s);
fuzz = fwidth(v_st.s);
}
// u_mode == 0 -> thin line
// len = len * clamp(float(u_mode), len, 1.0);
if (fuzz > 2.0)
gl_FragColor = u_color * 0.5;
else
gl_FragColor = u_color * clamp((1.0 - len) / max(u_fade, fuzz), 0.0, 1.0);
//gl_FragColor = u_color * clamp((1.0 - len), 0.0, 1.0);
}

View File

@ -13,18 +13,17 @@ attribute float a_flip;
varying vec2 v_st;
void main() {
vec4 pos;
if (a_flip == 0.0) {
// vec2 dir = u_width * a_pos0.zw;
pos = vec4(a_pos0.xy + (u_width * a_pos0.zw), 0.0, 1.0);
v_st = vec2(a_len0.x / u_pscale, 1.0);
}
else {
// vec2 dir = u_width * a_pos1.zw;
pos = vec4(a_pos1.xy - (u_width * a_pos1.zw), 0.0, 1.0);
v_st = vec2(a_len1.x / u_pscale, -1.0);
}
gl_Position = u_mvp * pos;
vec4 pos;
if (a_flip == 0.0) {
// vec2 dir = u_width * a_pos0.zw;
pos = vec4(a_pos0.xy + (u_width * a_pos0.zw), 0.0, 1.0);
v_st = vec2(a_len0.x / u_pscale, 1.0);
} else {
// vec2 dir = u_width * a_pos1.zw;
pos = vec4(a_pos1.xy - (u_width * a_pos1.zw), 0.0, 1.0);
v_st = vec2(a_len1.x / u_pscale, -1.0);
}
gl_Position = u_mvp * pos;
}
$$
@ -41,15 +40,15 @@ uniform float u_pwidth;
varying vec2 v_st;
void main() {
/* distance on perpendicular to the line */
float dist = abs(v_st.t);
float fuzz = fwidth(v_st.t);
float fuzz_p = fwidth(v_st.s);
float line_w = smoothstep(0.0, fuzz, 1.0 - dist);
float stipple_w = smoothstep(0.0, fuzz, u_pwidth - dist);
/* triangle waveform in the range 0..1 for regular pattern */
float phase = abs(mod(v_st.s, 2.0) - 1.0);
/* interpolate between on/off phase, 0.5 = equal phase length */
float stipple_p = smoothstep(0.5 - fuzz_p, 0.5 + fuzz_p, phase);
gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));
/* distance on perpendicular to the line */
float dist = abs(v_st.t);
float fuzz = fwidth(v_st.t);
float fuzz_p = fwidth(v_st.s);
float line_w = smoothstep(0.0, fuzz, 1.0 - dist);
float stipple_w = smoothstep(0.0, fuzz, u_pwidth - dist);
/* triangle waveform in the range 0..1 for regular pattern */
float phase = abs(mod(v_st.s, 2.0) - 1.0);
/* interpolate between on/off phase, 0.5 = equal phase length */
float stipple_p = smoothstep(0.5 - fuzz_p, 0.5 + fuzz_p, phase);
gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));
}

View File

@ -13,18 +13,17 @@ attribute float a_flip; // flip state
varying vec2 v_st;
void main() {
vec4 pos;
if (a_flip == 0.0) {
// vec2 dir = u_width * a_pos0.zw;
pos = vec4(a_pos0.xy + (u_width * a_pos0.zw), 0.0, 1.0);
v_st = vec2(a_len0.x / u_pscale, 1.0);
}
else {
// vec2 dir = u_width * a_pos1.zw;
pos = vec4(a_pos1.xy - (u_width * a_pos1.zw), 0.0, 1.0);
v_st = vec2(a_len1.x / u_pscale, -1.0);
}
gl_Position = u_mvp * pos;
vec4 pos;
if (a_flip == 0.0) {
// vec2 dir = u_width * a_pos0.zw;
pos = vec4(a_pos0.xy + (u_width * a_pos0.zw), 0.0, 1.0);
v_st = vec2(a_len0.x / u_pscale, 1.0);
} else {
// vec2 dir = u_width * a_pos1.zw;
pos = vec4(a_pos1.xy - (u_width * a_pos1.zw), 0.0, 1.0);
v_st = vec2(a_len1.x / u_pscale, -1.0);
}
gl_Position = u_mvp * pos;
}
$$
@ -43,31 +42,29 @@ uniform sampler2D tex;
uniform int u_mode;
void main() {
if (u_mode >= 1) {
/* Dash array or texture */
float step = 2.0;
if (u_mode == 2) { // dashed texture
step = 1.0;
if (u_mode >= 1) {
/* Dash array or texture */
float step = 2.0;
if (u_mode == 2) { // dashed texture
step = 1.0;
}
// use lineLength mod texture step (mod is always positive)
// add 1.0 to avoid static line textures while zooming
vec4 c = texture2D(tex, vec2(mod(v_st.s + 1.0, step), (v_st.t + 1.0) * 0.5));
float fuzz = fwidth(c.a);
gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a);
} else {
/* No dash array or texture */
/* distance on perpendicular to the line */
float dist = abs(v_st.t);
float fuzz = fwidth(v_st.t);
float fuzz_p = fwidth(v_st.s);
float line_w = smoothstep(0.0, fuzz, 1.0 - dist);
float stipple_w = smoothstep(0.0, fuzz, u_pwidth - dist);
/* triangle waveform in the range 0..1 for regular pattern */
float phase = abs(mod(v_st.s, 2.0) - 1.0);
/* interpolate between on/off phase, 0.5 = equal phase length */
float stipple_p = smoothstep(0.5 - fuzz_p, 0.5 + fuzz_p, phase);
gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));
}
// use lineLength mod texture step (mod is always positive)
// add 1.0 to avoid static line textures while zooming
vec4 c = texture2D(tex, vec2(mod(v_st.s + 1.0, step), (v_st.t + 1.0) * 0.5));
float fuzz = fwidth(c.a);
gl_FragColor = (c * u_color) * smoothstep(0.5 - fuzz, 0.5 + fuzz, c.a);
}
else {
/* No dash array or texture */
/* distance on perpendicular to the line */
float dist = abs(v_st.t);
float fuzz = fwidth(v_st.t);
float fuzz_p = fwidth(v_st.s);
float line_w = smoothstep(0.0, fuzz, 1.0 - dist);
float stipple_w = smoothstep(0.0, fuzz, u_pwidth - dist);
/* triangle waveform in the range 0..1 for regular pattern */
float phase = abs(mod(v_st.s, 2.0) - 1.0);
/* interpolate between on/off phase, 0.5 = equal phase length */
float stipple_p = smoothstep(0.5 - fuzz_p, 0.5 + fuzz_p, phase);
gl_FragColor = line_w * mix(u_bgcolor, u_color, min(stipple_w, stipple_p));
}
}

View File

@ -6,7 +6,7 @@ uniform float u_height;
attribute vec2 a_pos;
void main() {
gl_Position = u_mvp * vec4(a_pos, u_height, 1.0);
gl_Position = u_mvp * vec4(a_pos, u_height, 1.0);
}
$$
@ -17,5 +17,5 @@ precision highp float;
uniform vec4 u_color;
void main() {
gl_FragColor = u_color;
gl_FragColor = u_color;
}

View File

@ -8,9 +8,9 @@ varying vec2 v_st;
varying vec2 v_st2;
void main() {
v_st = clamp(a_pos.xy, 0.0, 1.0) * (2.0 / u_scale.y);
v_st2 = clamp(a_pos.xy, 0.0, 1.0) * (4.0 / u_scale.y);
gl_Position = u_mvp * a_pos;
v_st = clamp(a_pos.xy, 0.0, 1.0) * (2.0 / u_scale.y);
v_st2 = clamp(a_pos.xy, 0.0, 1.0) * (4.0 / u_scale.y);
gl_Position = u_mvp * a_pos;
}
$$
@ -25,5 +25,5 @@ varying vec2 v_st;
varying vec2 v_st2;
void main() {
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x);
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x);
}

View File

@ -8,9 +8,9 @@ varying vec2 v_st;
varying vec2 v_st2;
void main() {
v_st = clamp(a_pos.xy, 0.0, 1.0) * (2.0 / u_scale.y);
v_st2 = clamp(a_pos.xy, 0.0, 1.0) * (4.0 / u_scale.y);
gl_Position = u_mvp * a_pos;
v_st = clamp(a_pos.xy, 0.0, 1.0) * (2.0 / u_scale.y);
v_st2 = clamp(a_pos.xy, 0.0, 1.0) * (4.0 / u_scale.y);
gl_Position = u_mvp * a_pos;
}
$$
@ -25,5 +25,5 @@ varying vec2 v_st;
varying vec2 v_st2;
void main() {
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x) * u_color;
gl_FragColor = mix(texture2D(tex, v_st), texture2D(tex, v_st2), u_scale.x) * u_color;
}

View File

@ -6,8 +6,8 @@ attribute vec4 a_pos;
varying vec2 tex_pos;
void main() {
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
}
$$
@ -20,7 +20,5 @@ uniform vec2 u_pixel;
varying vec2 tex_pos;
void main() {
gl_FragColor = texture2D(u_texColor, tex_pos) * 0.8;
gl_FragColor = texture2D(u_texColor, tex_pos) * 0.8;
}

View File

@ -10,13 +10,13 @@ varying vec2 tex_sw;
varying vec2 tex_se;
void main() {
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
vec2 pixel = u_pixel * 2.5;
tex_nw = tex_pos + vec2(-1.0, -1.0) * pixel;
tex_ne = tex_pos + vec2(1.0, -1.0) * pixel;
tex_sw = tex_pos + vec2(-1.0, 1.0) * pixel;
tex_se = tex_pos + vec2(1.0, 1.0) * pixel;
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
vec2 pixel = u_pixel * 2.5;
tex_nw = tex_pos + vec2(-1.0, -1.0) * pixel;
tex_ne = tex_pos + vec2(1.0, -1.0) * pixel;
tex_sw = tex_pos + vec2(-1.0, 1.0) * pixel;
tex_se = tex_pos + vec2(1.0, 1.0) * pixel;
}
$$
@ -46,139 +46,138 @@ const float farZ = 8.0;
const int iterations = 2;
float getDepth(float posZ) {
return (2.0 * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));
return (2.0 * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));
}
float compareDepths(in float depth1, in float depth2, inout float far) {
// depth difference (0-100)
float diff = (depth1 - depth2) * 100.0;
// set 'far == 1.0' when 'diff' > 'gdisplace'
far = step(diff, gdisplace);
// gauss bell width 2,
// if far reduce left bell width to avoid self-shadowing
float garea = max((1.0 - far) * 2.0, 0.1);
// depth difference (0-100)
float diff = (depth1 - depth2) * 100.0;
// set 'far == 1.0' when 'diff' > 'gdisplace'
far = step(diff, gdisplace);
// gauss bell width 2,
// if far reduce left bell width to avoid self-shadowing
float garea = max((1.0 - far) * 2.0, 0.1);
//return (step(diff, 0.0) * -0.1) + pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
return pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
//return (step(diff, 0.0) * -0.1) + pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
return pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
}
void addAO(int run, inout float depth, in float x1, in float y1, in float x2, in float y2, inout float ao){
float z_11 = getDepth(texture2D(u_tex, vec2(x1, y1)).x);
float z_12 = getDepth(texture2D(u_tex, vec2(x1, y2)).x);
float z_21 = getDepth(texture2D(u_tex, vec2(x2, y1)).x);
float z_22 = getDepth(texture2D(u_tex, vec2(x2, y2)).x);
void addAO(int run, inout float depth, in float x1, in float y1, in float x2, in float y2, inout float ao) {
float z_11 = getDepth(texture2D(u_tex, vec2(x1, y1)).x);
float z_12 = getDepth(texture2D(u_tex, vec2(x1, y2)).x);
float z_21 = getDepth(texture2D(u_tex, vec2(x2, y1)).x);
float z_22 = getDepth(texture2D(u_tex, vec2(x2, y2)).x);
if (run == 0)
if (run == 0)
depth = 0.5 * depth + (z_11 + z_12 + z_21 + z_22) * (0.25 * 0.5);
float f_11;
float d_11 = compareDepths(depth, z_11, f_11);
float f_11;
float d_11 = compareDepths(depth, z_11, f_11);
float f_12;
float d_12 = compareDepths(depth, z_12, f_12);
float f_12;
float d_12 = compareDepths(depth, z_12, f_12);
float f_21;
float d_21 = compareDepths(depth, z_21, f_21);
float f_21;
float d_21 = compareDepths(depth, z_21, f_21);
float f_22;
float d_22 = compareDepths(depth, z_22, f_22);
float f_22;
float d_22 = compareDepths(depth, z_22, f_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * (1.0 - step(1.0, y1))
* (d_11 + f_11 * (1.0 - d_11) * d_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * (1.0 - step(1.0, y1))
* (d_11 + f_11 * (1.0 - d_11) * d_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * step(0.0, y2)
* (d_12 + f_12 * (1.0 - d_12) * d_21);
ao += 1.0 //(1.0 - step(1.0, x1)) * step(0.0, y2)
* (d_12 + f_12 * (1.0 - d_12) * d_21);
ao += 1.0 //step(0.0, x2) * (1.0 - step(1.0, y1))
* (d_21 + f_21 * (1.0 - d_21) * d_12);
ao += 1.0 //step(0.0, x2) * (1.0 - step(1.0, y1))
* (d_21 + f_21 * (1.0 - d_21) * d_12);
ao += 1.0 //step(0.0, x2) * step(0.0, y2)
* (d_22 + f_22 * (1.0 - d_22) * d_11);
ao += 1.0 //step(0.0, x2) * step(0.0, y2)
* (d_22 + f_22 * (1.0 - d_22) * d_11);
}
void main() {
vec2 pixel = u_pixel * 3.15;
vec2 pixel = u_pixel * 3.15;
vec4 rgbNW = texture2D(u_texColor, tex_nw);
vec4 rgbNE = texture2D(u_texColor, tex_ne);
vec4 rgbSW = texture2D(u_texColor, tex_sw);
vec4 rgbSE = texture2D(u_texColor, tex_se);
vec4 rgbNW = texture2D(u_texColor, tex_nw);
vec4 rgbNE = texture2D(u_texColor, tex_ne);
vec4 rgbSW = texture2D(u_texColor, tex_sw);
vec4 rgbSE = texture2D(u_texColor, tex_se);
vec4 rgbM = texture2D(u_texColor, tex_pos);
vec4 rgbM = texture2D(u_texColor, tex_pos);
if (rgbNW.a + rgbNE.a + rgbSW.a + rgbSE.a < 0.1) {
gl_FragColor = rgbM;
return;
}
//return vec4(rgbM - (rgbNW + rgbNE)*0.25,1.0);
if (rgbNW.a + rgbNE.a + rgbSW.a + rgbSE.a < 0.1) {
gl_FragColor = rgbM;
return;
}
//return vec4(rgbM - (rgbNW + rgbNE)*0.25,1.0);
float lumaNW = dot(rgbNW.rgb, luma);
float lumaNE = dot(rgbNE.rgb, luma);
float lumaSW = dot(rgbSW.rgb, luma);
float lumaSE = dot(rgbSE.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);
float lumaNW = dot(rgbNW.rgb, luma);
float lumaNE = dot(rgbNE.rgb, luma);
float lumaSW = dot(rgbSW.rgb, luma);
float lumaSE = dot(rgbSE.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
//vec4 rgb = texture2D (tex, tex_pos);
//return vec4(0.5 + lumaM - lumaMin, lumaM, 0.5 + lumaM - lumaMax, 1.0) * rgb.a;
//vec4 rgb = texture2D (tex, tex_pos);
//return vec4(0.5 + lumaM - lumaMin, lumaM, 0.5 + lumaM - lumaMax, 1.0) * rgb.a;
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * m_ReduceMul), FXAA_REDUCE_MIN);
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * m_ReduceMul), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (dirReduce + min(abs(dir.x), abs(dir.y)));
float rcpDirMin = 1.0 / (dirReduce + min(abs(dir.x), abs(dir.y)));
dir = min(m_SpanMax, max(-m_SpanMax, dir * rcpDirMin)) * pixel;
dir = min(m_SpanMax, max(-m_SpanMax, dir * rcpDirMin)) * pixel;
vec4 rgbA = 0.5 * (texture2D(u_texColor, tex_pos + dir * vec2(1.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(2.0 / 3.0 - 0.5)));
vec4 rgbA = 0.5 * (texture2D(u_texColor, tex_pos + dir * vec2(1.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(2.0 / 3.0 - 0.5)));
vec4 rgbB = rgbA * 0.5 + 0.25 * (texture2D(u_texColor, tex_pos + dir * vec2(0.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(3.0 / 3.0 - 0.5)));
vec4 rgbB = rgbA * 0.5 + 0.25 * (texture2D(u_texColor, tex_pos + dir * vec2(0.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(3.0 / 3.0 - 0.5)));
float lumaB = dot(rgbB.rgb, luma.rgb);
float lumaB = dot(rgbB.rgb, luma.rgb);
float d = step(lumaB, lumaMin) + step(lumaMax, lumaB);
float d = step(lumaB, lumaMin) + step(lumaMax, lumaB);
vec4 color = (1.0 - d) * rgbB + d * rgbA;
vec4 color = (1.0 - d) * rgbB + d * rgbA;
//vec4 color = texture2D(u_texColor, tex_pos);
//vec4 color = texture2D(u_texColor, tex_pos);
float depth = texture2D(u_tex, tex_pos).x;
float foggy = pow(depth,3.0);
float depth = texture2D(u_tex, tex_pos).x;
float foggy = pow(depth, 3.0);
depth = getDepth(depth);
depth = getDepth(depth);
float x = tex_pos.x;
float y = tex_pos.y;
float pw = u_pixel.x;
float ph = u_pixel.y;
float ao = 0.0;
for (int i = 0; i < iterations; i++) {
float pwByDepth = pw / depth;
float phByDepth = ph / depth;
addAO(i, depth, x + pwByDepth, y + phByDepth, x - pwByDepth, y - phByDepth, ao);
pwByDepth *= 1.2;
phByDepth *= 1.2;
addAO(i, depth, x + pwByDepth, y, x, y - phByDepth, ao);
// sample jittering:
// pw += random.x * 0.0007;
// ph += random.y * 0.0007;
// increase sampling area:
pw *= 1.7;
ph *= 1.7;
float x = tex_pos.x;
float y = tex_pos.y;
float pw = u_pixel.x;
float ph = u_pixel.y;
float ao = 0.0;
for (int i = 0; i < iterations; i++) {
float pwByDepth = pw / depth;
float phByDepth = ph / depth;
addAO(i, depth, x + pwByDepth, y + phByDepth, x - pwByDepth, y - phByDepth, ao);
pwByDepth *= 1.2;
phByDepth *= 1.2;
addAO(i, depth, x + pwByDepth, y, x, y - phByDepth, ao);
// sample jittering:
// pw += random.x * 0.0007;
// ph += random.y * 0.0007;
// increase sampling area:
pw *= 1.7;
ph *= 1.7;
}
}
ao = ao / float(iterations * 8);
ao *= 0.4 * foggy;
ao = clamp(ao, 0.0, 1.0);
ao = ao / float(iterations * 8);
ao *= 0.4 * foggy;
ao = clamp(ao, 0.0, 1.0);
//gl_FragColor = vec4(0.5 - vao, max(0.5, ao));
gl_FragColor = vec4(color.rgb - ao, max(color.a, ao));
//gl_FragColor = vec4(0.5 - vao, max(0.5, ao));
gl_FragColor = vec4(color.rgb - ao, max(color.a, ao));
}

View File

@ -10,13 +10,13 @@ varying vec2 tex_sw;
varying vec2 tex_se;
void main() {
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
vec2 pixel = u_pixel * 2.5;
tex_nw = tex_pos + vec2(-1.0, -1.0) * pixel;
tex_ne = tex_pos + vec2(1.0, -1.0) * pixel;
tex_sw = tex_pos + vec2(-1.0, 1.0) * pixel;
tex_se = tex_pos + vec2(1.0, 1.0) * pixel;
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
vec2 pixel = u_pixel * 2.5;
tex_nw = tex_pos + vec2(-1.0, -1.0) * pixel;
tex_ne = tex_pos + vec2(1.0, -1.0) * pixel;
tex_sw = tex_pos + vec2(-1.0, 1.0) * pixel;
tex_se = tex_pos + vec2(1.0, 1.0) * pixel;
}
$$
@ -39,70 +39,70 @@ const vec3 luma = vec3(0.299, 0.587, 0.114);
#define FXAA_REDUCE_MIN (1.0/128.0)
//float FxaaLuma(float3 rgb) {
// return rgb.g * (0.587/0.299) + rgb.b;
// return rgb.g * (0.587 / 0.299) + rgb.b;
//}
void main() {
vec2 pixel = u_pixel * 3.15;
vec2 pixel = u_pixel * 3.15;
vec4 rgbNW = texture2D(u_texColor, tex_nw);
vec4 rgbNE = texture2D(u_texColor, tex_ne);
vec4 rgbSW = texture2D(u_texColor, tex_sw);
vec4 rgbSE = texture2D(u_texColor, tex_se);
vec4 rgbNW = texture2D(u_texColor, tex_nw);
vec4 rgbNE = texture2D(u_texColor, tex_ne);
vec4 rgbSW = texture2D(u_texColor, tex_sw);
vec4 rgbSE = texture2D(u_texColor, tex_se);
vec4 rgbM = texture2D(u_texColor, tex_pos);
vec4 rgbM = texture2D(u_texColor, tex_pos);
if (rgbNW.a + rgbNE.a + rgbSW.a + rgbSE.a < 0.1) {
gl_FragColor = rgbM;
return;
}
//return vec4(rgbM - (rgbNW + rgbNE)*0.25,1.0);
if (rgbNW.a + rgbNE.a + rgbSW.a + rgbSE.a < 0.1) {
gl_FragColor = rgbM;
return;
}
//return vec4(rgbM - (rgbNW + rgbNE) * 0.25, 1.0);
float lumaNW = dot(rgbNW.rgb, luma);
float lumaNE = dot(rgbNE.rgb, luma);
float lumaSW = dot(rgbSW.rgb, luma);
float lumaSE = dot(rgbSE.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);
float lumaNW = dot(rgbNW.rgb, luma);
float lumaNE = dot(rgbNE.rgb, luma);
float lumaSW = dot(rgbSW.rgb, luma);
float lumaSE = dot(rgbSE.rgb, luma);
float lumaM = dot(rgbM.rgb, luma);
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
float lumaMin = min(lumaM, min(min(lumaNW, lumaNE), min(lumaSW, lumaSE)));
float lumaMax = max(lumaM, max(max(lumaNW, lumaNE), max(lumaSW, lumaSE)));
//vec4 rgb = texture2D (tex, tex_pos);
//return vec4(0.5 + lumaM - lumaMin, lumaM, 0.5 + lumaM - lumaMax, 1.0) * rgb.a;
//vec4 rgb = texture2D (tex, tex_pos);
//return vec4(0.5 + lumaM - lumaMin, lumaM, 0.5 + lumaM - lumaMax, 1.0) * rgb.a;
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
vec2 dir;
dir.x = -((lumaNW + lumaNE) - (lumaSW + lumaSE));
dir.y = ((lumaNW + lumaSW) - (lumaNE + lumaSE));
// if (max(dir.x, dir.y) > 0.1){
// gl_FragColor = vec4(dir*0.5, 0.0, 0.5);
// } else{
// gl_FragColor = vec4(rgbM.rgb * 0.2, 0.8);
// if (max(dir.x, dir.y) > 0.1) {
// gl_FragColor = vec4(dir*0.5, 0.0, 0.5);
// } else {
// gl_FragColor = vec4(rgbM.rgb * 0.2, 0.8);
// }
// return;
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * m_ReduceMul), FXAA_REDUCE_MIN);
float dirReduce = max((lumaNW + lumaNE + lumaSW + lumaSE) * (0.25 * m_ReduceMul), FXAA_REDUCE_MIN);
float rcpDirMin = 1.0 / (dirReduce + min(abs(dir.x), abs(dir.y)));
float rcpDirMin = 1.0 / (dirReduce + min(abs(dir.x), abs(dir.y)));
dir = min(m_SpanMax, max(-m_SpanMax, dir * rcpDirMin)) * pixel;
dir = min(m_SpanMax, max(-m_SpanMax, dir * rcpDirMin)) * pixel;
vec4 rgbA = 0.5 * (texture2D(u_texColor, tex_pos + dir * vec2(1.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(2.0 / 3.0 - 0.5)));
vec4 rgbA = 0.5 * (texture2D(u_texColor, tex_pos + dir * vec2(1.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(2.0 / 3.0 - 0.5)));
vec4 rgbB = rgbA * 0.5 + 0.25 * (texture2D(u_texColor, tex_pos + dir * vec2(0.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(3.0 / 3.0 - 0.5)));
vec4 rgbB = rgbA * 0.5 + 0.25 * (texture2D(u_texColor, tex_pos + dir * vec2(0.0 / 3.0 - 0.5))
+ texture2D(u_texColor, tex_pos + dir * vec2(3.0 / 3.0 - 0.5)));
float lumaB = dot(rgbB.rgb, luma.rgb);
float lumaB = dot(rgbB.rgb, luma.rgb);
float d = step(lumaB, lumaMin) + step(lumaMax, lumaB);
float d = step(lumaB, lumaMin) + step(lumaMax, lumaB);
gl_FragColor = (1.0 - d) * rgbB + d * rgbA;
gl_FragColor = (1.0 - d) * rgbB + d * rgbA;
//gl_FragColor = vec4(rgbM.rgb * 0.5, 1.0) + vec4(((1.0 - d) * rgbB.rgb + d * rgbA.rgb) - rgbM.rgb, 1.0) * 2.0;
//gl_FragColor = vec4(rgbM.rgb * 0.5, 1.0) + vec4(((1.0 - d) * rgbB.rgb + d * rgbA.rgb) - rgbM.rgb, 1.0) * 2.0;
// if ((lumaB < lumaMin) || (lumaB > lumaMax))
// { return rgbA; } else { return rgbB; }
//if ((lumaB < lumaMin) || (lumaB > lumaMax))
// { return rgbA; } else { return rgbB; }
}
//vec2 rcpFrame = vec2(1.0) / g_Resolution;

View File

@ -6,8 +6,8 @@ attribute vec4 a_pos;
varying vec2 tex_pos;
void main() {
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
gl_Position = a_pos;
tex_pos = (a_pos.xy + 1.0) * 0.5;
}
$$
@ -27,116 +27,111 @@ const float farZ = 4.0;
const int iterations = 4;
float getDepth(float posZ) {
return (2.0 * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));
return (2.0 * nearZ) / (nearZ + farZ - posZ * (farZ - nearZ));
}
float compareDepths(in float depth1, in float depth2, inout float far) {
// depth difference (0-100)
float diff = (depth1 - depth2) * 100.0;
// set 'far == 1.0' when 'diff' > 'gdisplace'
far = step(diff, gdisplace);
// gauss bell width 2,
// if far reduce left bell width to avoid self-shadowing
float garea = max((1.0 - far) * 2.0, 0.1);
// depth difference (0-100)
float diff = (depth1 - depth2) * 100.0;
// set 'far == 1.0' when 'diff' > 'gdisplace'
far = step(diff, gdisplace);
// gauss bell width 2,
// if far reduce left bell width to avoid self-shadowing
float garea = max((1.0 - far) * 2.0, 0.1);
//return (step(diff, 0.0) * -0.1) + pow(2.7182, -2.0 * pow(diff - gdisplace, 2.0) / pow(garea, 2.0));
return pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
//return (step(diff, 0.0) * -0.1) + pow(2.7182, -2.0 * pow(diff - gdisplace, 2.0) / pow(garea, 2.0));
return pow(2.7182, -2.0 * pow(diff - gdisplace,2.0) / pow(garea, 2.0));
}
void addAO(in float depth, in float x1, in float y1, in float x2, in float y2, inout float ao){
float z_11 = getDepth(texture2D(u_tex, vec2(x1, y1)).x);
float z_12 = getDepth(texture2D(u_tex, vec2(x1, y2)).x);
float z_21 = getDepth(texture2D(u_tex, vec2(x2, y1)).x);
float z_22 = getDepth(texture2D(u_tex, vec2(x2, y2)).x);
//depth = 0.99 * depth + (z_11 + z_12 + z_21 + z_22) * (0.25 * 0.01);
void addAO(in float depth, in float x1, in float y1, in float x2, in float y2, inout float ao) {
float z_11 = getDepth(texture2D(u_tex, vec2(x1, y1)).x);
float z_12 = getDepth(texture2D(u_tex, vec2(x1, y2)).x);
float z_21 = getDepth(texture2D(u_tex, vec2(x2, y1)).x);
float z_22 = getDepth(texture2D(u_tex, vec2(x2, y2)).x);
//depth = 0.99 * depth + (z_11 + z_12 + z_21 + z_22) * (0.25 * 0.01);
float f_11;
float d_11 = compareDepths(depth, z_11, f_11);
float f_11;
float d_11 = compareDepths(depth, z_11, f_11);
float f_12;
float d_12 = compareDepths(depth, z_12, f_12);
float f_12;
float d_12 = compareDepths(depth, z_12, f_12);
float f_21;
float d_21 = compareDepths(depth, z_21, f_21);
float f_21;
float d_21 = compareDepths(depth, z_21, f_21);
float f_22;
float d_22 = compareDepths(depth, z_22, f_22);
float f_22;
float d_22 = compareDepths(depth, z_22, f_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * (1.0 - step(1.0, y1))
* (d_11 + f_11 * (1.0 - d_11) * d_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * (1.0 - step(1.0, y1))
* (d_11 + f_11 * (1.0 - d_11) * d_22);
ao += 1.0 //(1.0 - step(1.0, x1)) * step(0.0, y2)
* (d_12 + f_12 * (1.0 - d_12) * d_21);
ao += 1.0 //(1.0 - step(1.0, x1)) * step(0.0, y2)
* (d_12 + f_12 * (1.0 - d_12) * d_21);
ao += 1.0 //step(0.0, x2) * (1.0 - step(1.0, y1))
* (d_21 + f_21 * (1.0 - d_21) * d_12);
ao += 1.0 //step(0.0, x2) * (1.0 - step(1.0, y1))
* (d_21 + f_21 * (1.0 - d_21) * d_12);
ao += 1.0 //step(0.0, x2) * step(0.0, y2)
* (d_22 + f_22 * (1.0 - d_22) * d_11);
ao += 1.0 //step(0.0, x2) * step(0.0, y2)
* (d_22 + f_22 * (1.0 - d_22) * d_11);
}
void main() {
// randomization texture:
// vec2 fres = vec2(20.0, 20.0);
// vec3 random = texture2D(rand, gl_TexCoord[0].st * fres.xy);
// random = random * 2.0 - vec3(1.0);
vec4 color = texture2D(u_texColor, tex_pos);
float depth = texture2D(u_tex, tex_pos).x;
//randomization texture:
//vec2 fres = vec2(20.0, 20.0);
//vec3 random = texture2D(rand, gl_TexCoord[0].st * fres.xy);
//random = random * 2.0 - vec3(1.0);
vec4 color = texture2D(u_texColor, tex_pos);
float depth = texture2D(u_tex, tex_pos).x;
float fog = pow(depth, 3.0);
//return;
depth = getDepth(depth);
float fog = pow(depth, 3.0);
//return;
depth = getDepth(depth);
float x = tex_pos.x;
float y = tex_pos.y;
float pw = u_pixel.x;
float ph = u_pixel.y;
float ao = 0.0;
float x = tex_pos.x;
float y = tex_pos.y;
float pw = u_pixel.x;
float ph = u_pixel.y;
float ao = 0.0;
for (int i = 0; i < iterations; i++) {
float pwByDepth = pw / depth;
float phByDepth = ph / depth;
addAO(depth, x + pwByDepth, y + phByDepth, x - pwByDepth, y - phByDepth, ao);
pwByDepth *= 1.2;
phByDepth *= 1.2;
addAO(depth, x + pwByDepth, y, x, y - phByDepth, ao);
// sample jittering:
// pw += random.x * 0.0007;
// ph += random.y * 0.0007;
// increase sampling area:
pw *= 1.7;
ph *= 1.7;
for (int i = 0; i < iterations; i++) {
float pwByDepth = pw / depth;
float phByDepth = ph / depth;
addAO(depth, x + pwByDepth, y + phByDepth, x - pwByDepth, y - phByDepth, ao);
pwByDepth *= 1.2;
phByDepth *= 1.2;
addAO(depth, x + pwByDepth, y, x, y - phByDepth, ao);
// sample jittering:
// pw += random.x * 0.0007;
// ph += random.y * 0.0007;
// increase sampling area:
pw *= 1.7;
ph *= 1.7;
}
}
//vec3 vao = vec3(fog * pow(ao / float(iterations * 8), 1.2));
ao = ao / float(iterations * 8);
ao *= 0.2;
ao = clamp(ao, 0.0, 1.0);
//vec3 vao = vec3(fog * pow(ao / float(iterations * 8), 1.2));
ao = ao / float(iterations * 8);
ao *= 0.2;
ao = clamp(ao, 0.0, 1.0);
vec3 vao = vec3(ao);
vec3 vao = vec3(ao);
//gl_FragColor = vec4(0.5 - vao, max(0.5, ao));
gl_FragColor = vec4(color.rgb - ao, max(color.a, ao));
//gl_FragColor = vec4(0.5 - vao, max(0.5, ao));
gl_FragColor = vec4(color.rgb - ao, max(color.a, ao));
//gl_FragColor = color - (fog * vec4(vao, 0.0));
//gl_FragColor = vec4(vec3(0.8) - vao, 1.0);
//gl_FragColor = color - (fog * vec4(vao, 0.0));
//color *= 0.5;
//gl_FragColor = vec4(color.rgb - fog * vao, max(color.a, ao));
//gl_FragColor = vec4(vec3(0.8) - vao, 1.0);
//gl_FragColor = vec4(1.0) - (vec4(vao, 0.0));
//gl_FragColor = vec4((color.rgb + vao)*0.5, color.a);
//color *= 0.5;
//gl_FragColor = vec4(color.rgb - fog * vao, max(color.a, ao));
//gl_FragColor = vec4(1.0) - (vec4(vao, 0.0));
//gl_FragColor = vec4((color.rgb + vao)*0.5, color.a);
// }
// gl_FragColor = vec4(vao, 1.0) * texture2D(u_texColor, tex_pos.xy);
// gl_FragColor = vec4(gl_TexCoord[0].xy, 0.0, 1.0);
// gl_FragColor = vec4(tex_pos.xy, 0.0, 1.0);
// gl_FragColor = vec4(gl_FragCoord.xy / u_screen, 0.0, 1.0);
//}
//gl_FragColor = vec4(vao, 1.0) * texture2D(u_texColor, tex_pos.xy);
//gl_FragColor = vec4(gl_TexCoord[0].xy, 0.0, 1.0);
//gl_FragColor = vec4(tex_pos.xy, 0.0, 1.0);
//gl_FragColor = vec4(gl_FragCoord.xy / u_screen, 0.0, 1.0);
}

View File

@ -7,8 +7,8 @@ uniform mat4 u_mvp;
varying vec2 tex_c;
void main() {
gl_Position = u_mvp * vec4(vertex, 0.0, 1.0);
tex_c = tex_coord;
gl_Position = u_mvp * vec4(vertex, 0.0, 1.0);
tex_c = tex_coord;
}
$$
@ -21,5 +21,5 @@ uniform float u_alpha;
varying vec2 tex_c;
void main() {
gl_FragColor = texture2D(tex, tex_c) * u_alpha;
gl_FragColor = texture2D(tex, tex_c) * u_alpha;
}

View File

@ -11,18 +11,17 @@ uniform vec2 u_div;
varying vec2 tex_c;
void main() {
vec4 pos;
vec2 dir = vertex.zw;
float coord_scale = 1.0 / u_coord_scale;
if (abs(mod(vertex.x, 2.0)) == 0.0) {
pos = u_proj * (u_mv * vec4(vertex.xy + dir * u_scale, 0.0, 1.0));
}
else { // place as billboard
vec4 center = u_mv * vec4(vertex.xy, 0.0, 1.0);
pos = u_proj * (center + vec4(dir * coord_scale, 0.0, 0.0));
}
gl_Position = pos;
tex_c = tex_coord * u_div;
vec4 pos;
vec2 dir = vertex.zw;
float coord_scale = 1.0 / u_coord_scale;
if (abs(mod(vertex.x, 2.0)) == 0.0) {
pos = u_proj * (u_mv * vec4(vertex.xy + dir * u_scale, 0.0, 1.0));
} else { // place as billboard
vec4 center = u_mv * vec4(vertex.xy, 0.0, 1.0);
pos = u_proj * (center + vec4(dir * coord_scale, 0.0, 0.0));
}
gl_Position = pos;
tex_c = tex_coord * u_div;
}
$$
@ -34,5 +33,5 @@ uniform sampler2D tex;
varying vec2 tex_c;
void main() {
gl_FragColor = texture2D(tex, tex_c.xy);
gl_FragColor = texture2D(tex, tex_c.xy);
}