Author Topic: Shader Fog Lighting Lag  (Read 863 times)


This effect right here lags so hard, it cuts 100+ FPS off. It's ridiculous because everything else runs fine. I get that it's poorly optimized or whatever, but is there a way to remove it?

It's ridiculous because everything else runs fine.

It really isn't ridiculous. Normally, Blockland just has to apply shadows for every visible surface point. With particles, it has to apply them for every 3D layer and every pixel of the particle texture.

Is there a way to disable the shadows on particles though?

Instead of this:

   float occlusionFactor = 0.0f;
   if(NdotL > -0.01f)
   {
      if(shadowSplitCount <= 0)
         occlusionFactor = 1.0f;
      else
         occlusionFactor = shadowCoef();
   }

   // Apply lighting and fog.
   vec4 fragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
   if(isParticle == 1)
   {
      vec4 texAlbedo = texture2D(tex, texCoord);
           
      vec4 dirLightDirect = (dirLightColor * occlusionFactor) + (dirLightAmbient * occlusionFactor) + (dirShadowColor * (1.0f - occlusionFactor));
      vec4 plt = accumulateParticlePointLights();

      vec4 lightTotal = dirLightDirect + plt;
      lightTotal.x = clamp(lightTotal.x, 0.0f, 1.2f);
      lightTotal.y = clamp(lightTotal.y, 0.0f, 1.2f);
      lightTotal.z = clamp(lightTotal.z, 0.0f, 1.2f);

      fragColor = texAlbedo * gl_Color * lightTotal;

      applyFog(fragColor);
      fragColor.a = texAlbedo.a * gl_Color.a;
   }
   else
   {
      applyLighting(fragColor, albedo, occlusionFactor);
      applyFog(fragColor);
   }


Try something like this (not tested):

   // Apply lighting and fog.
   vec4 fragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
   if(isParticle == 1)
   {
      vec4 texAlbedo = texture2D(tex, texCoord);
           
      vec4 dirLightDirect = dirLightColor + dirLightAmbient;
      vec4 plt = accumulateParticlePointLights();

      vec4 lightTotal = dirLightDirect + plt;
      lightTotal.x = clamp(lightTotal.x, 0.0f, 1.2f);
      lightTotal.y = clamp(lightTotal.y, 0.0f, 1.2f);
      lightTotal.z = clamp(lightTotal.z, 0.0f, 1.2f);

      fragColor = texAlbedo * gl_Color * lightTotal;

      applyFog(fragColor);
      fragColor.a = texAlbedo.a * gl_Color.a;
   }
   else
   {
      float occlusionFactor = 0.0f;

      if(NdotL > -0.01f)
      {
         if(shadowSplitCount <= 0)
            occlusionFactor = 1.0f;
         else
            occlusionFactor = shadowCoef();
      }

      applyLighting(fragColor, albedo, occlusionFactor);
      applyFog(fragColor);
   }


I don't think it'll work since isParticle has been unreliable in the past, but try it.


Ok it worked, in that it removed the fog lighting effect. The fog still, however, lags when I zoom in. No clue why now, haha.

Code: [Select]
void main()
{
   vec4 albedo = vec4(0.0f, 0.0f, 0.0f, 0.0f);
   calculateSurface(gl_Color, albedo);
 
   // Apply lighting and fog.
   vec4 fragColor = vec4(0.0f, 0.0f, 0.0f, 0.0f);
   if(isParticle == 1)
   {
      vec4 texAlbedo = texture2D(tex, texCoord);
           
      vec4 dirLightDirect = dirLightColor + dirLightAmbient;
      vec4 plt = accumulateParticlePointLights();
 
      vec4 lightTotal = dirLightDirect + plt;
      lightTotal.x = clamp(lightTotal.x, 0.0f, 1.2f);
      lightTotal.y = clamp(lightTotal.y, 0.0f, 1.2f);
      lightTotal.z = clamp(lightTotal.z, 0.0f, 1.2f);
 
      fragColor = texAlbedo * gl_Color; //* lightTotal;
 
      applyFog(fragColor);
      fragColor.a = texAlbedo.a * gl_Color.a;
   }
   else
   {
  float occlusionFactor = 0.0f;
  if(NdotL > -0.01f)
  {
if(shadowSplitCount <= 0)
occlusionFactor = 1.0f;
else
occlusionFactor = shadowCoef();
  }
      applyLighting(fragColor, albedo, occlusionFactor);
      applyFog(fragColor);
   }
   
   // Uncomment to viz depth in B.
   //fragColor.z = vPos.y * 0.01f;
 
   gl_FragColor = fragColor;
}
Works.