Skip to content

Commit

Permalink
[1.20] Update texture encoding (#519)
Browse files Browse the repository at this point in the history
* Update texture encoding

* Add Embeddium dependency & make it mandatory

In dev, mandatory = true can be removed for testing the vanilla
pipeline

* Remove Embeddium requirement
  • Loading branch information
embeddedt authored Dec 24, 2023
1 parent f027e2d commit c37a355
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ loom.platform = forge
archives_base_name = oculus

# Dependencies
embeddium_version=0.2.12-git.149aa28+mc1.20.1
embeddium_version=0.2.14-git.dbe9f77+mc1.20.1
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ float _material_alpha_cutoff(uint material) {
void _vert_init() {
_vert_position = (vec3(a_PosId.xyz) * 4.8828125E-4f + -8.0f);
_vert_tex_diffuse_coord = (a_TexCoord * 1.52587891E-5f);
_vert_tex_diffuse_coord = (a_TexCoord * 1.0f / 32768.0f);
_vert_tex_light_coord = a_LightCoord;
_vert_color = a_Color;
_draw_id = (a_PosId.w >> 8u) & 0xffu;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void transform(
SodiumParameters parameters) {
CommonTransformer.transform(t, tree, root, parameters, false);

replaceMidTexCoord(t, tree, root, 1.0f / 65536.0f);
replaceMidTexCoord(t, tree, root, 1.0f / 32768.0f);

root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix0, "mat4(1.0)");
root.replaceExpressionMatches(t, CommonTransformer.glTextureMatrix1, "iris_LightmapTextureMatrix");
Expand Down Expand Up @@ -150,7 +150,7 @@ public static void injectVertInit(
"void _vert_init() {" +
"_vert_position = (vec3(a_PosId.xyz) * 0.00048828125 + -8.0"
+ ");" +
"_vert_tex_diffuse_coord = (a_TexCoord * 1.52587891E-5);" +
"_vert_tex_diffuse_coord = (a_TexCoord * 1.0f / 32768.0f);" +
"_vert_tex_light_coord = a_LightCoord;" +
"_vert_color = " + separateAo + ";" +
"_draw_id = (a_PosId.w >> 8u) & 0xFFu; }",
Expand Down
6 changes: 6 additions & 0 deletions src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ mandatory = true
versionRange = "[1.20.1]"
ordering = "NONE"
side = "BOTH"

[[dependencies.oculus]]
modId = "embeddium"
versionRange = "[0.2.14,)"
ordering = "NONE"
side = "CLIENT"
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class XHFPModelVertexType implements ChunkVertexType {
.build();

private static final int POSITION_MAX_VALUE = 65536;
private static final int TEXTURE_MAX_VALUE = 65536;
private static final int TEXTURE_MAX_VALUE = 32768;

private static final float MODEL_ORIGIN = 8.0f;
private static final float MODEL_RANGE = 32.0f;
Expand All @@ -48,7 +48,7 @@ public ChunkVertexEncoder getEncoder() {
}

static short encodeBlockTexture(float value) {
return (short) (Math.min(0.99999997F, value) * TEXTURE_MAX_VALUE);
return (short) (Math.round(value * TEXTURE_MAX_VALUE) & 0xFFFF);
}

static float decodeBlockTexture(short raw) {
Expand Down

0 comments on commit c37a355

Please sign in to comment.