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

This commit is contained in:
2019-06-19 10:50:20 +00:00
parent 246e3e258c
commit 7eb0919657
16 changed files with 396 additions and 94 deletions

47
qglview/shaders/dof.frag Normal file
View File

@@ -0,0 +1,47 @@
#version 150
uniform float z_near, z_far;
uniform sampler2D t0, td;
uniform vec2 dt;
uniform float radius, focus, diaphragm;
float w, sum;
const float _pe = 2.4e-7;
vec4 getTexel(vec2 c, float coeff) {
vec4 ret = texture(t0, c);
float cw = texture(td, c).r;
cw = clamp(1. - abs(cw - w) * 1000, 0., 1.) * coeff;
sum += cw;
return ret * cw;
}
void main(void) {
vec2 tc = qgl_FragTexture.xy;
vec4 scol = texture(t0, tc);
w = texture(td, tc).r;
float z = w + w - 1;
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
z = 1./(z + 1);
float cf = 1./(focus + 1);
float factor = clamp(abs(z - cf) * diaphragm, 0, 100);
factor = 1. - 1. / (factor + 1.);
factor *= factor;
factor *= factor;
//factor *= factor;
factor *= radius;
vec2 cdt = factor * dt;
sum = 1.;
scol += getTexel(tc + (cdt * 1), 2.5);
scol += getTexel(tc + (cdt * 2), 2.0);
scol += getTexel(tc + (cdt * 3), 1.5);
scol += getTexel(tc + (cdt * 4), 1.0);
scol += getTexel(tc + (cdt * 5), 0.5);
scol += getTexel(tc + (cdt * -1), 2.5);
scol += getTexel(tc + (cdt * -2), 2.0);
scol += getTexel(tc + (cdt * -3), 1.5);
scol += getTexel(tc + (cdt * -4), 1.0);
scol += getTexel(tc + (cdt * -5), 0.5);
scol /= sum;
qgl_FragData[0].rgba = scol;
}

6
qglview/shaders/dof.vert Normal file
View File

@@ -0,0 +1,6 @@
#version 150
void main(void) {
qgl_FragTexture = qgl_Texture;
gl_Position = qgl_ftransform();
}

View File

@@ -22,9 +22,11 @@ void main(void) {
float hei = dot(texture(qgl_Material.map_relief.map, tc).rgb, luma) * qgl_Material.map_relief.amount + qgl_Material.map_relief.offset;
vec3 n, dn, bn;
dn = (texture(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.)) * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
dn = texture(qgl_Material.map_normal.map, tc).rgb - vec3(0.5, 0.5, 1.);
dn = dn * qgl_Material.map_normal.amount + qgl_Material.map_normal.offset;
dn.y = -dn.y;
dn = TBN * dn;
//dn.z = 0;
n = normalize(qgl_NormalMatrix * (normal + dn));
bn = normalize(qgl_NormalMatrix * binormal);
//n = dn;

View File

@@ -34,57 +34,55 @@ void calcLight(in int index, in vec3 n, in vec3 v, in vec4 v2) {
ldist = length(ldir);
ldir = normalize(ldir);
halfV = normalize(ldir + v);
NdotL = max(dot(n, ldir), 0.);
NdotH = max(dot(n, halfV), 0.);
NdotL = max(dot(n, ldir), 0.0001);
NdotH = max(dot(n, halfV), 0.0001);
spot = step(0., NdotL) * qgl_Light[index].intensity;
if (NdotL > 0.) {
if (qgl_Light[index].endAngle <= 90.) {
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
//bn2 = normalize(cross(lwdir, bn));
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
//spot *= clamp(1. - sdist, 0, 1);
vds = ds * bn.xyz;
vds2 = ds * bn2.xyz;
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
getShadow(index, pos.xyz, vds ) * 2. +
getShadow(index, pos.xyz, - vds ) * 2. +
getShadow(index, pos.xyz, - vds2 ) * 2. +
getShadow(index, pos.xyz, + vds2 ) * 2. +
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds ) +
getShadow(index, pos.xyz, - vds - vds ) +
getShadow(index, pos.xyz, - vds2 - vds2) +
getShadow(index, pos.xyz, + vds2 + vds2) +
getShadow(index, pos.xyz, vds + vds - vds2 ) +
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
getShadow(index, pos.xyz, vds + vds + vds2 ) +
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
getShadow(index, pos.xyz, vds - vds2 - vds2) +
getShadow(index, pos.xyz, vds + vds2 + vds2) +
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
getShadow(index, pos.xyz, - vds + vds2 + vds2);
spot *= mix(1., shadow / 29., shadow_on);
}
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
float NdotLs = NdotL*NdotL;
float NdotHs = NdotH*NdotH;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (sh_mul + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
ndlc = (1. - NdotHs) / NdotHs;
der = NdotHs * (sh_mul + ndlc);
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
if (qgl_Light[index].endAngle <= 90.) {
float scos = max(dot(-ldir, qgl_Light[index].direction.xyz), 0.);
spot *= scos * step(qgl_Light[index].endAngleCos, scos);
spot *= smoothstep(qgl_Light[index].endAngleCos, qgl_Light[index].startAngleCos, scos);
lwdir = mat3(mat_viewi) * qgl_Light[index].direction.xyz;
//bn = normalize(cross(lwdir, vec3(1, 0, 0)));
//bn2 = normalize(cross(lwdir, bn));
float ds = ldist/200.;//max(abs(sdist) / 5000, 0.02);
//spot *= clamp(1. - sdist, 0, 1);
vds = ds * bn.xyz;
vds2 = ds * bn2.xyz;
float shadow = getShadow(index, pos.xyz, vec3(0)) * 3. +
getShadow(index, pos.xyz, vds ) * 2. +
getShadow(index, pos.xyz, - vds ) * 2. +
getShadow(index, pos.xyz, - vds2 ) * 2. +
getShadow(index, pos.xyz, + vds2 ) * 2. +
getShadow(index, pos.xyz, vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds - vds2 ) * 1.5 +
getShadow(index, pos.xyz, - vds + vds2 ) * 1.5 +
getShadow(index, pos.xyz, vds + vds ) +
getShadow(index, pos.xyz, - vds - vds ) +
getShadow(index, pos.xyz, - vds2 - vds2) +
getShadow(index, pos.xyz, + vds2 + vds2) +
getShadow(index, pos.xyz, vds + vds - vds2 ) +
getShadow(index, pos.xyz, - vds - vds - vds2 ) +
getShadow(index, pos.xyz, vds + vds + vds2 ) +
getShadow(index, pos.xyz, - vds - vds + vds2 ) +
getShadow(index, pos.xyz, vds - vds2 - vds2) +
getShadow(index, pos.xyz, vds + vds2 + vds2) +
getShadow(index, pos.xyz, - vds - vds2 - vds2) +
getShadow(index, pos.xyz, - vds + vds2 + vds2);
spot *= mix(1., shadow / 29., shadow_on);
}
spot /= (qgl_Light[index].constantAttenuation + ldist * (qgl_Light[index].linearAttenuation + ldist * qgl_Light[index].quadraticAttenuation));
///li += spot * gl_LightSource[index].diffuse.rgb * light_diffuse(0, ldir, n);
//si += spot * qgl_Light[index].color.rgb * sh_mul * light_specular(0, ldir, n, halfV, v, sh_pow);
float NdotLs = NdotL*NdotL;
float NdotHs = NdotH*NdotH;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (sh_mul + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - sh_mul) * ndlc));
li += spot * qgl_Light[index].color.rgb * diff;// * light_diffuse(0, ldir, n);
ndlc = (1. - NdotHs) / NdotHs;
der = NdotHs * (sh_mul + ndlc);
si += spot * qgl_Light[index].color.rgb * (sh_mul / (der*der) / 3.1416);
}

