The JavaFX Rewrite 2016-09-14

I have been working on rewriting the Chunky UI using JavaFX. After a few months of work I am nearly done with the rewrite and it has resulted in removing more than 7 thousand lines of code. That’s close to 15% of the total source code removed!

During the JavaFX rewrite i changed much more than just the UI code. In this post I will summarize the major things that I rewrote or refactored as part of the JavaFX rewrite.

1 Comment on The JavaFX Rewrite
Categories: Chunky Programming

Chunky 2014 Fall Update 2014-11-09

It has been a few months since the last Chunky posts on this blog, and since I have referred people interested in the development process to this blog I thought it was time to give an update on the current status of Chunky.

Some of you may already be aware that I am a PhD student. This is in practice a more-than-full-time occupation. I work on Chunky mostly during my summer vacation, and a bit during Christmas. I can’t let Chunky interfere with my work, and that is the main reason that development has been on a hiatus now since summer.

With that in mind, I have some short-term goals for Chunky that I hope I can reach when I have time to tinker with Chunky again. First, entity rendering should be added in a snapshot release. There is some partial entity support currently that I have in my development branch. The rendering pipeline and scene graph is in need of some significant refactoring in order to implement entities in a nicer way, so it might require a lot of work.

During the summer I worked on some improvements for sky rendering, but there is more that can be done in that area. I would like to improve the fog/atmosphere effects. This also ties in to the rendering pipeline refactoring. The new 3D cloud feature was hampered by a really bad rendering pipeline architecture.

In the distant future I would like to add an entity posing tool and a material editor. These are large components that would take a lot of work to design and implement but I think they would be really great additions to Chunky.

Of course, the often-requested GPU rendering support would also be fun to continue work on.

I don’t know when I can start working on the entity support again. My work is taking up much of my “free time” currently. I might be able to code some on Chunky around Christmas, hopefully!

2 Comments on Chunky 2014 Fall Update
Categories: Chunky

Chunky 1.2.1 Released! 2014-01-03

The 1.2 release was big and unwieldy. I knew there were bound to be a bunch of bugs because I had changed so very much in the code since the previous release, however the launcher was the worst in terms of bugs and usability problems. The launcher looked like it was in a pretty decent state when I released 1.2, but immediately after the release I had to hotfix a problem that could cause it to ignore new releases in favor of snapshots. Then I started seeing comments from users that were unable to launch Chunky and the launcher would just close without an error. Further bugs became apparent when I was testing the launcher and fixing the previously mentioned problems.

The past couple days have been pretty intense in terms of bug fixing activity as I’ve tried to fix all the major problems with the launcher. Now again I think that the launcher is in a decent working state, but I am sure that there will appear new bugs to fix when people start using it and uncover new problems.

Version 1.2.1 should be a lot more stable than 1.2.0. I fixed a lot of things besides the launcher bugs. For example I fixed an issue that caused the scene selector to load the skymap for each and every available scene. I also fixed a rendering problem when using the parallel/isometric projector, and a problem that made it impossible to enable snapshot saving properly.

Click here to view the 1.2.1 release thread.

No Comments on Chunky 1.2.1 Released!
Categories: Chunky

Chunky 1.2 Progress 2013-12-15

I just pushed a huge commit to Chunky — 222 changed files with 7257 additions and 2022 deletions! Here’s the short list of changes:

  • Added launcher
    • allows specifying minecraft directory and Java runtime
    • can launch any locally available version of Chunky
    • has a debug console
    • has an online updater
    • still allows headless mode
  • Added First-Time Setup Dialog
  • Added custom Json library generated with JastAdd
  • Split Chunky into separate eclipse projects
    • added separate launcher project
    • added separate common library project
  • Update text field of adjuster on clamp
  • Use JSON to store Chunky settings
  • Highlight blocks targeted in render preview
  • Implemented stained glass block
  • Refactored rendering
    • added WorkerState class to keep thread-local worker state
  • Scene Selector now shows canvas size, current SPP and total render time
  • Added seed display in World Selector
  • Added ESC shortcut to close dialogs
  • Fixed error in scene name truncation
  • Fixed test renderer to work with new camera
  • Scenes now stored in Json format (SDF 2)
  • Changed sample buffer into a flat array
  • Made dump frequency editable
  • Implemented save snapshot checkbox
  • Added Acacia and Dark Oak
  • Added packed ice

Normally I would have publish one change at a time, but there were some big changes I started working on that were not finished until now that worked as show stoppers. The reason is simply my desire to not leave the public repository in a blatantly broken state – you should be able to check out any commit and know that it has no major bugs.

