mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 15:50:37 +02:00
Fixed bug due to incorrect discard of fragments with no local lights
This commit is contained in:
parent
32445a5660
commit
3382a35c3f
10 changed files with 81 additions and 51 deletions
|
@ -171,9 +171,11 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
|
||||||
<$declareLightingAmbient(1, 1, 1)$>
|
<$declareLightingAmbient(1, 1, 1)$>
|
||||||
<$declareLightingDirectional()$>
|
<$declareLightingDirectional()$>
|
||||||
|
|
||||||
vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity) {
|
vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity, vec3 prevLighting) {
|
||||||
<$prepareGlobalLight()$>
|
<$prepareGlobalLight()$>
|
||||||
|
|
||||||
|
color = prevLighting;
|
||||||
|
|
||||||
color += emissive * isEmissiveEnabled();
|
color += emissive * isEmissiveEnabled();
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
|
@ -195,25 +197,26 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
|
||||||
|
|
||||||
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal,
|
||||||
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity)
|
vec3 albedo, vec3 fresnel, float metallic, vec3 emissive, float roughness, float opacity, vec3 prevLighting)
|
||||||
{
|
{
|
||||||
<$prepareGlobalLight()$>
|
<$prepareGlobalLight()$>
|
||||||
|
|
||||||
|
color = prevLighting;
|
||||||
|
|
||||||
color += emissive * isEmissiveEnabled();
|
color += emissive * isEmissiveEnabled();
|
||||||
|
|
||||||
// Ambient
|
// Ambient
|
||||||
vec3 ambientDiffuse;
|
vec3 ambientDiffuse;
|
||||||
vec3 ambientSpecular;
|
vec3 ambientSpecular;
|
||||||
evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
|
evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
|
||||||
color += ambientDiffuse;
|
|
||||||
color += ambientSpecular / opacity;
|
|
||||||
|
|
||||||
// Directional
|
// Directional
|
||||||
vec3 directionalDiffuse;
|
vec3 directionalDiffuse;
|
||||||
vec3 directionalSpecular;
|
vec3 directionalSpecular;
|
||||||
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
|
evalLightingDirectional(directionalDiffuse, directionalSpecular, lightDirection, lightIrradiance, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, shadowAttenuation);
|
||||||
color += directionalDiffuse;
|
|
||||||
color += directionalSpecular / opacity;
|
color += ambientDiffuse + directionalDiffuse;
|
||||||
|
color += (ambientSpecular + directionalSpecular) / opacity;
|
||||||
|
|
||||||
// Haze
|
// Haze
|
||||||
if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
||||||
|
|
|
@ -95,22 +95,32 @@ int clusterGrid_getClusterLightId(int index, int offset) {
|
||||||
|
|
||||||
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
|
ivec3 cluster = clusterGrid_getCluster(frustumGrid_clusterToIndex(clusterPos));
|
||||||
int numLights = cluster.x + cluster.y;
|
int numLights = cluster.x + cluster.y;
|
||||||
if (numLights <= 0) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
ivec3 dims = frustumGrid.dims.xyz;
|
ivec3 dims = frustumGrid.dims.xyz;
|
||||||
if (clusterPos.x < 0 || clusterPos.x >= dims.x) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (clusterPos.y < 0 || clusterPos.y >= dims.y) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
if (clusterPos.z < 0 || clusterPos.z > dims.z) {
|
|
||||||
discard;
|
|
||||||
}
|
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
bool hasLocalLights(int numLights, ivec3 clusterPos, ivec3 dims) {
|
||||||
|
/*
|
||||||
|
if (numLights <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clusterPos.x < 0 || clusterPos.x >= dims.x) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clusterPos.y < 0 || clusterPos.y >= dims.y) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (clusterPos.z < 0 || clusterPos.z > dims.z) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
*/
|
||||||
|
return numLights>0
|
||||||
|
&& all(greaterThanEqual(clusterPos, ivec3(0)))
|
||||||
|
&& all(lessThan(clusterPos.xy, dims.xy))
|
||||||
|
&& clusterPos.z <= dims.z;
|
||||||
|
}
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
|
@ -22,8 +22,11 @@
|
||||||
|
|
||||||
vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fragNormal, vec3 fragEyeDir,
|
vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fragNormal, vec3 fragEyeDir,
|
||||||
vec4 midNormalCurvature, vec4 lowNormalCurvature,
|
vec4 midNormalCurvature, vec4 lowNormalCurvature,
|
||||||
float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo) {
|
float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo,
|
||||||
vec4 _fragColor = vec4(0.0);
|
float opacity) {
|
||||||
|
vec4 fragColor = vec4(0.0);
|
||||||
|
vec3 fragSpecular = vec3(0.0);
|
||||||
|
vec3 fragDiffuse = vec3(0.0);
|
||||||
int lightClusterOffset = cluster.z;
|
int lightClusterOffset = cluster.z;
|
||||||
|
|
||||||
// Compute the rougness into gloss2 once:
|
// Compute the rougness into gloss2 once:
|
||||||
|
@ -72,11 +75,11 @@ vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fra
|
||||||
evalFragShadingGloss(diffuse, specular, fragNormal, fragLightDir, fragEyeDir, fragMetallic, fragFresnel, fragGloss2, fragAlbedo);
|
evalFragShadingGloss(diffuse, specular, fragNormal, fragLightDir, fragEyeDir, fragMetallic, fragFresnel, fragGloss2, fragAlbedo);
|
||||||
}
|
}
|
||||||
|
|
||||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
diffuse *= lightEnergy;
|
||||||
specular *= lightEnergy * isSpecularEnabled();
|
specular *= lightEnergy;
|
||||||
|
|
||||||
_fragColor.rgb += diffuse;
|
fragDiffuse.rgb += diffuse;
|
||||||
_fragColor.rgb += specular;
|
fragSpecular.rgb += specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = cluster.x; i < numLights; i++) {
|
for (int i = cluster.x; i < numLights; i++) {
|
||||||
|
@ -127,11 +130,17 @@ vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fra
|
||||||
evalFragShadingGloss(diffuse, specular, fragNormal, fragLightDir, fragEyeDir, fragMetallic, fragFresnel, fragGloss2, fragAlbedo);
|
evalFragShadingGloss(diffuse, specular, fragNormal, fragLightDir, fragEyeDir, fragMetallic, fragFresnel, fragGloss2, fragAlbedo);
|
||||||
}
|
}
|
||||||
|
|
||||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
diffuse *= lightEnergy;
|
||||||
specular *= lightEnergy * isSpecularEnabled();
|
specular *= lightEnergy;
|
||||||
|
|
||||||
_fragColor.rgb += diffuse;
|
fragDiffuse.rgb += diffuse;
|
||||||
_fragColor.rgb += specular;
|
fragSpecular.rgb += specular;
|
||||||
}
|
}
|
||||||
return _fragColor;
|
|
||||||
|
fragDiffuse *= isDiffuseEnabled();
|
||||||
|
fragSpecular *= isSpecularEnabled();
|
||||||
|
|
||||||
|
fragColor.rgb += fragDiffuse;
|
||||||
|
fragColor.rgb += fragSpecular / opacity;
|
||||||
|
return fragColor;
|
||||||
}
|
}
|
|
@ -55,6 +55,9 @@ void main(void) {
|
||||||
vec4 fragPos = invViewMat * fragPosition;
|
vec4 fragPos = invViewMat * fragPosition;
|
||||||
|
|
||||||
<$fetchClusterInfo(fragPos)$>;
|
<$fetchClusterInfo(fragPos)$>;
|
||||||
|
if (!hasLocalLights(numLights, clusterPos, dims)) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
// Frag to eye vec
|
// Frag to eye vec
|
||||||
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||||
|
|
|
@ -41,6 +41,9 @@ void main(void) {
|
||||||
vec4 fragWorldPos = invViewMat * fragPosition;
|
vec4 fragWorldPos = invViewMat * fragPosition;
|
||||||
|
|
||||||
<$fetchClusterInfo(fragWorldPos)$>;
|
<$fetchClusterInfo(fragWorldPos)$>;
|
||||||
|
if (!hasLocalLights(numLights, clusterPos, dims)) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
|
|
||||||
vec4 midNormalCurvature;
|
vec4 midNormalCurvature;
|
||||||
vec4 lowNormalCurvature;
|
vec4 lowNormalCurvature;
|
||||||
|
@ -55,7 +58,7 @@ void main(void) {
|
||||||
|
|
||||||
_fragColor = evalLocalLighting(cluster, numLights, fragWorldPos.xyz, frag.normal, fragEyeDir,
|
_fragColor = evalLocalLighting(cluster, numLights, fragWorldPos.xyz, frag.normal, fragEyeDir,
|
||||||
midNormalCurvature, lowNormalCurvature, frag.roughness, frag.scattering,
|
midNormalCurvature, lowNormalCurvature, frag.roughness, frag.scattering,
|
||||||
frag.metallic, frag.fresnel, frag.albedo);
|
frag.metallic, frag.fresnel, frag.albedo, 1.0);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,16 +68,17 @@ void main(void) {
|
||||||
vec3 fragNormal = normalize(_normal);
|
vec3 fragNormal = normalize(_normal);
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
|
vec4 localLighting = vec4(0.0);
|
||||||
|
|
||||||
<$fetchClusterInfo(_worldPosition)$>;
|
<$fetchClusterInfo(_worldPosition)$>;
|
||||||
|
if (hasLocalLights(numLights, clusterPos, dims)) {
|
||||||
|
vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0));
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||||
|
|
||||||
vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0));
|
localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector);
|
vec4(0), vec4(0), roughness, 0.0,
|
||||||
|
metallic, fresnel, albedo, opacity);
|
||||||
vec4 localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
}
|
||||||
vec4(0), vec4(0), roughness, 0.0,
|
|
||||||
metallic, fresnel, albedo);
|
|
||||||
emissive += localLighting.rgb;
|
|
||||||
|
|
||||||
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
cam._viewInverse,
|
cam._viewInverse,
|
||||||
|
@ -89,6 +90,6 @@ void main(void) {
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive,
|
emissive,
|
||||||
roughness, opacity),
|
roughness, opacity, localLighting.rgb),
|
||||||
opacity);
|
opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,16 +77,17 @@ void main(void) {
|
||||||
vec3 fragNormal = normalize(_normal);
|
vec3 fragNormal = normalize(_normal);
|
||||||
|
|
||||||
TransformCamera cam = getTransformCamera();
|
TransformCamera cam = getTransformCamera();
|
||||||
|
vec4 localLighting = vec4(0.0);
|
||||||
|
|
||||||
<$fetchClusterInfo(_worldPosition)$>;
|
<$fetchClusterInfo(_worldPosition)$>;
|
||||||
|
if (hasLocalLights(numLights, clusterPos, dims)) {
|
||||||
|
vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0));
|
||||||
|
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||||
|
|
||||||
vec3 fragEyeVector = vec3(cam._viewInverse * vec4(-fragPosition, 0.0));
|
localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||||
vec3 fragEyeDir = normalize(fragEyeVector);
|
vec4(0), vec4(0), roughness, 0.0,
|
||||||
|
metallic, fresnel, albedo, opacity);
|
||||||
vec4 localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
}
|
||||||
vec4(0), vec4(0), roughness, 0.0,
|
|
||||||
metallic, fresnel, albedo);
|
|
||||||
emissive += localLighting.rgb;
|
|
||||||
|
|
||||||
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
cam._viewInverse,
|
cam._viewInverse,
|
||||||
|
@ -98,6 +99,6 @@ void main(void) {
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive+fadeEmissive,
|
emissive+fadeEmissive,
|
||||||
roughness, opacity),
|
roughness, opacity, localLighting.rgb),
|
||||||
opacity);
|
opacity);
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,7 +75,7 @@ void main(void) {
|
||||||
fresnel,
|
fresnel,
|
||||||
metallic,
|
metallic,
|
||||||
emissive,
|
emissive,
|
||||||
roughness, opacity),
|
roughness, opacity, vec3(0)),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
// Apply standard tone mapping
|
// Apply standard tone mapping
|
||||||
|
|
|
@ -56,7 +56,7 @@ void main(void) {
|
||||||
0.0,
|
0.0,
|
||||||
vec3(0.0f),
|
vec3(0.0f),
|
||||||
DEFAULT_ROUGHNESS,
|
DEFAULT_ROUGHNESS,
|
||||||
opacity),
|
opacity, vec3(0)),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
}
|
}
|
|
@ -68,7 +68,7 @@ void main(void) {
|
||||||
0.0f,
|
0.0f,
|
||||||
fadeEmissive,
|
fadeEmissive,
|
||||||
DEFAULT_ROUGHNESS,
|
DEFAULT_ROUGHNESS,
|
||||||
opacity),
|
opacity, vec3(0)),
|
||||||
opacity);
|
opacity);
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue