relief map support, small refactoring, shadow bias now based on geometry normal
This commit is contained in:
@@ -5,15 +5,19 @@ out mat3 TBN;
|
||||
out vec4 object_color;
|
||||
out float object_flags;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
void main(void) {
|
||||
qgl_MaterialIndex = qgl_Material;
|
||||
qgl_FragTexture = qgl_getFragTexture();
|
||||
gl_Position = qgl_ftransform();
|
||||
|
||||
geom_normal = normalize(qgl_Normal * qgl_getNormalMatrix());
|
||||
TBN = qgl_getTangentMatrix() * mat3(qgl_Tangent, qgl_Bitangent, qgl_Normal);
|
||||
object_color = qgl_ObjectColor;
|
||||
object_flags = qgl_ObjectFlags;
|
||||
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, qgl_FragTexture, vec4(0.)).rgb, luma);
|
||||
gl_Position = qgl_ViewProjMatrix * (qgl_ModelMatrix * (vec4(qgl_Vertex + qgl_Normal * height, 1.)));//qgl_ftransform();
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +30,7 @@ in float object_flags;
|
||||
|
||||
uniform vec2 dt;
|
||||
uniform float z_near;
|
||||
uniform int out_index_normal = dbrNormalZ, out_index_metal = dbrMetalRoughReflectFlags;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
const float _pe = 2.4e-7;
|
||||
@@ -33,13 +38,13 @@ const float _pe = 2.4e-7;
|
||||
void main(void) {
|
||||
vec2 tc = qgl_FragTexture.xy;
|
||||
|
||||
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, tc, vec4(0)) * object_color;
|
||||
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, tc, vec4(0.)) * object_color;
|
||||
diffuse.rgb *= qgl_material[qgl_MaterialIndex].color_diffuse.rgb;
|
||||
#ifdef SOLID
|
||||
if(diffuse.a < 0.5)
|
||||
discard;
|
||||
#endif
|
||||
diffuse.a *= (1.f - qgl_material[qgl_MaterialIndex].transparency);
|
||||
diffuse.a *= (1. - qgl_material[qgl_MaterialIndex].transparency);
|
||||
|
||||
vec3 normal, dn;
|
||||
dn = qgl_materialTexture(QGL_MAP_NORMAL, tc, -vec4(0.5, 0.5, 1., 0.)).xyz;
|
||||
@@ -49,28 +54,27 @@ void main(void) {
|
||||
dn *= dn_sl / (length(dn) + 1E-6);
|
||||
normal = normalize(geom_normal + dn);
|
||||
|
||||
float metalness = dot(qgl_materialTexture(QGL_MAP_METALNESS, tc, vec4(0)).rgb, luma);
|
||||
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);
|
||||
float roughness = dot(qgl_materialTexture(QGL_MAP_ROUGHNESS, tc, vec4(0.)).rgb, luma);
|
||||
roughness = clamp(roughness, 0.0001, 0.9999);
|
||||
|
||||
float reflectivity = clamp(qgl_material[qgl_MaterialIndex].reflectivity, 0., 1.);
|
||||
|
||||
vec4 emission = qgl_materialTexture(QGL_MAP_EMISSION, tc, vec4(0));
|
||||
vec4 emission = qgl_materialTexture(QGL_MAP_EMISSION, tc, vec4(0.));
|
||||
emission *= qgl_material[qgl_MaterialIndex].color_emission;
|
||||
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, tc, vec4(0)).rgb, luma);
|
||||
|
||||
float z = gl_FragCoord.z;
|
||||
z = z + z - 1;
|
||||
z = z + z - 1.;
|
||||
z = ((_pe - 2.) * z_near) / (z + _pe - 1.); // infinite depth
|
||||
|
||||
qgl_FragData[0] = vec4(diffuse .rgba);
|
||||
qgl_FragData[1] = vec4(normal .xyz, z);
|
||||
qgl_FragData[2] = vec4(metalness, roughness, reflectivity, object_flags);
|
||||
qgl_FragData[3] = vec4(emission.rgb, 0/*bn.x*/);
|
||||
//qgl_FragData[4] = vec4(speed.xy, bn.yz);
|
||||
|
||||
qgl_FragData[dbrDiffuse ] = vec4(diffuse .rgba);
|
||||
qgl_FragData[out_index_normal] = vec4(normal .xyz, z);
|
||||
qgl_FragData[out_index_metal ] = vec4(metalness, roughness, reflectivity, object_flags);
|
||||
qgl_FragData[dbrEmission ] = vec4(emission.rgb, 0./*bn.x*/);
|
||||
//qgl_FragData[dbrSpeedBitangXY] = vec4(speed.xy, bn.yz);
|
||||
qgl_FragData[dbrGeoNormal ] = vec4(normalize(geom_normal), 1.);
|
||||
|
||||
//ivec2 itc = ivec2(gl_FragCoord.xy);
|
||||
//qgl_FragData[0].rgb = vec3(dot(n,vec3(0,0,1)));
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -19,7 +19,7 @@ void main(void) {
|
||||
float l = dot(res, luma) * 0.75;
|
||||
float g = gamma / frame_max;
|
||||
res /= l;
|
||||
l = 1 - exp(-l*g);
|
||||
res = max(vec3(0.f), res * l);
|
||||
l = 1. - exp(-l*g);
|
||||
res = max(vec3(0.), res * l);
|
||||
qgl_FragColor = vec4(res, dot(res, luma));
|
||||
}
|
||||
|
||||
@@ -4,13 +4,16 @@ flat out uint object_flags;
|
||||
out float distance;
|
||||
out vec4 pos;
|
||||
|
||||
const vec3 luma = vec3(0.299, 0.587, 0.114);
|
||||
|
||||
void main(void) {
|
||||
object_flags = qgl_ObjectFlags;
|
||||
if (bitfieldExtract(object_flags, 2, 1) == 0)
|
||||
return;
|
||||
qgl_MaterialIndex = qgl_Material;
|
||||
qgl_FragTexture = qgl_getFragTexture();
|
||||
pos = qgl_ftransform();
|
||||
float height = dot(qgl_materialTexture(QGL_MAP_RELIEF, qgl_FragTexture, vec4(0.)).rgb, luma);
|
||||
pos = qgl_ViewProjMatrix * (qgl_ModelMatrix * (vec4(qgl_Vertex + qgl_Normal * height, 1.)));//qgl_ftransform();
|
||||
gl_Position = pos;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user