Anyway, that’s a big list of changes and some of them are not backward compatible with previous Chunky versions so I’ve decided that this will go into version 1.2. One important thing that has changed is the Scene Description Format (SDF) which is now based on JSON. SDF used to be called “Chunk View Format” and was based on NBT – the same data format used for Minecraft levels. The problem with NBT is that it is a binary format, which makes NBT files difficult to edit since you need a special tool, rather than just a text editor. I want SDF files to be easily editable so that people can simply tweak something in their scene by editing the SDF file for it. To make this even more obvious I decided to use the ‘.json’ extension for SDF files.

Here is a short snippet from a file using the new Scene Description Format:

{
  "sdfVersion": 2,
  "name": "test_1.7.4",
  "width": 400,
  "height": 400,
  "exposure": 1.0,
  "postprocess": 1,
  "renderTime": 14823,
  ...

Another nice thing about JSON is that the JSON format is very widely used and many scripting languages can handle JSON without much hassle. I hope that this will make it simpler for people to script their scenes and do for example animation just using a script that runs Chunky as a batch process.

I have some things left to do before I will start making release candidates. I want to add more MC 1.7.2 features such as stained glass panes and the new biome colors. I also intend to change the way chunks are represented internally in Chunky. I want to move from the Octree data structure currently used to something more like the structure which Minecraft worlds are saved in. I’ll write more about the Octree stuff in another blog post.

Comments Off on Chunky 1.2 Progress
Categories: Chunky

Faster Math 2013-06-22

One of the first optimizations I did in Chunky’s was to get rid of some java.lang.Math calls. By implementing a custom floor method I was able to speed up the rendering quite a bit. You may be wondering why that function was important, and how I could be much faster than Java’s built-in math library. I’ll answer these questions and then talk about a recent optimization that improved Chunky’s preformance by at least 8 percent!

Why is floor important?

Chunky uses an octree to represent Minecraft worlds. Each block in a world is represented using integer coordinates in the octree. The floor function is used to translate the floating-point coordinates used in the ray-tracing algorithm into integer block coordinates. The floor function is called repeatedly in the most important loop in the rendering aglorithm, so any improvement to the function’s running time results in a large speedup of the entire rendering algorithm.

The below graph shows a performance comparison for Chunky using the standard floor function and my custom version:

Performance improvements from replacing floor

Performance improvements from replacing floor

Why is java.lang.Math slow?

The built-in Java math functions need to deal with all kinds of edge cases. For example what happens if you pass NaN (Not a Number) as an argument? Or infinity? Or negative zero? Some of these edge cases require an extra conditional branch, which really hurts runtime performance. In Chunky we can usually disregard these edge cases. That’s what I did to get a faster floor function. I just don’t care what happens if a NaN or infinite float show up, because the code guards against such incorrect values. If any computation produces such a value the result would be incorrect regardless of how floor handles it.

FastMath

The Apache Commons Math library includes a class named FastMath that provides quicker implementations of the standard math functions found in java.lang.Math. The techniques used to improve performance here are a bit different compared to my floor hack. The FastMath functions, to my knowledge, should follow the same specifications as the java.lang.Math functinos.

A user on GitHub named twirrim recently submitted a pull request that replaced all remaining calls to java.lang.Math by calls to FastMath. By doing this he improved the performance of Chunky by at least 8% (on my machine, could vary on other machines)! Pretty impressive! The calls he changed were not as frequent as the floor calls discussed above, but still important enough that they apparently made a big performance difference.

Here is a graph showing the before and after performance (higher is better) of a Chunky benchmark using different numbers of render threads on a 4-core machine (8 hyperthreads):

The black bars indicate 90% confidence intervals for the measurements

The black bars indicate 90% confidence intervals for the measurements

No Comments on Faster Math
Categories: Chunky

Chunky Goals 2013-05-05

Sometimes people ask me what I’m planning to work on in Chunky. I have a set of goals that I want to achieve, and a rough idea of what order I want to work on these goals.

My current goals are (ordered after approximate priority):

  • More Sky Options – control over sky light multiplier, custom sky color gradients, improved clouds, night mode, etc.
  • Material Editor – allow changing block textures, reflectance, emittance
  • Improved Scene Manager
  • Distributed Rendering
  • New CPU Renderer – add a renderer with better convergence rate for indoor scenes
  • OpenCL GPU Renderer
  • Entity Rendering – render paintings, mobs, boats etc.

That’s a big list. Many of those goals require a lot of work. The first item, More Sky Options, is what I’m planning for version 1.2, but when and in what order the others are implemented is undecided. Usually I am distracted by my job, bugfixes and minor features.

2 Comments on Chunky Goals
Categories: Chunky