Thursday, May 19, 2011

Version 1.5_01_F

First some bugfixes. 

The briefly flashing blue rectangle visible after destroying a block was caused by too much optimization for the sunset lag. It is fixed now and the sunset lag is also no more.

The new features. 

1. Smooth FPS

One of the long standing problems with the Minecraft performance is the unstable framerate. Random lag spikes can appear out of nowhere and then disappear. They are visible as random freezing or stuttering. Even worse is the magnitude of the lag spikes, some of them corresponding to 2 or 3 times lower framerate than the average one. The effective visual framerate is the lowest framerate for a given period, so the spikes are ruining the game appearance.

The reason for the spikes turned out to be the graphic card driver. The OpenGL specification allows the driver to buffer up to 3 frames, before rendering them to the screen. 

To fix this OptiFog adds "Smooth FPS" which explicitely flushes all OpenGL bufferes before rendering the next frame. This removes almost all of the random lag spikes and affects minimally the average FPS.

This is how the lag spikes look on a laptop with ATI HD 4200:

The average framerate is 29 FPS, but the worse spikes correspond to framerate 10 FPS, which reflects the allowed buffering of 3 frames.

With "Smooth FPS" turned on the framerate is much more stable. Average is 26 FPS with biggest spikes about 20 FPS.:

On a desktop PC with nVidia FX 5600 the lag spikes are appearing at every third frame. The visible effect is stuttering, especially at lower framerates.

With Smooth FPS the spikes are gone, and the average FPS is not affected:

The option Advanced OpenGL seems to reduce the random lag spikes on some systems, but have no effect on other. This is dependant on the graphic card driver.

2. Brightness

Minecraft uses non-linear light levels. The difference between level 0 and 1 is much smaller than the difference between level 14 and 15.

On a good calibrated monitor which can show near-black colors the Minecraft night scenes are almost fully black (light level 4). On the other hand, not so good monitors which have problems with near black colors show the night scenes very good.

The Brightness setting fixes the Minecraft light levels for properly calibrated monitors.  
Brightness 0% corresponds to default Minecraft light levels. Brightness 100% uses linear light levels, so the steps between all light levels are equal. 

3. Framerate Limit: VSync

A new value for the Framerate Limit, turns on vertical synchronization (VSync) between the graphic card and the monitor so that the monitor always show fully rendered frames. 

The visual effect is limiting the framerate to the monitor framerate, usually 60 or 70 FPS. However if Minecraft is not able to reach the full monitor framerate, the FPS will be limited to half the monitor framerate (30).

You can find more info about VSync here:

Wednesday, May 18, 2011

Version 1.5_01_E is Out

It has taken a while, but version 1.5_01_E is out.
Fixed are the sunset lag spikes and fancy clouds rendering on some nVidia cards.

Unfortunately the most interesting new features did not make it in the E release.

Currently OptiFog has three development branches:

A. Anisotropic Filtering and Full Screen Antialiasing using texture atlas
Adds AF and FSAA using the default Minecraft texture atlas.
Not quite working, some color bleeding is still visible in far objects. May need some shader support to really work.

B. Anisotropic Filtering and Full Screen Antialiasing using separate textures
This one is in development. The performance may be problematic, still have to be tested. If it works Minecraft will finally look nice.

C. Background chunk loading
Loads chunks on a separate thread.
On dual-core CPU-s it uses the second core for loading chunks while the first one renders. Chunk loading should not cause lag spikes, even with integrated graphics.
This branch is already working, but not yet deliverable. Mod compatibility may be problematic, because more class files are changed.

Friday, May 13, 2011

On Decompilers and Obfuscators

The guys at Minecraft Coders Pack have done a great job at lowering the entry barrier for Minecraft modders. Really.

Decompiling Java programs and recompiling them again has never been a real problem. However Minecraft is also obfuscated so that all class and method names are replaced with short meaningless labels.

Most obfuscators deliberately try to generate code which while still functionally identical to the original is as confusing as possible for a decompiler. This includes generating bytecode which can not be produced by a Java compiler or adding dead code with illegal functionality in hopes of disorienting the decompiler and forcing it to give up.

The decompiler used by MCP suffers from all this and is in fact not able to correctly decompile all the bytecode. However MCP uses a set of patches to help the decompiler where it has given up. These patches are updated manually for every Minecraft release.

Where MCP really has succeeded is at the returning of the meaning of the decompiled code. The MCP community has reverse engineered almost all of the Minecraft source and while some places are not quite right and one or two are totally wrong the final result is quite comprehensible.

MCP also includes the tools needed to recompile and reobfuscate the changed source so that the final result is compatible to the original Minecraft bytecode.

On IRC #mcp on there is even a bot which can report the current deobfuscation mapping and accept names for the missing entries.

One just can not wish for more.

In the beginning was the Fog

Minecraft has always looked foggy, even on Normal and Far render distances. And this has always annoyed me a little.

The fog was robbing the vibrant colors of the valleys and mountains and turning them into washed-out background panes. Switching the render distance was also changing the fog density which was breaking the illusion of seeing a natural world.

Being a Java programmer since ever, I naturally came to the question "How hard could it be?".

This is how OptiFog was created.