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

@@ -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);
}