Skip to content

Commit

Permalink
Improve biome blending in 3D (#1637)
Browse files Browse the repository at this point in the history
* Only do 3D blur when necessary during biome blending. Do only 2D blur when possible

* Implement 2D blur using a summed-area table and fix bugs observed during testing

* Implement 3D blur using a summed-area table too

* Narrow the y interval on which biome blending must be done by querying the blocks to know if they use biome blending

* Group 3D blur computation for transition that are close to one another

* Expose control in UI for biome blending radius

* Clean up

* Rename useBiomeTint to isBiomeDependant. Make 2D biome benefit from tracking whether biome is used int the chunk or not

* Don't use title case for the biome blending checkbox.

* Fix bug where chunk on the edge of the selection when the chunk coordinate are negative had wildy wrong biome colors due to off by 1 error when testing if the chunk is loaded caused by int division rounding behavior

---------

Co-authored-by: Maik Marschner <[email protected]>
  • Loading branch information
aTom3333 and leMaik authored Dec 23, 2023
1 parent 7ee31cb commit 097cf54
Show file tree
Hide file tree
Showing 14 changed files with 643 additions and 160 deletions.
5 changes: 5 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/AbstractModelBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ public BlockModel getModel() {
public boolean intersect(Ray ray, Scene scene) {
return model.intersect(ray, scene);
}

@Override
public boolean isBiomeDependant() {
return super.isBiomeDependant() || model.isBiomeDependant();
}
}
7 changes: 7 additions & 0 deletions chunky/src/java/se/llbit/chunky/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,11 @@ public boolean isModifiedByBlockEntity() {
public Tag getNewTagWithBlockEntity(Tag blockTag, CompoundTag entityTag) {
return null;
}

/**
* Does this block use biome tint for its rendering
*/
public boolean isBiomeDependant() {
return isWaterFilled();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,4 +83,9 @@ public Tag getNewTagWithBlockEntity(Tag blockTag, CompoundTag entityTag) {

return tag; // keep empty
}

@Override
public boolean isBiomeDependant() {
return true; // (in reality it is only used for fern)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,9 @@ public void finalizeBlock(FinalizationState state) {
// otherwise just unwrap the block
state.replaceCurrentBlock(tag);
}

@Override
public boolean isBiomeDependant() {
return true;
}
}
13 changes: 13 additions & 0 deletions chunky/src/java/se/llbit/chunky/model/AABBModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Random;

/**
Expand Down Expand Up @@ -181,4 +182,16 @@ private boolean intersectFace(Ray ray, Scene scene, Texture texture, UVMapping m
}
return false;
}

@Override
public boolean isBiomeDependant() {
Tint[][] tints = getTints();
if(tints == null)
return false;

return Arrays.stream(tints)
.filter(Objects::nonNull)
.flatMap(Arrays::stream)
.anyMatch(Tint::isBiomeTint);
}
}
2 changes: 2 additions & 0 deletions chunky/src/java/se/llbit/chunky/model/BlockModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@ public interface BlockModel {
void sample(int face, Vector3 loc, Random rand);

double faceSurfaceArea(int face);

boolean isBiomeDependant();
}
12 changes: 12 additions & 0 deletions chunky/src/java/se/llbit/chunky/model/QuadModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
import se.llbit.math.Vector3;
import se.llbit.math.Vector4;

import java.util.Arrays;
import java.util.Objects;
import java.util.Random;

/**
Expand Down Expand Up @@ -148,4 +150,14 @@ public boolean intersect(Ray ray, Scene scene) {
}
return hit;
}

@Override
public boolean isBiomeDependant() {
Tint[] tints = getTints();
if(tints == null)
return false;

return Arrays.stream(tints)
.anyMatch(Tint::isBiomeTint);
}
}
4 changes: 4 additions & 0 deletions chunky/src/java/se/llbit/chunky/model/Tint.java
Original file line number Diff line number Diff line change
Expand Up @@ -98,4 +98,8 @@ public void tint(Vector4 color, Ray ray, Scene scene) {
color.z *= tintColor[2];
}
}

public boolean isBiomeTint() {
return type == TintType.BIOME_FOLIAGE || type == TintType.BIOME_GRASS || type == TintType.BIOME_WATER;
}
}
Loading

0 comments on commit 097cf54

Please sign in to comment.