Skip to content

Commit

Permalink
Converted the triangle images back to the simple storage format
Browse files Browse the repository at this point in the history
  • Loading branch information
Martomate committed Jan 16, 2024
1 parent acf4b53 commit 42f11ce
Show file tree
Hide file tree
Showing 9 changed files with 7 additions and 79 deletions.
42 changes: 3 additions & 39 deletions game/src/main/resources/shaders/block.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ void main() {
#pragma shader frag
#define y60 0.866025403784439

ivec2 triCoordsToStorage(in ivec2 triCoords);

struct FragInFlat {
int blockTex;
int faceIndex;
Expand Down Expand Up @@ -122,10 +120,10 @@ void main() {

int texOffset = (fragInFlat.blockTex >> (4 * (5 - ss)) & 0xffff) >> 12 & 15; // blockTex: 11112222333344445555 + 12 bits

vec2 tex = vec2(1 + px, 1) * factor * texSizef;
int texX = clamp(int(tex.x), 0, texSize * 2);
vec2 tex = vec2(min(1 + px, 1), min(1 - px, 1)) * factor * texSizef;
int texX = clamp(int(tex.x), 0, texSize - 1);
int texY = clamp(int(tex.y), 0, texSize - 1);
ivec2 stCoords = triCoordsToStorage(ivec2(texX, texY));
ivec2 stCoords = ivec2(int(tex.x), int(tex.y));
color = textureGrad(
texSampler,
vec3(vec2(stCoords) / texSizef, texDepth + texOffset),
Expand All @@ -138,37 +136,3 @@ void main() {

color.rgb *= (fragIn.brightness * 0.8 + 0.2) * visibility;
}

// Recursive storage format
ivec2 triCoordsToStorage(in ivec2 triCoords) {
int sx = 0;
int sy = 0;
int bsize = texSize;
int x = triCoords.x;
int y = triCoords.y;
int sign = 1;

while (bsize > 0) {
int rest = y - bsize;

if (y < bsize) {
} else if (x <= 2 * rest) { // left
sy += bsize * sign;
y = rest;
} else if (x >= 2 * bsize) { // right
sx += bsize * sign;
x -= 2 * bsize;
y = rest;
} else {
sx += (2 * bsize - 1) * sign;
sy += (2 * bsize - 1) * sign;
sign = -sign;
x = 2 * bsize - 1 - x;
y = bsize - 1 - rest;
}

bsize >>= 1;
}

return ivec2(sx, sy);
}
42 changes: 3 additions & 39 deletions game/src/main/resources/shaders/gui_block.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ void main() {
#pragma shader frag
#define y60 0.866025403784439

ivec2 triCoordsToStorage(in ivec2 triCoords);

struct FragInFlat {
int blockTex;
int faceIndex;
Expand Down Expand Up @@ -96,10 +94,10 @@ void main() {

int texOffset = (fragInFlat.blockTex >> (4 * (5 - ss)) & 0xffff) >> 12 & 15; // blockTex: 11112222333344445555 + 12 bits

vec2 tex = vec2(1 + px, 1) * factor * texSizef;
int texX = clamp(int(tex.x), 0, texSize * 2);
vec2 tex = vec2(min(1 + px, 1), min(1 - px, 1)) * factor * texSizef;
int texX = clamp(int(tex.x), 0, texSize - 1);
int texY = clamp(int(tex.y), 0, texSize - 1);
ivec2 stCoords = triCoordsToStorage(ivec2(texX, texY));
ivec2 stCoords = ivec2(int(tex.x), int(tex.y));

color = textureGrad(
texSampler,
Expand All @@ -112,37 +110,3 @@ void main() {

color.rgb *= fragInFlat.brightness * visibility;
}

// Recursive storage format
ivec2 triCoordsToStorage(in ivec2 triCoords) {
int sx = 0;
int sy = 0;
int bsize = texSize;
int x = triCoords.x;
int y = triCoords.y;
int sign = 1;

while (bsize > 0) {
int rest = y - bsize;

if (y < bsize) {
} else if (x <= 2 * rest) { // left
sy += bsize * sign;
y = rest;
} else if (x >= 2 * bsize) { // right
sx += bsize * sign;
x -= 2 * bsize;
y = rest;
} else {
sx += (2 * bsize - 1) * sign;
sy += (2 * bsize - 1) * sign;
sign = -sign;
x = 2 * bsize - 1 - x;
y = bsize - 1 - rest;
}

bsize >>= 1;
}

return ivec2(sx, sy);
}
Binary file modified game/src/main/resources/textures/blocks/grassTop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified game/src/main/resources/textures/blocks/log.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified game/src/main/resources/textures/blocks/log_birch.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified game/src/main/resources/textures/blocks/planks_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified game/src/main/resources/textures/blocks/stoneTop.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified game/src/main/resources/textures/blocks/tnt_top.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion game/src/test/scala/hexacraft/RootArchTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ class RootArchTest extends FunSuite {
// TODO: reduce package dependencies and update this test accordingly
test("packages should not depend on too many other packages") {
val root = "root"
val Text = "Text"
val Game = "Game"
val GUI = "GUI"
val Infra = "Infra"
val Main = "Main"
val Math = "Math"
val Physics = "Physics"
val Renderer = "Renderer"
val Text = "Text"
val Util = "Util"
val World = "World"

Expand Down

0 comments on commit 42f11ce

Please sign in to comment.