Skip to content

Refactor the path tracer - #1830

Open
Peregrine05 wants to merge 173 commits into
chunky-dev:masterfrom
Peregrine05:new-pt
Open

Peregrine05 wants to merge 173 commits into
chunky-dev:masterfrom
Peregrine05:new-pt

Conversation

@Peregrine05

@Peregrine05 Peregrine05 commented Aug 27, 2025 •

Copy link
Copy Markdown
Member

Closes #26
Closes #361
Closes #502
Closes #612
Closes #636
Closes #665
Closes #893
Closes #980
Closes #1162
Closes #1230
Closes #1258
Closes #1409
Closes #1476
Closes #1477
Closes #1482
Closes #1515
Closes #1591
Possibly closes #1617
Possibly closes #1642
Closes #1669
Closes #1671

Closes #1494 in favor of this
Closes #1577 in favor of this
Closes #1601 in favor of this
Includes the changes from #1627, and adds a GUI for the reference color system.
Closes #1660 in favor of this
Closes #1668 in favor of this
Closes #1673 in favor of this
Includes the changes from #1809

The primary purpose of this PR is to refactor the path tracer to use a simple ray, and intersection records. The new ray stores a Vector3 origin, a Vector3 direction, the material it is traversing, and a flags integer. The IntersectionRecord stores distance, geometry normal, shading normal, uv coordinates, material, color, and a flags integer.

I fixed a few other problems, but unfortunately did not think to change branches while doing so.

Notably:

  • I made use of the ControlsFX library for the ToggleSwitch control, which is a better design choice than a CheckBox when the effects of the control are realized immediately, rather than later.

  • The Lighting tab was removed. Its contents pertaining to the sky and to the sun were relocated to the new Environment tab. The contents pertaining to emitters were relocated to the new Emitters tab.

  • The Sky & Fog tab was removed. Its contents pertaining to the sky were relocated to the Environment tab. Its contents pertaining to fog and clouds were relocated to the new Fog & Clouds tab.

  • The Water visibility, Water opacity, and water color controls were removed, in favor of using material properties to control these properties. Notably, biome-tinted water is no longer possible, but it doesn't look realistic to begin with.

  • More material properties were added to the Materials tab.

  • Materials can be right-clicked in the render preview to be edited through a dialog box. The advantages of this approach are that individual blockstates can be edited, which is something that the Materials tab does not support. While changes to octree materials are saved to the blockPalette, allowing them to persist through scene saves and restarts, they are not saved to the scene.json, making external editing difficult. Also, individual materials in the BVH can be edited; however, since individual BVH materials are not saved to the scene.json, these changes will not persist through scene saves and restarts.

These material properties are:

  • Emittance color: Changes the tint of the color of emitted light.

  • Emitter mapping offset: See Color-based, per-material emittance mapping #1627 for details.

  • Emitter mapping type: See Color-based, per-material emittance mapping #1627 for details.

  • Use reference colors: Extracted this option to its own control, so that it can be used in conjunction with the other emitter mapping types.

  • Alpha: Changes the opacity of the texture.

  • Subsurface scattering: Changes the percentage of rays that have their normal inverted, so that they scatter to the other side of the texture.

  • Diffuse color: Changes the tint of diffuse reflections.

  • Specular: Changes the percentage of rays that are specularly reflected with no texture tinting.

  • Transmission smoothness: Changes the smoothness for transmitted and refracted rays.

  • Opaque: This option requires a chunk reload for its effects to be realized.

  • Hidden: Prevents intersections with this material entirely.

  • Volume density: When the current ray medium is the selected material, this sets the density of the volume scatter medium.

  • Absorption: Rays travelling through the medium will be attenuated if the value is greater than 0.

  • Metalness: Changes the percentage of specularly-reflected rays that are texture-tinted.

  • Transmission metalness: Changes the percentage of specularly-transmitted or refracted rays that are texture tinted.

The reference color GUI should be self-explanatory.

