Minecraft Wiki

What really is fog?[]

Hello the topic is "What is fog?"--142.167.105.242 21:48, 24 March 2021 (UTC)

Fog is a rendering feature intended for obscuring the player's view distance, usually for atmospheric effect or for seamlessly occluding sharp boundaries such as unloaded chunks. While traditionally referring to render distance, there are many other types of fog that can be encountered in-game under specific circumstances.

The article
Humiebeetalk contribs 21:51, 24 March 2021 (UTC)

Minecraft Void Fog[]

Minecraft 1.7.10 is the latest release featuring the void fog
So if you decompile this version using MCP, and extract the code resulting that's responsible for this feature, here is what you get
(Simplified)

public abstract class WorldProvider {
    /**
     * returns true if this dimension is supposed to display void particles and pull in the far plane based on the
     * user's Y offset.
     */
    public boolean getWorldHasVoidParticles()
    {
        return this.terrainType != WorldType.FLAT && !this.hasNoSky;
    }

    /**
     * Returns a double value representing the Y value relative to the top of the map at which void fog is at its
     * maximum. The default factor of 0.03125 relative to 256, for example, means the void fog will be at its maximum at
     * (256*0.03125), or 8.
     */
    public double getVoidFogYFactor()
    {
        return this.terrainType == WorldType.FLAT ? 1.0D : 0.03125D;
    }
}

public class EntityRenderer implements IResourceManagerReloadListener {
    private void updateFogColor(float p_78466_1_) {
        WorldClient var2 = this.mc.theWorld;
        EntityLivingBase var3 = this.mc.renderViewEntity;
        double var14 = (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)p_78466_1_) * var2.provider.getVoidFogYFactor();

        if (var3.isPotionActive(Potion.blindness))
        {
            int var16 = var3.getActivePotionEffect(Potion.blindness).getDuration();

            if (var16 < 20)
            {
                var14 *= (double)(1.0F - (float)var16 / 20.0F);
            }
            else
            {
                var14 = 0.0D;
            }
        }

        if (var14 < 1.0D)
        {
            if (var14 < 0.0D)
            {
                var14 = 0.0D;
            }

            var14 *= var14;
            this.fogColorRed = (float)((double)this.fogColorRed * var14);
            this.fogColorGreen = (float)((double)this.fogColorGreen * var14);
            this.fogColorBlue = (float)((double)this.fogColorBlue * var14);
        }
    }

    private void setupFog(int p_78468_1_, float p_78468_2_) {
        EntityLivingBase var3 = this.mc.renderViewEntity;
        boolean var4 = false;

        if (var3 instanceof EntityPlayer)
        {
            var4 = ((EntityPlayer)var3).capabilities.isCreativeMode;
        }

        if (p_78468_1_ == 999) {}
        else {
            else {
                var6 = this.farPlaneDistance;
                if (this.mc.theWorld.provider.getWorldHasVoidParticles() && !var4)
                {
                    double var10 = (double)((var3.getBrightnessForRender(p_78468_2_) & 15728640) >> 20) / 16.0D + (var3.lastTickPosY + (var3.posY - var3.lastTickPosY) * (double)p_78468_2_ + 4.0D) / 32.0D;

                    if (var10 < 1.0D)
                    {
                        if (var10 < 0.0D)
                        {
                            var10 = 0.0D;
                        }

                        var10 *= var10;
                        float var9 = 100.0F * (float)var10;

                        if (var9 < 5.0F)
                        {
                            var9 = 5.0F;
                        }

                        if (var6 > var9)
                        {
                            var6 = var9;
                        }
                    }
                }

                if (p_78468_1_ < 0)
                {
                    GL11.glFogf(GL11.GL_FOG_START, 0.0F);
                    GL11.glFogf(GL11.GL_FOG_END, var6);
                }
                else
                {
                    GL11.glFogf(GL11.GL_FOG_START, var6 * 0.75F);
                    GL11.glFogf(GL11.GL_FOG_END, var6);
                }
            }
        }
    }
}

public class WorldClient extends World {
    public void doVoidFogParticles(int p_73029_1_, int p_73029_2_, int p_73029_3_)
    {
        byte var4 = 16;
        Random var5 = new Random();

        for (int var6 = 0; var6 < 1000; ++var6)
        {
            int var7 = p_73029_1_ + this.rand.nextInt(var4) - this.rand.nextInt(var4);
            int var8 = p_73029_2_ + this.rand.nextInt(var4) - this.rand.nextInt(var4);
            int var9 = p_73029_3_ + this.rand.nextInt(var4) - this.rand.nextInt(var4);
            Block var10 = this.getBlock(var7, var8, var9);

            if (var10.getMaterial() == Material.air)
            {
                if (this.rand.nextInt(8) > var8 && this.provider.getWorldHasVoidParticles())
                {
                    this.spawnParticle("depthsuspend", (double)((float)var7 + this.rand.nextFloat()), (double)((float)var8 + this.rand.nextFloat()), (double)((float)var9 + this.rand.nextFloat()), 0.0D, 0.0D, 0.0D);
                }
            }
            else
            {
                var10.randomDisplayTick(this, var7, var8, var9, var5);
            }
        }
    }
}

public class Minecraft implements IPlayerUsage {
    public void runTick() {
        if (this.theWorld != null) {
            if (!this.isGamePaused && this.theWorld != null)
            {
                this.theWorld.doVoidFogParticles(MathHelper.floor_double(this.thePlayer.posX), MathHelper.floor_double(this.thePlayer.posY), MathHelper.floor_double(this.thePlayer.posZ));
            }
        }
    }
}

After some testing and deduction, I've come to this conclusion
The fog effect starts appearing if the player isn't in creative mode at layer 26 (var10 < 1.0D is only true when the player is at this level or below, assuming the sunlight does not alter var10), this effect can be altered if the player is exposed to sunlight, the fog gets gradually closer to the player until the player reaches the level 0, the fog remains the same below that level
As for the particles effect, it happends starting at level 8, and as does the fog, they gradually increase as the player goes down to level 0

I'd like to say that I may be wrong on some things I said, however, the tests I did were pretty successful and the results I got are much closer to what we're able to see in game, so this is the reason why I decided to modify the void fog section
Delxmos (talk) 22:54, 14 September 2023 (UTC)