Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve biome blending in 3D #1637

Merged
merged 10 commits into from
Dec 23, 2023
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)
Copy link
Member

@leMaik leMaik Oct 2, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be fixed then (or does this method only check if the model uses it at all)?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Returning true only for fern would be better. But from the function just above it seem the entityTag is needed to determine whether this is a fern or not. And because returning true when it should be false doesn't lead to a big adverse effect (it may lead to unnecessary work as more biome blending than necessary is performed), I just was lazy and made it simpler

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, this shouldn't be a problem at all. We replace all legacy blocks while loading a legacy chunk and let it create a new tag that takes the entity tag's information into account.

All the biome stuff is handled after converting the legacy blocks.

}
}
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
Loading