Other things of note are:

  • Branched path tracing is not functional at the moment. The infrastructure is still present in the renderer, but it is not implemented in the path tracer. As such, branch count is hard-coded to 1, and the control is hidden.

  • Fancier translucency is removed, because the new path tracer should handle transparent colors correctly* (At least it seems to do so.)

  • The sun sampling options have been changed. Sample through opacity does what Chunky's current FAST does. Sample only stops when it hits certain interactions (like glass). Diffuse treats the sun as part of the skymap. Mix allows diffuse sun intersections after hitting those certain interactions that Sample only does not handle, but prevents diffuse sun intersections when sampling the sun directly is possible. Overall, the results should be the same as with Diffuse.

  • Draw sun enables or disables sunlight entirely, through adding or removing the sun texture from the skymap. It does not stop "sun sampling", however, as Chunky will still sample the sky where the sun is. This can be used to sample an HDRi, for example.

  • Use flat texture overrides the sun texture provided by the resource pack with a simple solid color square. It is enabled by default, and should be used when you want a specific sun color.

  • Sunlight color tints the sun texture when Use flat texture is disabled, and controls the sun color directly when it is enabled.

  • The Nishita sky model now has many more customization options available.

There may still be plenty of bugs, so this PR could use some testing.

@Peregrine05

Copy link
Copy Markdown
Member Author

To build and run the PR, follow the instructions below.


Download ControlsFX from here: https://repo1.maven.org/maven2/org/controlsfx/controlsfx/11.2.1/controlsfx-11.2.1.jar

Create a new folder somewhere, such as controlsfx in the .chunky folder. Add the ControlsFX Jar to the folder.

