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

This commit is contained in:
2019-12-13 23:15:59 +00:00
parent cac73a63f1
commit 2136b4d30b
22 changed files with 653 additions and 671 deletions

View File

@@ -42,7 +42,8 @@ void main(void) {
dn *= dn_sl / (length(dn) + 1E-6);
normal = normalize(geom_normal + dn);
vec4 specular = qgl_materialTexture(QGL_MAP_SPECULAR, tc, vec4(0)) * qgl_material[qgl_MaterialIndex].color_specular;
float metalness = dot(qgl_materialTexture(QGL_MAP_METALNESS, tc, vec4(0)).rgb, luma);
metalness = clamp(metalness, 0, 1);
float roughness = dot(qgl_materialTexture(QGL_MAP_ROUGHNESS, tc, vec4(0)).rgb, luma);
roughness = clamp(roughness, 0.0001, 0.9999);
@@ -60,8 +61,8 @@ void main(void) {
qgl_FragData[0] = vec4(diffuse .rgba);
qgl_FragData[1] = vec4(normal .xyz, z);
qgl_FragData[2] = vec4(specular.rgb, reflectivity);
qgl_FragData[3] = vec4(emission.rgb, roughness/*bn.x*/);
qgl_FragData[2] = vec4(metalness, roughness, reflectivity, 0);
qgl_FragData[3] = vec4(emission.rgb, 0/*bn.x*/);
//qgl_FragData[4] = vec4(speed.xy, bn.yz);
//ivec2 itc = ivec2(gl_FragCoord.xy);

View File

@@ -5,6 +5,7 @@ out vec3 view_dir;
uniform vec4 view_corners[4];
void main(void) {
qgl_FragTexture = qgl_Texture;
gl_Position = qgl_ftransform();
view_dir = view_corners[gl_VertexID].xyz;
}
@@ -16,6 +17,7 @@ in vec3 view_dir;
uniform vec2 dt;
uniform float z_near;
uniform sampler2D tex_coeffs[2];
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4;
uniform int lights_start, lights_count;
@@ -23,12 +25,12 @@ uniform vec4 fog_color = vec4(0.5, 0.5, 0.5, 1);
uniform float fog_decay = 10, fog_density = 0;
const vec3 luma = vec3(0.299, 0.587, 0.114);
const float _pe = 2.4e-7, _min_rough = 1.e-8;
const float _min_rough = 1.e-8;
vec4 pos, lpos, shp;
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
//vec3 vds, vds2;
float shm_diff, shm_spec, dist, NdotL, NdotH, spot, ldist, diff, sdist, shadow;
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow;
void calcLight(in int index, in vec3 n, in vec3 v) {
lpos = qgl_light_position[index].position;
@@ -77,17 +79,20 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
#endif
vec3 dist_decay = vec3(1, ldist, ldist*ldist);
spot /= dot(qgl_light_parameter[index].decay_intensity.xyz, dist_decay);
float NdotLs = NdotL*NdotL;
float NdotHs = NdotH*NdotH;
float ndlc = (1. - NdotLs) / NdotLs;
float der = NdotLs * (shm_diff + ndlc);
diff = 2. / (1. + sqrt(1. + (1. - shm_diff) * ndlc));
diff = 2. / (1. + sqrt(1. + (1. - rough_diff) * ndlc));
//diff = texture(tex_coeffs[0], vec2(roughness, (NdotLs))).r;
li += spot * diff * qgl_light_parameter[index].color.rgb;
ndlc = (1. - NdotHs) / NdotHs;
der = NdotHs * (shm_spec + ndlc);
si += spot * (shm_spec / (der*der) / 3.1416) * qgl_light_parameter[index].color.rgb;
float der = NdotHs * (rough_spec + ndlc);
spec = rough_spec / (der*der) / 3.1416;
//spec = texture(tex_coeffs[1], vec2(roughness, (NdotHs))).r;
si += spot * spec * qgl_light_parameter[index].color.rgb;
}
void main(void) {
@@ -95,8 +100,7 @@ void main(void) {
vec4 v1 = texelFetch(tex_1, tc, 0);
float z = v1.w;
if (z == 1.) {
qgl_FragColor = vec4(fog_color.rgb, 0);
return;
discard;
}
pos.w = 1;
pos.xyz = view_dir * z;
@@ -109,23 +113,25 @@ void main(void) {
vec3 diffuse = v0.rgb;
vec3 normal = v1.xyz;
vec3 specular = v2.rgb;
vec3 emission = v3.rgb;
float alpha = v0.a;
float reflectivity = v2.w;
float roughness = v3.w;
float metalness = v2.r;
float roughness = v2.g;
float reflectivity = v2.b;
//bn = normalize(vec3(v3.w, v4.zw));
//bn2 = normalize(cross(n, bn));
roughness = max(roughness, _min_rough);
rough_diff = max(roughness, _min_rough);
rough_spec = max(roughness*roughness*roughness, _min_rough);
float shlick = clamp(metalness + (1 - metalness) * pow(1 - dot(normal, v), 5), 0, 1);
shm_diff = roughness;
shm_spec = max(roughness*roughness*roughness, _min_rough);
//sh_pow = 1. / max(roughness, 0.00001);
li = vec3(0.);//qgl_AmbientLight.color.rgb * qgl_AmbientLight.intensity;
si = vec3(0.);
for (int i = 0; i < lights_count; ++i)
calcLight(lights_start + i, normal, v);
vec3 res_col = max(vec3(0), li * diffuse + si * specular + emission);
si *= shlick;
li *= (1 - shlick);
alpha = min(1, alpha * (1 + shlick));
vec3 res_col = max(vec3(0), li * diffuse + si * mix(vec3(1), diffuse, metalness) + emission);
float plen = length(pos.xyz);
float fog = 1 - exp(-plen / fog_decay);
@@ -133,5 +139,7 @@ void main(void) {
res_col = mix(res_col, fog_color.rgb, fog);
qgl_FragColor = vec4(res_col, alpha);
//qgl_FragColor.rgb = vec3(normal);
//qgl_FragColor.rgb = vec3(texture(tex_coeffs[0], qgl_FragTexture.xy).r);
//qgl_FragColor.rgb = vec3(ldir);
}