full support of ObjectBase:: isReceiveShadows, isCastShadows, isAcceptLight and isAcceptFog

This commit is contained in:
2023-02-12 22:49:38 +03:00
parent e3389bcc20
commit c8dcd5e9c0
10 changed files with 84 additions and 40 deletions

View File

@@ -3,6 +3,7 @@
out vec3 geom_normal;
out mat3 TBN;
out vec4 object_color;
out float object_flags;
void main(void) {
qgl_MaterialIndex = qgl_Material;
@@ -12,6 +13,7 @@ void main(void) {
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;
}
@@ -20,6 +22,7 @@ void main(void) {
in vec3 geom_normal;
in mat3 TBN;
in vec4 object_color;
in float object_flags;
uniform vec2 dt;
uniform float z_near;
@@ -65,7 +68,7 @@ void main(void) {
qgl_FragData[0] = vec4(diffuse .rgba);
qgl_FragData[1] = vec4(normal .xyz, z);
qgl_FragData[2] = vec4(metalness, roughness, reflectivity, 0);
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);

View File

@@ -37,6 +37,7 @@ vec4 pos, lpos, shp;
vec3 li, si, ldir, halfV, bn, bn2, lwdir;
vec3 vds, vds2;
float rough_diff, rough_spec, dist, NdotL, NdotH, spot, ldist, diff, spec, sdist, shadow;
uint flags;
vec4 mapScreenToShadow(in int light_index, in vec3 offset) {
@@ -74,12 +75,12 @@ void calcLight(in int index, in vec3 n, in vec3 v) {
spot *= scos * step(qgl_light_parameter[index].angles.w, scos);
spot *= smoothstep(qgl_light_parameter[index].angles.w, qgl_light_parameter[index].angles.y, scos);
if (qgl_light_parameter[index].flags == 1) {
if (qgl_light_parameter[index].flags == 1 && bitfieldExtract(flags, 3, 1) == 1) {
float ds = ldist/300.;
//float bias = ldist * 0.05;
vds = ds * bn.xyz;
vds2 = ds * bn2.xyz;
//vds = ds * bn.xyz;
//vds2 = ds * bn2.xyz;
int layer = index - lights_start;
float shadow = 0.;
@@ -192,16 +193,21 @@ void main(void) {
float reflectivity = v2.b;
float NdotV = dot(normal, v);
float roughness3 = roughness*roughness*roughness;
bn = normalize(cross(normal, view_dir));
bn2 = normalize(cross(normal, bn));
//bn = normalize(cross(normal, view_dir));
//bn2 = normalize(cross(normal, bn));
rough_diff = max(roughness, _min_rough);
rough_spec = max(roughness3, _min_rough);
float shlick = clamp(metalness + (1 - metalness) * pow(1 - NdotV, 5), 0, 1);
flags = uint(v2.w);
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);
if (bitfieldExtract(flags, 0, 1) == 1) {
for (int i = 0; i < lights_count; ++i)
calcLight(lights_start + i, normal, v);
} else {
li = vec3(1.);
}
si *= shlick;
li *= (1 - shlick);
alpha = min(1, alpha * (1 + shlick));
@@ -215,13 +221,16 @@ void main(void) {
vec3 res_col = max(vec3(0), li * diffuse + si * spec_col + emission);
res_col = mix(res_col, env_col, env_spec * reflectivity);
float plen = length(pos.xyz);
float fog = 1 - exp(-plen / fog_decay);
fog = clamp(fog * fog_color.a * fog_density, 0, 1);
res_col = mix(res_col, fog_color.rgb, fog);
if (bitfieldExtract(flags, 1, 1) == 1) {
float plen = length(pos.xyz);
float fog = 1 - exp(-plen / fog_decay);
fog = clamp(fog * fog_color.a * fog_density, 0, 1);
res_col = mix(res_col, fog_color.rgb, fog);
}
qgl_FragColor = vec4(res_col, alpha);
//qgl_FragColor.rgb = view_dir;
//qgl_FragColor.rgb = vec3((v2.w/15));
//qgl_FragColor.rgb = diffuse.rgb;
/*
#ifdef SPOT
vec4 wpos = vec4(world_dir * z, 1);

View File

@@ -1,6 +1,11 @@
// vert //
flat out uint object_flags;
void main(void) {
object_flags = qgl_ObjectFlags;
if (bitfieldExtract(object_flags, 2, 1) == 0)
return;
qgl_MaterialIndex = qgl_Material;
qgl_FragTexture = qgl_getFragTexture();
gl_Position = qgl_ftransform();
@@ -9,10 +14,14 @@ void main(void) {
// frag //
flat in uint object_flags;
float z_near = 0.1f;
const float _pe = 2.4e-7;
void main(void) {
if (bitfieldExtract(object_flags, 2, 1) == 0)
discard;
vec4 diffuse = qgl_materialTexture(QGL_MAP_DIFFUSE, qgl_FragTexture.xy, vec4(0));
if(diffuse.a < 0.5)
discard;