View File

@@ -173,6 +173,7 @@ void main(void) {
}
if (acc_fog)
color.rgb = mix(color.rgb, gl_Fog.color.rgb, fogCoord);
color.r = 250;
gl_FragColor = color;
//gl_FragColor.rgb = mix(ldir, texture2D(t2, sp).rgb, 1. - alpha);
}

View File

@@ -13,8 +13,8 @@ void main(void) {
vec4 ds3 = abs(texelFetchOffset(t0, tc, 0, ivec2(0, 1)) - selected);
float d0 = dot(ds0, vec4(1., 1., 1., 1.)), d1 = dot(ds1, vec4(1., 1., 1., 1.)), d2 = dot(ds2, vec4(1., 1., 1., 1.)), d3 = dot(ds3, vec4(1., 1., 1., 1.));
float vs = step(1e-6, d0 + d1 + d2 + d3);
float vm = step(1e-3, (d0 * 255.) * (d1 * 255.) * (d2 * 255.) * (d3 * 255.));
float vm = step(1e-3, (d0 * 25.) * (d1 * 25.) * (d2 * 255.) * (d3 * 255.));
float v = mix(vs - vm, vs - vm - vm + 1, fill);
//qgl_FragData[0] = vec4(1,0,0,0.5);//vec4(color.rgb, v * color.a);
qgl_FragData[0] = vec4(color.rgb, v * color.a);
qgl_FragData[0] = vec4(color.bgr, v * color.a);
}

View File

@@ -1,9 +0,0 @@
#version 200
//in vec3 src_normal, normal, et;
in vec3 wpos;
void main(void) {
//vec2 tc = gl_TexCoord[0].xy;
gl_FragColor.xyz = wpos * 1E+6;
}

View File

@@ -1,13 +0,0 @@
#version 300 core
layout(triangles, invocations = 1) in;
//in vec3 normal[];
void main() {
for (int i = 0; i < gl_in.length(); i++ ) {
gl_Position = gl_in[i].gl_Position;
EmitVertex();
}
EndPrimitive();
}

View File

@@ -1,11 +0,0 @@
#version 300 core
//in vec3 src_normal, normal, et;
out vec3 wpos;
void main(void) {
//vec2 tc = gl_TexCoord[0].xy;
wpos = gl_Vertex.xyz;
//gl_TexCoord[0] = gl_MultiTexCoord0;
gl_Position = ftransform();
}