git-svn-id: svn://db.shs.com.ru/libs@75 a8b55f48-bf90-11e4-a774-851b48703e85

This commit is contained in:
2016-01-18 14:41:29 +00:00
parent 5b523a65ae
commit d88b341070
28 changed files with 539 additions and 112 deletions

View File

@@ -16,7 +16,7 @@ const vec3 luma = vec3(0.299, 0.587, 0.114);
void main(void) {
//float z = pos.w;//((z_near / (z_near-z_far)) * z_far) / (pos.w - (z_far / (z_far-z_near)));
float logz = log(pos.w * C + 1.) * FC;
//float logz = log(pos.w * C + 1.) * FC;
vec4 dc = qgl_FragColor;
vec2 tc = qgl_FragTexture.xy;
float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
@@ -44,7 +44,7 @@ void main(void) {
//speed /= abs(pos.z);
//gl_FragDepth = logz;
qgl_FragData[0] = vec4(dc.rgb, pos.w);
qgl_FragData[0] = vec4(dc.rgb, 0.);
qgl_FragData[1] = vec4(n.xyz, specularity + round(reflectivity * 100));
qgl_FragData[2] = vec4(spec.rgb, hei);
qgl_FragData[3] = vec4(self.rgb, bn.x);

View File

@@ -24,7 +24,7 @@ float sh_pow, sh_mul, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow;
float getShadow(int light, vec3 view_pos, vec3 dpos) {
shp = qgl_Light[light].shadowMatrix * vec4(view_pos + dpos, 1);
shp.z -= 0.05;
shp.z -= z_near / 20.;
return textureProj(qgl_Light[light].shadow, shp);
}
@@ -87,18 +87,26 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
}
}
const float _pe = 2.4e-7;
void main(void) {
//if (d == 1.) discard;
ivec2 tc = ivec2(gl_FragCoord.xy);
vec4 v0 = texelFetch(t0, tc, 0);
if (v0.w == 0.) {
float z = texelFetch(td, tc, 0).r;
if (z == 1.) {
qgl_FragData[0] = back_color;
return;
}
vec4 v1 = texelFetch(t1, tc, 0),
vec4 v0 = texelFetch(t0, tc, 0),
v1 = texelFetch(t1, tc, 0),
v2 = texelFetch(t2, tc, 0),
v3 = texelFetch(t3, tc, 0),
v4 = texelFetch(t4, tc, 0);
z = z + z - 1;
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
vec2 sp = gl_FragCoord.xy * dt * 2 - vec2(1, 1);
vec3 dc = v0.rgb, n = v1.xyz;
bn = normalize(vec3(v3.w, v4.zw));
@@ -113,7 +121,7 @@ void main(void) {
pos.z = posz;*/
pos.w = 1;
pos.xyz = view_dir * v0.w;
pos.xyz = view_dir * z;
pos.z = -pos.z;
//pos.z = posz;
@@ -133,10 +141,10 @@ void main(void) {
sh_mul = max(1. - specularity, 0.0001);
for (int i = 0; i < 8; ++i)
calcLight(i, n, v, v2);
calcLight(0, n, v, v2);
// calcLight(0, n, v, v2);
qgl_FragData[0] = vec4(max(vec3(0), li * dc + si * v2.rgb + v3.rgb + texelFetch(t_pp, tc, 0).rgb), v0.w);
//qgl_FragData[0].rgb = vec3(abs((v0.w)/50));
//qgl_FragData[0].rgb = vec3(-z);
//qgl_FragData[0].rgb = li + vec3(texelFetch(t_pp, tc, 0).xyz);
//shd = shd - shp.w;

View File

@@ -1,10 +1,7 @@
#version 150
in float logz;
uniform vec4 id;
void main(void) {
gl_FragDepth = logz;
qgl_FragData[0] = id;
}

View File

@@ -1,14 +1,8 @@
#version 150
out float logz;
uniform float z_near, z_far;
const float C = 0.0001;
float FC = 1. / log(z_far * C + 1.);
void main(void) {
vec4 pos = qgl_ftransform();
logz = log(pos.w * C + 1.) * FC;
gl_Position = pos;
}

View File

@@ -1,20 +1,26 @@
#version 150
uniform sampler2D t0, t1, ts, tbs;
uniform sampler2D t0, t1, ts, td, tbs;
uniform float z_near, z_far;
uniform mat4 mat_proj;
uniform vec3 cam_aim, cam_pos;
in vec3 view_dir;
const float _pe = 2.4e-7;
void main(void) {
ivec2 tc = ivec2(gl_FragCoord.xy);
vec4 v0 = texelFetch(t0, tc, 0), v1 = texelFetch(t1, tc, 0), vs = texelFetch(ts, tc, 0);
vec3 sp = vec3(qgl_FragTexture.xy, v0.w);
vec2 tsp;
vec4 pos;
float z = texelFetch(td, tc, 0).r;
z = z + z - 1;
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
pos.w = 1;
pos.xyz = view_dir * v0.w;
pos.xyz = view_dir * z;
//pos.z = -pos.z;
vec4 spos = pos;
vec4 tpos;
@@ -22,9 +28,11 @@ void main(void) {
vec3 vd = -normalize(vec3(-view_dir.xy, view_dir.z));
vec3 rn = reflect(vd, n);
//rn.z += 1.;
float coeff = clamp(1. - (dot(vec3(0,0,1), n)), 0, 1), cz = v0.w;
float coeff = clamp(1. - (dot(vec3(0,0,1), n)), 0, 1);
coeff = coeff*coeff;
/*coeff = coeff*coeff;
coeff = coeff*coeff;
coeff = coeff*coeff;*/
float reflectivity = 0.;
float specularity = modf(v1.w, reflectivity);
@@ -33,12 +41,15 @@ void main(void) {
vec4 tv0;
float l = z_far * 0.5;
pos.xyz += rn * l;
for (i = 0; i < 20; ++i) {
float cz;
for (i = 0; i < 24; ++i) {
tpos = mat_proj * pos;
tsp = -(tpos.xy / tpos.w) / 2. + 0.5;
tv0 = texture(t0, tsp);
cz = texture(td, tsp).r;
cz = cz + cz - 1;
cz = ((_pe - 2.) * z_near) / (cz + _pe - 1.); // infinite depth
l *= 0.5;
pos.xyz += rn * (step(pos.z, tv0.w) * 2. - 1.) * l;
pos.xyz += rn * (step(pos.z, cz) * 2. - 1.) * l;
}
vec2 ess = abs(tsp - vec2(0.5, 0.5)) - vec2(0.3, 0.3);
@@ -52,4 +63,5 @@ void main(void) {
vec3 rvs = texture(ts, tsp).rgb;
qgl_FragData[0] = vec4(rvs.rgb, coeff / 1.1 + clamp(round(blur * 10), 0, 1000));
//qgl_FragData[0] = vec4(rvs.rgb, cz/5);
}

View File

@@ -9,7 +9,7 @@ void main(void) {
float r = float(radius);
vec4 v0 = texture(t0, tc);
float rad;
float coeff = modf(v0.a, rad) * 1.1;
float coeff = modf(v0.w, rad) * 1.1;
rad /= 10.;
rad *= 2;
float o = radius * rad, o2 = radius * rad * 2;

View File

@@ -6,10 +6,10 @@ void main(void) {
ivec2 tc = ivec2(gl_FragCoord.xy);
vec4 v0 = texelFetch(t0, tc, 0), vg1 = texelFetch(tg1, tc, 0), vs = texelFetch(ts, tc, 0);
float rad;
float coeff = clamp(modf(v0.a, rad) * 1.1, 0., 1.);
float coeff = clamp(modf(v0.w, rad) * 1.1, 0., 1.);
float reflectivity = 0.;
float specularity = modf(vg1.w, reflectivity);
reflectivity = clamp(reflectivity / 100., 0., 1.);
qgl_FragData[0].rgb = mix(vs.rgb, v0.rgb, coeff * reflectivity);
//qgl_FragData[0].rgb = vec3(vs.rgb*coeff * reflectivity);
//qgl_FragData[0].rgb = vec3(v0.w);
}