relief map support, small refactoring, shadow bias now based on geometry normal
This commit is contained in:
@@ -18,8 +18,8 @@ in vec3 view_dir, world_dir;
|
||||
|
||||
uniform vec2 dt, shadow_size;
|
||||
uniform float z_near;
|
||||
uniform sampler2D tex_coeffs[2], tex_noise;
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_sh;
|
||||
uniform sampler2D tex_coeff_brdf, tex_noise;
|
||||
uniform sampler2D tex_0, tex_1, tex_2, tex_3, tex_4, tex_5, tex_sh;
|
||||
//uniform sampler2DShadow tex_shadow[16];
|
||||
uniform sampler2DArrayShadow tex_shadows_cone;
|
||||
uniform sampler2DArray tex_depths_cone;
|
||||
@@ -42,7 +42,7 @@ const float PI = 3.1416;
|
||||
ivec2 tc;
|
||||
vec4 pos, lpos, shp;
|
||||
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
|
||||
vec3 normal, vds, vds2;
|
||||
vec3 normal, geom_normal, vds, vds2;
|
||||
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow, shadow_dz;
|
||||
uint flags;
|
||||
|
||||
@@ -67,7 +67,7 @@ float getShadowCone(in vec3 uvz, in int layer) {
|
||||
uvv[3] = iuvp.x * iuvp.y;
|
||||
shadow_dz = max(max(uvz.z - gt[0], uvz.z - gt[1]), max(uvz.z - gt[2], uvz.z - gt[3]));
|
||||
return clamp(dot(step(vec4(uvz.z), gt), uvv), 0, 1);*/
|
||||
float z = 1 - 1 / (uvz.z - z_near + 1);
|
||||
float z = 1. - 1. / (uvz.z - z_near + 1.);
|
||||
return texture(tex_shadows_cone, vec4(uvz.xy, layer, z));
|
||||
}
|
||||
|
||||
@@ -83,7 +83,7 @@ float getShadowOmni(in vec4 uvwz, in int layer) {
|
||||
uvv[2] = uvp.y * iuvp.z;
|
||||
uvv[3] = iuvp.y * iuvp.z;
|
||||
return clamp(dot(step(vec4(uvwz.w), gt), uvv), 0, 1);*/
|
||||
float d = 1 - 1 / (uvwz.w - z_near + 1);
|
||||
float d = 1. - 1. / (uvwz.w - z_near + 1.);
|
||||
return texture(tex_shadows_omni, vec4(uvwz.xyz, layer), d);
|
||||
//return step(uvwz.w, gt[3]);
|
||||
}
|
||||
@@ -110,7 +110,7 @@ float floatConstruct( uint m ) {
|
||||
m |= ieeeOne; // Add fractional part to 1.0
|
||||
|
||||
float f = uintBitsToFloat( m ); // Range [1:2]
|
||||
return f - 1.0; // Range [0:1]
|
||||
return f - 1.; // Range [0:1]
|
||||
}
|
||||
float random( float x ) { return floatConstruct(hash(floatBitsToUint(x))); }
|
||||
float random( vec2 v ) { return floatConstruct(hash(floatBitsToUint(v))); }
|
||||
@@ -174,11 +174,13 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
|
||||
#endif
|
||||
|
||||
if (int(round(qgl_light_parameter[index].flags)) == 1 && bitfieldExtract(flags, 3, 1) == 1 && (spot > 1E-4)) {
|
||||
#ifndef SPOT
|
||||
vec3 odir = -(view_mat * ldir);
|
||||
#endif
|
||||
int layer = index - lights_start;
|
||||
float shadow = 0.;
|
||||
//float bias = abs(tan(PI/2.*(1 - abs(dot(normal, ldir)))) + 1) * z_near * 1;
|
||||
float bias = (1. + 1. / abs(dot(normal, ldir))) * z_near * 2.;
|
||||
float bias = (1. + 1. / abs(dot(geom_normal, ldir))) * z_near * 2.;
|
||||
//bias = bias * bias + z_near;
|
||||
|
||||
if (soft_shadows_enabled) {
|
||||
@@ -291,10 +293,12 @@ void main(void) {
|
||||
vec4 v0 = texelFetch(tex_0, tc, 0),
|
||||
v2 = texelFetch(tex_2, tc, 0),
|
||||
v3 = texelFetch(tex_3, tc, 0),
|
||||
v4 = texelFetch(tex_4, tc, 0);
|
||||
v4 = texelFetch(tex_4, tc, 0),
|
||||
v5 = texelFetch(tex_5, tc, 0);
|
||||
|
||||
vec3 diffuse = v0.rgb;
|
||||
normal = v1.xyz;
|
||||
geom_normal = v5.xyz;
|
||||
vec3 emission = v3.rgb;
|
||||
float alpha = v0.a;
|
||||
float metalness = v2.r;
|
||||
@@ -324,7 +328,7 @@ void main(void) {
|
||||
li *= (1. - shlick);
|
||||
alpha = min(1., alpha * (1. + shlick));
|
||||
|
||||
vec2 brdf = texture(tex_coeffs[0], vec2(NdotV*0.99, roughness*0.995)).rg;
|
||||
vec2 brdf = texture(tex_coeff_brdf, vec2(NdotV*0.99, roughness*0.995)).rg;
|
||||
float env_spec = shlick * brdf.x + brdf.y;
|
||||
vec3 spec_col = mix(vec3(1.), diffuse, metalness);
|
||||
vec3 env_dir = view_mat * reflect(-v, normal);
|
||||
@@ -341,8 +345,9 @@ void main(void) {
|
||||
}
|
||||
|
||||
qgl_FragColor = vec4(res_col, alpha);
|
||||
//qgl_FragColor = vec4(diffuse.rgb, 0.25);
|
||||
//qgl_FragColor.a = alpha;
|
||||
//qgl_FragColor.rgb = vec3(bn.z);
|
||||
//qgl_FragColor.rgb = vec3(geom_normal.rgb);
|
||||
//qgl_FragColor.rgba = vec4(vec3(0), 0.5);
|
||||
|
||||
#ifdef SPOT
|
||||
|
||||
Reference in New Issue
Block a user