mirror of
https://github.com/lubosz/overte.git
synced 2025-04-19 16:44:04 +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)$>
|
||||
<$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()$>
|
||||
|
||||
color = prevLighting;
|
||||
|
||||
color += emissive * isEmissiveEnabled();
|
||||
|
||||
// Ambient
|
||||
|
@ -195,25 +197,26 @@ vec3 evalGlobalLightingAlphaBlended(mat4 invViewMat, float shadowAttenuation, fl
|
|||
|
||||
vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||
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()$>
|
||||
|
||||
color = prevLighting;
|
||||
|
||||
color += emissive * isEmissiveEnabled();
|
||||
|
||||
// Ambient
|
||||
vec3 ambientDiffuse;
|
||||
vec3 ambientSpecular;
|
||||
evalLightingAmbient(ambientDiffuse, ambientSpecular, lightAmbient, fragEyeDir, fragNormal, roughness, metallic, fresnel, albedo, obscurance);
|
||||
color += ambientDiffuse;
|
||||
color += ambientSpecular / opacity;
|
||||
|
||||
// Directional
|
||||
vec3 directionalDiffuse;
|
||||
vec3 directionalSpecular;
|
||||
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
|
||||
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));
|
||||
int numLights = cluster.x + cluster.y;
|
||||
if (numLights <= 0) {
|
||||
discard;
|
||||
}
|
||||
|
||||
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@>
|
||||
|
||||
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@>
|
||||
|
|
|
@ -22,8 +22,11 @@
|
|||
|
||||
vec4 evalLocalLighting(ivec3 cluster, int numLights, vec3 fragWorldPos, vec3 fragNormal, vec3 fragEyeDir,
|
||||
vec4 midNormalCurvature, vec4 lowNormalCurvature,
|
||||
float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo) {
|
||||
vec4 _fragColor = vec4(0.0);
|
||||
float fragRoughness, float fragScattering, float fragMetallic, vec3 fragFresnel, vec3 fragAlbedo,
|
||||
float opacity) {
|
||||
vec4 fragColor = vec4(0.0);
|
||||
vec3 fragSpecular = vec3(0.0);
|
||||
vec3 fragDiffuse = vec3(0.0);
|
||||
int lightClusterOffset = cluster.z;
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
||||
specular *= lightEnergy * isSpecularEnabled();
|
||||
diffuse *= lightEnergy;
|
||||
specular *= lightEnergy;
|
||||
|
||||
_fragColor.rgb += diffuse;
|
||||
_fragColor.rgb += specular;
|
||||
fragDiffuse.rgb += diffuse;
|
||||
fragSpecular.rgb += specular;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
diffuse *= lightEnergy * isDiffuseEnabled();
|
||||
specular *= lightEnergy * isSpecularEnabled();
|
||||
diffuse *= lightEnergy;
|
||||
specular *= lightEnergy;
|
||||
|
||||
_fragColor.rgb += diffuse;
|
||||
_fragColor.rgb += specular;
|
||||
fragDiffuse.rgb += diffuse;
|
||||
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;
|
||||
|
||||
<$fetchClusterInfo(fragPos)$>;
|
||||
if (!hasLocalLights(numLights, clusterPos, dims)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
// Frag to eye vec
|
||||
vec4 fragEyeVector = invViewMat * vec4(-frag.position.xyz, 0.0);
|
||||
|
|
|
@ -41,6 +41,9 @@ void main(void) {
|
|||
vec4 fragWorldPos = invViewMat * fragPosition;
|
||||
|
||||
<$fetchClusterInfo(fragWorldPos)$>;
|
||||
if (!hasLocalLights(numLights, clusterPos, dims)) {
|
||||
discard;
|
||||
}
|
||||
|
||||
vec4 midNormalCurvature;
|
||||
vec4 lowNormalCurvature;
|
||||
|
@ -55,7 +58,7 @@ void main(void) {
|
|||
|
||||
_fragColor = evalLocalLighting(cluster, numLights, fragWorldPos.xyz, frag.normal, fragEyeDir,
|
||||
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);
|
||||
|
||||
TransformCamera cam = getTransformCamera();
|
||||
vec4 localLighting = vec4(0.0);
|
||||
|
||||
<$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));
|
||||
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||
|
||||
vec4 localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||
vec4(0), vec4(0), roughness, 0.0,
|
||||
metallic, fresnel, albedo);
|
||||
emissive += localLighting.rgb;
|
||||
localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||
vec4(0), vec4(0), roughness, 0.0,
|
||||
metallic, fresnel, albedo, opacity);
|
||||
}
|
||||
|
||||
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
||||
cam._viewInverse,
|
||||
|
@ -89,6 +90,6 @@ void main(void) {
|
|||
fresnel,
|
||||
metallic,
|
||||
emissive,
|
||||
roughness, opacity),
|
||||
roughness, opacity, localLighting.rgb),
|
||||
opacity);
|
||||
}
|
||||
|
|
|
@ -77,16 +77,17 @@ void main(void) {
|
|||
vec3 fragNormal = normalize(_normal);
|
||||
|
||||
TransformCamera cam = getTransformCamera();
|
||||
vec4 localLighting = vec4(0.0);
|
||||
|
||||
<$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));
|
||||
vec3 fragEyeDir = normalize(fragEyeVector);
|
||||
|
||||
vec4 localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||
vec4(0), vec4(0), roughness, 0.0,
|
||||
metallic, fresnel, albedo);
|
||||
emissive += localLighting.rgb;
|
||||
localLighting = evalLocalLighting(cluster, numLights, _worldPosition.xyz, fragNormal, fragEyeDir,
|
||||
vec4(0), vec4(0), roughness, 0.0,
|
||||
metallic, fresnel, albedo, opacity);
|
||||
}
|
||||
|
||||
_fragColor = vec4(evalGlobalLightingAlphaBlendedWithHaze(
|
||||
cam._viewInverse,
|
||||
|
@ -98,6 +99,6 @@ void main(void) {
|
|||
fresnel,
|
||||
metallic,
|
||||
emissive+fadeEmissive,
|
||||
roughness, opacity),
|
||||
roughness, opacity, localLighting.rgb),
|
||||
opacity);
|
||||
}
|
||||
|
|
|
@ -75,7 +75,7 @@ void main(void) {
|
|||
fresnel,
|
||||
metallic,
|
||||
emissive,
|
||||
roughness, opacity),
|
||||
roughness, opacity, vec3(0)),
|
||||
opacity);
|
||||
|
||||
// Apply standard tone mapping
|
||||
|
|
|
@ -56,7 +56,7 @@ void main(void) {
|
|||
0.0,
|
||||
vec3(0.0f),
|
||||
DEFAULT_ROUGHNESS,
|
||||
opacity),
|
||||
opacity, vec3(0)),
|
||||
opacity);
|
||||
|
||||
}
|
|
@ -68,7 +68,7 @@ void main(void) {
|
|||
0.0f,
|
||||
fadeEmissive,
|
||||
DEFAULT_ROUGHNESS,
|
||||
opacity),
|
||||
opacity, vec3(0)),
|
||||
opacity);
|
||||
|
||||
}
|
Loading…
Reference in a new issue