Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
173 commits
Select commit Hold shift + click to select a range
a50c842
Initial testing
Peregrine05 Nov 17, 2023
ea4b35d
Remove Point3, Point3i, and Tuple3
Peregrine05 Nov 18, 2023
422d7e2
Just save changes
Peregrine05 Jun 1, 2024
e39d23b
Save changes
Peregrine05 Jun 1, 2024
5a949f7
Save changes
Peregrine05 Jun 5, 2024
07ebdd6
Save changes
Peregrine05 Sep 4, 2024
ca739fe
Save Changes
Peregrine05 Sep 4, 2024
574bfdb
Fix IllegalArgumentException
Peregrine05 Sep 4, 2024
e652b8b
Sample sky, fix bamboo, camera JSON
Peregrine05 Sep 5, 2024
7c3dd20
Code cleanup
Peregrine05 Sep 5, 2024
17e4233
Revert clouds changes
Peregrine05 Sep 30, 2024
80ca921
Maybe better scattering
Peregrine05 Oct 17, 2024
8e3a777
Fix blackness on BVH intersections
Peregrine05 Oct 17, 2024
bd0ca90
Save changes
Peregrine05 Aug 27, 2025
71bf1b8
Add label to emitterMappingType
Peregrine05 Aug 27, 2025
8f44acc
Move controls and remove unused controls
Peregrine05 Aug 27, 2025
616ee90
Disable branched path tracing
Peregrine05 Aug 27, 2025
8eb0ebb
Remove mistakenly added files
Peregrine05 Aug 28, 2025
fae3326
Fix file permissions
NotStirred Aug 28, 2025
66374ce
Merge pull request #19 from NotStirred/fix/file_perms
Peregrine05 Aug 28, 2025
210af3a
Rename Ray2 to Ray
Peregrine05 Aug 28, 2025
448f51e
Fix cloud layer GUI
Peregrine05 Aug 28, 2025
f53cf15
Remove commented-out code
Peregrine05 Aug 29, 2025
3da6dbd
Hit water plane if it is enabled
Peregrine05 Aug 29, 2025
1f45521
Hit water plane with cauldron model
Peregrine05 Aug 29, 2025
c6a87c1
Improve tintColor
Peregrine05 Aug 29, 2025
fb8ea8d
Fix incorrect normal with water
Peregrine05 Aug 29, 2025
d4af62b
Update PluginApiTest
Peregrine05 Aug 29, 2025
6595366
Undo unnecessary changes
Peregrine05 Aug 29, 2025
186095c
Move path tracer functionality to methods
Peregrine05 Sep 3, 2025
151244c
Fix chunks of void in octree loaded chunks
Peregrine05 Sep 3, 2025
6c4a8e6
Slight code simplification
Peregrine05 Sep 3, 2025
5298d7e
Improve render preview tooltip information
Peregrine05 Sep 3, 2025
86f73cf
Interface to flags for Ray and IntersectionRecord
Peregrine05 Sep 3, 2025
7bcd191
Revert unnecessary changes
Peregrine05 Sep 3, 2025
85a0a81
Remove magic boolean in Leaves
Peregrine05 Sep 3, 2025
da435d1
Give CopperGrate its own class
Peregrine05 Sep 3, 2025
7ed87c5
Revert changes to entities, in favor of #1376
Peregrine05 Sep 3, 2025
e67112c
Undo changes to ApertureShape in favor of #1835
Peregrine05 Sep 3, 2025
bbe3b08
Remove duplicate code
Peregrine05 Sep 5, 2025
64317d8
Remove commented code
Peregrine05 Sep 5, 2025
1df659a
Revert changes to clouds
Peregrine05 Sep 5, 2025
7cd1cdc
`onEdge` only needs the distance.
Peregrine05 Sep 5, 2025
6e12575
undo spelling change
Peregrine05 Sep 6, 2025
44d9536
no newline at end of file
Peregrine05 Sep 6, 2025
72ca976
Add comments and Javadoc
Peregrine05 Sep 7, 2025
8b10d53
Fix issue with intersection
Peregrine05 Sep 8, 2025
1031807
Fix intersection issues with glass panes
Peregrine05 Sep 8, 2025
2db9936
Fix issue with ESS
Peregrine05 Sep 9, 2025
0d3b541
Simplify code slightly
Peregrine05 Sep 9, 2025
43ad930
Move `skyOcclusion` to `Scene`.
Peregrine05 Sep 10, 2025
b9ae5a9
Fix subsurface scattering
Peregrine05 Sep 11, 2025
549aa01
Add `Remove all entities` control
Peregrine05 Sep 11, 2025
9884339
Remove unused constants
Peregrine05 Sep 11, 2025
2177fd3
Fix sky emittance JSON
Peregrine05 Sep 11, 2025
5e8a954
Remove unused constant
Peregrine05 Sep 11, 2025
a2a1275
Remove commented out code
Peregrine05 Sep 12, 2025
7e8cd85
Fix removing non-actors not rebuilding the non-actor BVH
Peregrine05 Sep 12, 2025
baef6f8
Implement AgX tonemapping and Vignette filter
Peregrine05 Sep 12, 2025
d51caf9
Remove output clamping from AgX tonemapping
Peregrine05 Sep 12, 2025
f406187
Merge branch 'master' into new-pt
Peregrine05 Sep 13, 2025
8c19819
Update ColorUtilTest.java
Peregrine05 Sep 13, 2025
b35a9b8
Update copyright date and add credit to ControlsFX
Peregrine05 Sep 13, 2025
0cd442f
Fix Materials tab controls not updating
Peregrine05 Sep 14, 2025
e693825
Use correct block ID for `resin_brick_wall`
Peregrine05 Sep 14, 2025
19bf279
Parse canvasConfig width and height if present
Peregrine05 Sep 14, 2025
f9d6c4f
Actually save cloudLayers to JSON
Peregrine05 Sep 15, 2025
0b4c374
Fix glass panes model and intersection
Peregrine05 Apr 15, 2026
d51c8cf
Fix clouds intersection at octree edge
Peregrine05 Apr 15, 2026
48f6bf2
Don't edit the ray medium
Peregrine05 Apr 15, 2026
c2c7127
Make beacon beams reach Y=2048
Peregrine05 Jun 28, 2026
f93f1f7
Add a control to copy the target color
Peregrine05 Jun 28, 2026
99097c9
Add missing material controls to dialog
Peregrine05 Jun 28, 2026
0ebbf9e
Fix intersections with entities outside octree
Peregrine05 Jun 28, 2026
f468e5a
Allow changing material properties per blockstate
Peregrine05 Jun 28, 2026
e29289c
Use better names
Peregrine05 Jul 6, 2026
0128932
Use Edit Material dialog for sphere entity
Peregrine05 Jul 6, 2026
24496db
Fix slow entity selection with long entity lists
Peregrine05 Jul 6, 2026
de175d6
Build fog BVH when loading or building octree
Peregrine05 Jul 6, 2026
6d00051
Fix texture interpolation control
Peregrine05 Jul 16, 2026
e6236fc
Fix texture interpolation for mirrored skymap mode
Peregrine05 Jul 16, 2026
03ca232
Fix water plane intersections at bottom of octree
Peregrine05 Jul 16, 2026
64879f2
Fix water shader settings not loading from file
Peregrine05 Jul 16, 2026
303d68f
Use better names
Peregrine05 Oct 9, 2026
4bf72ff
Quad entity
Peregrine05 Oct 9, 2026
b4c77e3
Fix build config to match Chunky's master branch
leMaik Oct 9, 2026
05ec86a
Improve delta tracking performance
Peregrine05 Oct 17, 2026
df58aee
Improve readability in PathTracer.java
Peregrine05 Oct 17, 2026
cd72918
Fix crash when loading some resource packs. (#1838)
leMaik Sep 13, 2025
652cbc9
Fix error when trying to close LayeredResourcePack where the filesyst…
leMaik Sep 14, 2025
1e62109
Improve spherical aperture projector by allocating less objects.
leMaik Sep 14, 2025
2170828
Remove unused Model.scale and Quad.getScaled.
leMaik Sep 14, 2025
ac52531
Update glass pane model to match the ingame model and not include ext…
leMaik Sep 14, 2025
7d75178
Use y-clipping settings from the map view when creating a new scene o…
leMaik Sep 20, 2025
0a2b991
Fix pressed pressure plates, observer and attached tripwire block mod…
leMaik Sep 21, 2025
e4288e5
Update dragon egg and small dripleaf models (#1844)
leMaik Oct 4, 2025
71eecc1
Improve AABB model performance. (#1845)
ThatRedox Oct 4, 2025
d71ec21
Fix method signature
Peregrine05 Nov 1, 2026
20a5986
Add the copper golem statue. (#1848)
leMaik Nov 3, 2025
11590f2
Fix error when loading worlds with custom heads that have no uuid and…
leMaik Dec 11, 2025
20698ad
Fix missing sun texture in 1.21.11 or later. (#1854)
leMaik Dec 21, 2025
d6dd1c3
Fix loading grayscale textures being too bright sometimes.
leMaik Oct 4, 2025
263b6f8
Remove obsolete workaround for Java 8 ImageIO not supporting PNGs wit…
leMaik Oct 4, 2025
1033238
Remove Refreshable interface
Peregrine05 Nov 2, 2026
7460af8
Fix indentation
Peregrine05 Nov 2, 2026
f0be9de
Delete duplicated code
Peregrine05 Nov 3, 2026
04090df
Rename water corner constants and variables
Peregrine05 Nov 3, 2026
0c144a0
Mark farmland as solid.
leMaik Dec 24, 2025
75cded3
Fix water blocks on chunk borders having the wrong height if there is…
leMaik Nov 3, 2026
7cc25bb
Add missing description for pointed dripstone.
leMaik Dec 24, 2025
ec9dd9c
Apply material properties to block directly
Peregrine05 Nov 3, 2026
327e5b1
Remove special cases for waterlogging and make the waterlogged field …
leMaik Dec 24, 2025
38ecfe3
Use getter instead of directly accessing attribute
Peregrine05 Nov 3, 2026
1fe45a8
Move waterlogged to the Block class.
leMaik Dec 24, 2025
022a168
Use new method
Peregrine05 Nov 3, 2026
3963f9b
Fix camera not being centered above the selected chunks when creating…
leMaik Dec 27, 2025
0cc576a
Fix the scenes directory picker not showing up if the scenes director…
leMaik Jan 1, 2026
bc58f15
Do not show the camera tooltip if the window is not focused.
leMaik Jan 1, 2026
8727a88
Do not resize the right control panel when resizing the left control …
leMaik Jan 1, 2026
662b871
Fix entity face camera and face target buttons.
leMaik Jan 1, 2026
9b583a1
Fix hide water plane not working in chunks that don't use the biome c…
leMaik Jan 3, 2026
1085cbb
Fix negative distance resulting in infinite attenuation due to almost…
leMaik Nov 4, 2026
712a1ff
Implement new skin resolution logic for 25w34a and later.
leMaik Jan 4, 2026
48b2060
Fix player and armorstand armor not being rendered in worlds created …
leMaik Jan 4, 2026
56cfa36
Add copper armor support for players and armor stands.
leMaik Jan 4, 2026
e0d0d19
Fix missing armor texture when using Minecraft 24w36a or later.
leMaik Jan 6, 2026
631540c
Add golden dandelion and potted golden dandelion. (#1867)
leMaik Feb 5, 2026
395fe25
Make default material properties of weighted pressure plates consiste…
JustinTimeCuber Feb 6, 2026
e385356
Add support for the new world directory structure and remove the expo…
leMaik Mar 4, 2026
1a0cf80
Pre-compute the chiseled bookshelf textures. (#1874)
leMaik Mar 28, 2026
6b27c15
Add 26.1 entity texture paths.
leMaik Mar 28, 2026
c6e9853
Remove obsolete markdown link from credits.
leMaik Mar 28, 2026
6708d80
Update the copyright line.
leMaik Mar 29, 2026
8dc25ce
Fix loading players saved with older Chunky versions. (#1876)
leMaik Apr 6, 2026
b431b4c
Fix crash when loading a biome fails and show a warning instead.
leMaik Apr 8, 2026
b5a5328
Make banner pattern and painting variant loading warnings more helpful.
leMaik Apr 8, 2026
17ff063
Update resourcepack biomes loader to support new color formats (#1879)
leMaik Apr 8, 2026
49a6f8f
Fix armorstand and beacon beam textures in new resource packs. (#1881)
leMaik Apr 10, 2026
65c931e
Fix crash when rendering older scenes that have no dry foliage texture.
leMaik Apr 15, 2026
705430b
Fix crash on world loading when there is no single player uuid.
leMaik Apr 15, 2026
f87ab08
Fix error when loading the world if the singleplayer uuid is null. (#…
leMaik Apr 16, 2026
3e0f1aa
Warn about unsupported blocks after chunk loading (#1880)
mvanhorn Apr 20, 2026
7ca1deb
Fix scene reset warning blocking input events for all other dialogs. …
leMaik Apr 26, 2026
c837179
Show block properties of unknown blocks.
leMaik May 2, 2026
07dd309
Fix duplicate "minecraft:" in unknown blocks name.
leMaik May 2, 2026
fcf0760
Add the sulfur caves biome.
leMaik May 2, 2026
f48135f
Add new sulfur and cinnabar blocks.
leMaik May 2, 2026
cc7fcb6
Add support for 26.2 snapshot 3 (#1887)
leMaik May 19, 2026
8ebecc5
Add support for 26.2 snapshot 7 (#1889)
leMaik May 19, 2026
ab6c87c
Add new texture paths of quartz_pillar and purple_pillar. (#1891)
leMaik May 26, 2026
e3c93b4
Prevent an invalid world from breaking the world chooser dialog (#1896)
NotStirred Jul 13, 2026
073ddec
Fix CLI not always printing the render completed message. (#1890)
leMaik Jul 14, 2026
feef6b9
Fix biome texture being empty if any chunk has no blocks that are aff…
leMaik Jul 17, 2026
a6c5a24
Remove obsolete error handling for Java 8.
leMaik Jul 25, 2026
385879a
Resolve cyclic dependency between static initializers of EmptyWorld a…
leMaik Jul 26, 2026
845c1cb
Separate Lectern and Book to match enchantment tables and its book (#…
NotStirred Aug 30, 2026
6500b67
Allow loading and saving render dumps programmatically without scenes…
leMaik Aug 30, 2026
c889646
Calculate samples per second from time per pass instead of total rend…
leMaik Aug 31, 2026
900cfe4
Make the new render dump save methods non-static. (#1912)
leMaik Sep 5, 2026
120ced2
Add support for 26.3 chunk format, and update default block states to…
Peregrine05 Oct 13, 2026
070797c
Add blocks from 26.3 snapshot 1 (#1916)
Peregrine05 Oct 13, 2026
364a7f4
Add blocks from 26.3 snapshot 7 (#1917)
Peregrine05 Oct 13, 2026
1c86de4
Create a single place for all chunky thread/executors to be registere…
NotStirred Oct 13, 2026
efb9907
Add a shutdown hook to Plugin (#1902)
NotStirred Oct 13, 2026
596d78d
Add the straw bed block and an internal entity for the out-of-block-b…
leMaik Oct 24, 2026
c7debd8
Cleanup bed implementation.
leMaik Oct 24, 2026
d55c6da
Fix only the entities of blocks that are not replaced by entities bei…
leMaik Oct 24, 2026
cfe47d1
Add cushions.
leMaik Oct 24, 2026
ee587ef
Fix invalid palette serialization.
NotStirred Oct 24, 2026
a030088
Inline BlockSpec serialization and deserialization into BlockPalette …
leMaik Oct 27, 2026
b0377ad
Add volume emittance color
Peregrine05 Nov 4, 2026
9d402a5
Merge branch 'master' into new-pt
Peregrine05 Nov 5, 2026
1f7194b
Remove duplicated method
Peregrine05 Nov 5, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ For guides and more information please checkout the [Documentation][chunky-dev].
<details>
<summary><strong>Which Minecraft versions are supported?</strong></summary>

> Chunky 2.4.4 supports Minecraft 1.2-1.19.2 worlds and Cubic Chunks for Minecraft 1.10-1.12 worlds.
> Chunky 2.5.0 supports Minecraft 1.2-1.21.8 worlds and Cubic Chunks for Minecraft 1.10-1.12 worlds.
>
> We typically add new blocks shortly after a new Minecraft snapshot is released. Use the latest Chunky snapshot to render them until a new Chunky version is released.

Expand Down Expand Up @@ -189,7 +189,7 @@ when in doubt.

## Copyright & License

Chunky is Copyright (c) 2010-2023, Jesper Öqvist <jesper@llbit.se> and [Chunky Contributors][chunky-contributors].
Chunky is Copyright (c) 2010-2025, Jesper Öqvist <jesper@llbit.se> and [Chunky Contributors][chunky-contributors].

Permission to modify and redistribute is granted under the terms of
the GPLv3 license. See the file `LICENSE` for the full license.
Expand Down Expand Up @@ -221,6 +221,8 @@ Chunky uses the following 3rd party libraries:
See the file `licenses/Apache-2.0.txt` for the full license text.
See the file `licenses/lz4-java.txt` for the copyright notice.
lz4-java uses LZ4, by Yann Collet, which is covered by the BSD 2-Clause license. See the file `licenses/lz4.txt` for the copyright notice and full license.
- **ControlsFX by the ControlsFX Project team**
The library is released under the BSD 3-Clause license. See the file `licenses/controlsfx.txt` for the copyright notice and license text.

## Special Thanks

Expand Down
1 change: 1 addition & 0 deletions chunky/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
implementation 'it.unimi.dsi:fastutil:8.4.4'
implementation 'org.apache.commons:commons-math3:3.2'
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'org.controlsfx:controlsfx:11.2.1'
implementation 'org.lz4:lz4-java:1.8.0'
implementation 'org.apache.maven:maven-artifact:3.9.9'
implementation project(':lib')
Expand Down
188 changes: 184 additions & 4 deletions chunky/src/java/se/llbit/chunky/block/AbstractModelBlock.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package se.llbit.chunky.block;

import se.llbit.chunky.block.minecraft.Water;
import se.llbit.chunky.model.BlockModel;
import se.llbit.chunky.model.minecraft.WaterModel;
import se.llbit.chunky.plugin.PluginApi;
import se.llbit.chunky.renderer.scene.Scene;
import se.llbit.chunky.resources.Texture;
import se.llbit.math.Ray;
import se.llbit.math.Vector3;
import se.llbit.math.*;

import java.util.Random;

Expand Down Expand Up @@ -41,9 +42,188 @@ public BlockModel getModel() {
return model;
}

/**
* Moves {@code o} to the intersection point (specified by {@code d} and {@code distance}),
* and checks if it is at the edge of the block.
* @param o Origin point (which is updated)
* @param d Ray direction
* @param distance Distance to intersection
* @return Whether the intersection point is on the edge of the block.
*/
public static boolean onEdge(Vector3 o, Vector3 d, double distance) {
o.scaleAdd(distance, d);
double ix = o.x - QuickMath.floor(o.x);
double iy = o.y - QuickMath.floor(o.y);
double iz = o.z - QuickMath.floor(o.z);
return !(Constants.EPSILON < ix && ix < 1 - Constants.EPSILON &&
Constants.EPSILON < iy && iy < 1 - Constants.EPSILON &&
Constants.EPSILON < iz && iz < 1 - Constants.EPSILON);
}

@Override
public boolean intersect(Ray ray, IntersectionRecord intersectionRecord, Scene scene) {
Intersectable waterModel = null;

// TODO this shouldn't be checked at intersection time, but rather when loading chunks.
boolean isWaterloggedFull = false;
if (waterlogged) {
// If this block is waterlogged, we check if the block above it is either water or
// waterlogged (isWaterFilled()).
// If it is, then the water model to use should be the `Block.FULL_BLOCK` full block model.
// Otherwise, the `WaterModel.NOT_FULL_BLOCK` model for a full water block exposed to air
// will be used.

int x = (int) QuickMath.floor(ray.o.x + ray.d.x * Constants.OFFSET);
int y = (int) QuickMath.floor(ray.o.y + ray.d.y * Constants.OFFSET);
int z = (int) QuickMath.floor(ray.o.z + ray.d.z * Constants.OFFSET);
isWaterloggedFull = scene.getWorldOctree().getBlock(x, y + 1, z, scene.getPalette()).isWaterFilled();
if (ray.getCurrentMedium().isWater()) {
if (!isWaterloggedFull) {
waterModel = WaterModel.WATER_TOP;
}
} else {
waterModel = (isWaterloggedFull) ? Block.FULL_BLOCK : WaterModel.NOT_FULL_BLOCK;
}
}

IntersectionRecord modelIntersect = new IntersectionRecord();
IntersectionRecord waterIntersect = new IntersectionRecord();

boolean modelHit = model.intersect(ray, modelIntersect, scene);
boolean waterHit = false;
if (waterModel != null) {
waterHit = waterModel.closestIntersection(ray, waterIntersect, scene);
}

// Whether the ray hits the top of the water model when the water model is not a full block.
boolean hitTop = waterHit && !isWaterloggedFull && waterIntersect.n.y > 0 && ray.d.dot(waterIntersect.n) > 0;

if (ray.getCurrentMedium() == this) {
// Ray is currently traversing this block.
if (modelHit) {
intersectionRecord.setNormal(modelIntersect);
if (ray.d.dot(intersectionRecord.n) > 0) {
// Ray is exiting the block.
Vector3 o = new Vector3(ray.o);
if (onEdge(o, ray.d, modelIntersect.distance)) {
return false;
}
intersectionRecord.n.scale(-1);
intersectionRecord.shadeN.scale(-1);

Block waterPlaneMaterial = scene.waterPlaneMaterial(ray.o.rScaleAdd(intersectionRecord.distance, ray.d));
if (waterlogged) {
if (isWaterloggedFull || o.y < 1 - WaterModel.TOP_BLOCK_GAP) {
intersectionRecord.material = scene.getPalette().water;
Water.INSTANCE.getColor(intersectionRecord);
} else {
intersectionRecord.material = waterPlaneMaterial;
waterPlaneMaterial.getColor(intersectionRecord);
}
} else {
intersectionRecord.material = waterPlaneMaterial;
waterPlaneMaterial.getColor(intersectionRecord);
}
} else {
// Ray is not exiting the block, but it hit a surface inside the block.
intersectionRecord.color.set(modelIntersect.color);
}
intersectionRecord.distance = modelIntersect.distance;
intersectionRecord.flags = modelIntersect.flags;
return true;
} else {
return false;
}
} else if (ray.getCurrentMedium().isWater()) {
// Ray is currently traversing water, whether that be the water part of the block (if it be
// waterlogged), or water outside the block.
if (!waterlogged && (!modelHit || modelIntersect.distance > Constants.EPSILON)) {
// Ray is currently traversing water, and the block is not waterlogged.
// Therefore, if we don't hit the block model, or the distance to the model hit is greater
// than zero, we need to hit the "air part" of the block, to take the material properties
// into account. If the intersection point is below the water plane, the water plane
// material is hit instead of air.
intersectionRecord.distance = 0;
Block waterPlaneMaterial = scene.waterPlaneMaterial(ray.o);
intersectionRecord.material = waterPlaneMaterial;
waterPlaneMaterial.getColor(intersectionRecord);
return true;
}
if (modelHit && modelIntersect.distance < waterIntersect.distance - Constants.EPSILON) {
// The ray hit the block model, and the distance to the block model intersection is closer
// than the distance to the water model intersection. As such, we hit the block model.
intersectionRecord.distance = modelIntersect.distance;
intersectionRecord.setNormal(modelIntersect);
intersectionRecord.color.set(modelIntersect.color);
intersectionRecord.flags = modelIntersect.flags;
return true;
} else if (hitTop) {
// The ray is traversing water, did not hit the block model, and has hit the top of the
// water model (not full block).
intersectionRecord.distance = waterIntersect.distance;
intersectionRecord.setNormal(waterIntersect);

Ray testRay = new Ray(ray);
testRay.o.scaleAdd(intersectionRecord.distance, testRay.d);
intersectionRecord.material = scene.waterPlaneMaterial(testRay.o);
intersectionRecord.material.getColor(intersectionRecord);

Vector3 shadeNormal = scene.getCurrentWaterShader().doWaterShading(testRay, intersectionRecord, scene.getAnimationTime());
intersectionRecord.shadeN.set(shadeNormal);

intersectionRecord.n.scale(-1);
intersectionRecord.shadeN.scale(-1);
return true;
} else {
return false;
}
} else {
// The ray is currently traversing any other material, such as air, glass, WaterPlane, etc.
if (!waterlogged && (!modelHit || modelIntersect.distance > Constants.EPSILON)) {
// As before, if the block is not waterlogged, we need to make sure to take the "air part"
// into account, whether that be air, or the water plane.
Block waterPlaneMaterial = scene.waterPlaneMaterial(ray.o);
if (ray.getCurrentMedium() != waterPlaneMaterial) {
intersectionRecord.distance = 0;
intersectionRecord.material = waterPlaneMaterial;
waterPlaneMaterial.getColor(intersectionRecord);
return true;
}
}
if (modelHit && modelIntersect.distance < waterIntersect.distance + Constants.EPSILON) {
// The ray hit the block model, and the distance is closer than the distance to the water
// model intersection.
intersectionRecord.distance = modelIntersect.distance;
intersectionRecord.setNormal(modelIntersect);
intersectionRecord.color.set(modelIntersect.color);
intersectionRecord.flags = modelIntersect.flags;
return true;
} else if (waterHit) {
// The water model intersection is closer.
intersectionRecord.distance = waterIntersect.distance;
intersectionRecord.setNormal(waterIntersect);
Water.INSTANCE.getColor(intersectionRecord);
intersectionRecord.material = scene.getPalette().water;
intersectionRecord.flags = 0;

if (intersectionRecord.n.y > 0) {
// Add water shading.
Ray testRay = new Ray(ray);
testRay.o.scaleAdd(intersectionRecord.distance, testRay.d);
Vector3 shadeNormal = scene.getCurrentWaterShader().doWaterShading(testRay, intersectionRecord, scene.getAnimationTime());
intersectionRecord.shadeN.set(shadeNormal);
}
return true;
} else {
// The ray did not hit anything.
return false;
}
}
}

@Override
public boolean intersect(Ray ray, Scene scene) {
return model.intersect(ray, scene);
public boolean isInside(Ray ray) {
return model.isInside(ray);
}

@Override
Expand Down
33 changes: 15 additions & 18 deletions chunky/src/java/se/llbit/chunky/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@
import se.llbit.chunky.world.biome.Biome;
import se.llbit.json.JsonString;
import se.llbit.json.JsonValue;
import se.llbit.math.AABB;
import se.llbit.math.Ray;
import se.llbit.math.Vector3;
import se.llbit.math.*;
import se.llbit.nbt.CompoundTag;
import se.llbit.nbt.Tag;

import java.util.Collection;
import java.util.Random;

public abstract class Block extends Material {
private final static AABB block = new AABB(0, 1, 0, 1, 0, 1);
public static final AABB FULL_BLOCK = new AABB(0, 1, 0, 1,0, 1);

/**
* Set to true if there is a local intersection model for this block. If this is set to
* <code>false</code> (default), this block is assumed to be an opaque cube block and {@link
* #intersect(Ray, Scene)} will never be called.
* #intersect(Ray, IntersectionRecord, Scene)} will never be called.
*/
public boolean localIntersect = false;

Expand Down Expand Up @@ -53,14 +51,14 @@ public int faceCount() {
* @param rand Random number source.
*/
public void sample(int face, Vector3 loc, Random rand) {
block.sampleFace(face, loc, rand);
FULL_BLOCK.sampleFace(face, loc, rand);
}

/**
* Get the surface area of this face of the block.
*/
public double surfaceArea(int face) {
return block.faceSurfaceArea(face);
return FULL_BLOCK.faceSurfaceArea(face);
}

/**
Expand All @@ -72,17 +70,7 @@ public double surfaceArea(int face) {
* @param scene Scene
* @return True if the ray hit this block, false if not
*/
public boolean intersect(Ray ray, Scene scene) {
ray.t = Double.POSITIVE_INFINITY;
if (block.intersect(ray)) {
float[] color = texture.getColor(ray.u, ray.v);
if (color[3] > Ray.EPSILON) {
ray.color.set(color);
ray.distance += ray.tNext;
ray.o.scaleAdd(ray.tNext, ray.d);
return true;
}
}
public boolean intersect(Ray ray, IntersectionRecord intersectionRecord, Scene scene) {
return false;
}

Expand Down Expand Up @@ -186,6 +174,15 @@ public Tag getNewTagWithBlockEntity(Tag blockTag, CompoundTag entityTag) {
return null;
}

/**
* Checks whether the given ray is inside this block.
*/
public boolean isInside(Ray ray) {
double ix = ray.o.x - QuickMath.floor(ray.o.x);
double iy = ray.o.y - QuickMath.floor(ray.o.y);
double iz = ray.o.z - QuickMath.floor(ray.o.z);
return FULL_BLOCK.inside(new Vector3(ix, iy, iz));
}
/**
* Does this block use biome tint for its rendering
*/
Expand Down
24 changes: 16 additions & 8 deletions chunky/src/java/se/llbit/chunky/block/BlockSpec.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,14 @@
import java.util.LinkedList;
import java.util.List;

public class BlockSpec {
public record BlockSpec(Tag tag) implements Comparable<BlockSpec> {

public static final List<BlockProvider> blockProviders = new LinkedList<>();

private final Tag tag;

public BlockSpec(@NotNull Tag tag) {
this.tag = tag;
}

@Override
public int hashCode() {
return tag.hashCode();
}

@Override
public boolean equals(Object obj) {
return (obj instanceof BlockSpec) && ((BlockSpec) obj).tag.equals(tag);
Expand Down Expand Up @@ -77,4 +70,19 @@ public static Tag getPropertiesTag(Tag tag) {
}
return properties;
}

public String details() {
return tag.dumpTree();
}

@Override
public String toString() {
return tag.get("Name").stringValue("unknown:unknown");
}

@Override
public int compareTo(BlockSpec o) {
return tag.get("Name").stringValue("unknown:unknown")
.compareTo(o.tag.get("Name").stringValue("unknown:unknown"));
}
}
Loading
Loading