Build Chunky with ./gradlew buildReleaseJar. (The update site doesn't seem to work for this PR.) Run the build (which will be in build/installer/).

In the Java options field in the Launcher, move the cursor to the end of the value of the --module-path argument. Enter a semicolon ;, and then add the path to the folder containing the ControlsFX Jar. Then move the cursor to the end of the value of the --add-modules argument. Enter a comma ,, and then enter: org.controlsfx.controls.

Your Java options should look something like:

--module-path /home/user/.chunky/javafx/javafx-sdk-17.0.2/lib;/home/user/.chunky/controlsfx --add-modules javafx.controls,javafx.fxml,org.controlsfx.controls

leMaik and others added 30 commits November 3, 2026 19:20
(cherry picked from commit 5192f64)
(cherry picked from commit c3b4bb3)
* Add sulfur spikes.

* Add the new bed models and refactor loading bed textures to map old textures to the new format.

* Fix hard-coded legacy bed texture scale.

(cherry picked from commit 4676936)
* Add an adapter to convert old sign textures to 26.2 sign textures.

* Update the sign model.

* Update the wall sign model.

* Add an adapter to convert old hanging sign textures to 26.2 sign textures.

* Update the hanging sign model.

* Update the wall hanging sign model.

(cherry picked from commit 59ed6de)
…nd EmptyDimension. (chunky-dev#1905)

* Resolve cyclic dependency between static initializers of EmptyWorld and EmptyDimension.

* Ensure that EmptyWorld cannot change dimension.

(cherry picked from commit 156e2bb)
…hunky-dev#1376)

* Allow Blocks and Entities to return multiple Entities

Lecterns are no longer poseable
Lecterns now return both the lectern and its book.

* Use Collections.singleton instead of Collections.singletonList.

* Throw UnsupportedOperationException instead of Error when trying to create entities or block entities from blocks that don't support this.

* Rename some entity-related block methods and add more documentation to clarify how entities and block entities work.

* Make Entities#fromJson return a single entity, legacy entities now handled by caller

---------

Co-authored-by: Maik Marschner <leMaik@leMaik.de>

(cherry picked from commit b1bd7fa)
…er time. (chunky-dev#1911)

* Calculate samples per second from time per pass instead of total render time.

* Apply batched suggestions from code review

Fix ns to ms conversion.

Co-authored-by: Maik Marschner <m.marschner@wertarbyte.com>
(cherry picked from commit f2f7ab8)
… match Minecraft (chunky-dev#1915)

* Add support for new chunk format

* Update default block states to match Minecraft

* Remove unused import

* Update BlockPaletteTest.java

* Actually add support for the 26.3 chunk format

(cherry picked from commit 65db8a6)
* Add blocks from 26.3 snapshot 1

* Remove unused import

* Fix copy error

* Add age to shelf mushroom description.

* Move shelf mushroom texture selection into the model code.

---------

Co-authored-by: Maik Marschner <m.marschner@wertarbyte.com>
(cherry picked from commit 73497cd)
chunky-dev#1895)

* Create a single place for all chunky thread/executors to be registered
Closes chunky-dev#1893

- Allows chunky to close them on shutdown without a System.exit()
- Additionally provides an api to wait on all chunky threads to be joined.

* Fix race between joinAll and extremely lately added threads/executors

* Make joinAll not synchronized

* Return whether all threads were joined from joinAll methods

* Add Chunky's ForkJoinPool to ChunkyThread

* Change ExecutorService thread factory

* Add PluginApi to relevant ChunkyThread methods

* Add shutdown hook to handle early System.exit()

* Put interruptAndJoinAll in a finally block

* Switch back to ConsoleReceiver on UI stop

* Move the shutdown hook out of ChunkyThread, now managed by Chunky itself

* Remove PluginApi from joinAll

* Refactor ChunkyThread joinAll to give stronger guarantees

And hopefully be more readable

(cherry picked from commit a52b9bc)
* Remove jank in PluginManager

* Remove unnecessary chunky.plugins.maxLoadCycles jvm arg.

The comment already explains that the worst case cannot take more cycles
than the number of plugins to load, so we use that.

* Implement plugin shutdown

(cherry picked from commit f10ef3f)
(cherry picked from commit fa85002)
(cherry picked from commit 5c3ffc6)
(cherry picked from commit 053bf04)
…to remove implicit format dependencies.

(cherry picked from commit 891d6ad)
# Conflicts:
#	chunky/src/java/se/llbit/chunky/block/BlockSpec.java
#	chunky/src/java/se/llbit/chunky/block/MinecraftBlockProvider.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/CopperGolemStatue.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/CoralFan.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/Head.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/Lava.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/Lectern.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/LilyPad.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/SporeBlossom.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/WallCoralFan.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/WallHead.java
#	chunky/src/java/se/llbit/chunky/block/minecraft/Water.java
#	chunky/src/java/se/llbit/chunky/chunk/BlockPalette.java
#	chunky/src/java/se/llbit/chunky/entity/ChickenEntity.java
#	chunky/src/java/se/llbit/chunky/entity/Entity.java
#	chunky/src/java/se/llbit/chunky/entity/MooshroomEntity.java
#	chunky/src/java/se/llbit/chunky/entity/PlayerEntity.java
#	chunky/src/java/se/llbit/chunky/model/AABBModel.java
#	chunky/src/java/se/llbit/chunky/model/minecraft/GlassPaneModel.java
#	chunky/src/java/se/llbit/chunky/model/minecraft/ObserverModel.java
#	chunky/src/java/se/llbit/chunky/model/minecraft/PressurePlateModel.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/OctreeFinalizer.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/Scene.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/SceneEntities.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/sky/Sky.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/sky/Sun.java
#	chunky/src/java/se/llbit/chunky/renderer/scene/watershading/WaterShader.java
#	chunky/src/java/se/llbit/chunky/resources/SignTexture.java
#	chunky/src/java/se/llbit/chunky/ui/controller/ChunkyFxController.java
#	chunky/src/java/se/llbit/chunky/ui/render/tabs/EntitiesTab.java
#	chunky/src/java/se/llbit/chunky/world/ExtraMaterials.java
#	chunky/src/java/se/llbit/math/Octree.java
#	chunky/src/java/se/llbit/math/Vector3.java
#	chunky/src/res/se/llbit/chunky/ui/render/tabs/GeneralTab.fxml
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment