oriented wall torch

This commit is contained in:
Zack Buhman 2026-03-19 16:20:12 -05:00
parent 8283bc2974
commit 00420dd1ed
26 changed files with 109 additions and 72 deletions

View File

@ -8,6 +8,7 @@ short index_buffer_configuration_offsets[] = {
768, 780, 798, 816, 840, 858, 882, 906,
936, 954, 978, 1002, 1032, 1056, 1086, 1116,
};
// generated from
struct {
short offset;
short count;
@ -15,6 +16,7 @@ struct {
{1152, 3180}, // candle.obj
{4332, 1584}, // custom_mushroom.obj
{5916, 36}, // fence.obj
{5952, 12}, // tall_grass.obj
{5964, 2082}, // wall_torch.obj
{5952, 24}, // stair.obj
{5976, 12}, // tall_grass.obj
{5988, 2082}, // wall_torch.obj
};

View File

@ -25,8 +25,8 @@ namespace world {
};
};
// also update index_buffer_custom_offsets in data.inc
const int custom_block_types = 5;
// also update index_buffer_custom_offsets in include/minecraft_data.inc
const int custom_block_types = 6;
const int instance_cfg_length = 64 + custom_block_types;
struct instance_cfg_entry {

Binary file not shown.

View File

@ -5,16 +5,13 @@ Wooden Planks,5,,4,,,,"""linear texture index"" is invalid if unspecified"
Trunk,17,,5,,,,"""properties"" is (empty) if unspecified"
Trunk,17,1,5,,,,
Birch Block,17,2,6,,,,
Leaves,18,,12,,,,
Leaves,18,1,12,,,,
Leaves,18,2,12,,,,
Leaves,18,3,12,,,,
Leaves,18,"0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15",12,,,,
Unused,20,,11,,,,
Door Bottom,21,,18,,,,
Door Top,22,,17,,,,
Tall Grass,31,"0,1",22,tall_grass,,,
Tall Grass,31,"0,1",22,tall_grass,two_sided,,
Tan Block 1,35,1,2,,,,
White Block 2,35,5,6,,,,if you say so
White Block 2,35,5,6,,,,
Arch Bottom,35,6,10,,,,
Tan Block 2,35,8,3,,,,
White Block 1,35,9,21,,,,
@ -23,13 +20,14 @@ Unused,35,10,,,,,
Arch Top,35,14,9,,,,
Grey Bricks 1,35,15,8,,,,
White Block 3,35,,7,,,,
Lilac Grass,37,,15,tall_grass,,,
Spider Plant,38,,13,tall_grass,,,
Spider Plant,39,,13,tall_grass,,,
Lilac Grass,37,,15,tall_grass,two_sided,,
Spider Plant,38,,13,tall_grass,two_sided,,
Spider Plant,39,,13,tall_grass,two_sided,,
Red Mushroom,40,,14,custom_mushroom,,,
Start/Finish Line,45,,16,,,,
Shadow Block,49,,20,,,,
Wall Torch,50,"1,2,3,4",,wall_torch,emits_light,,
Candle,50,5,,candle,emits_light,,
Wall Torch,50,"1,2,3,4",62,wall_torch,"emits_light,torch_oriented",,
Candle,50,5,61,candle,emits_light,,
Stair,53,"0,1,2,3,4,5,6,7",4,stair,stair_oriented,,
Fence,85,0,4,fence,,,
Lamp Block,89,,19,,,,
Lamp Block,89,,19,,,,
1 name block id data linear texture index custom mesh properties notes
5 Trunk 17 5 "properties" is (empty) if unspecified
6 Trunk 17 1 5
7 Birch Block 17 2 6
8 Leaves 18 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 12
Leaves 18 1 12
Leaves 18 2 12
Leaves 18 3 12
9 Unused 20 11
10 Door Bottom 21 18
11 Door Top 22 17
12 Tall Grass 31 0,1 22 tall_grass two_sided
13 Tan Block 1 35 1 2
14 White Block 2 35 5 6 if you say so
15 Arch Bottom 35 6 10
16 Tan Block 2 35 8 3
17 White Block 1 35 9 21
20 Arch Top 35 14 9
21 Grey Bricks 1 35 15 8
22 White Block 3 35 7
23 Lilac Grass 37 15 tall_grass two_sided
24 Spider Plant 38 13 tall_grass two_sided
25 Spider Plant 39 13 tall_grass two_sided
26 Red Mushroom 40 14 custom_mushroom
27 Start/Finish Line 45 16
28 Shadow Block 49 20
29 Wall Torch 50 1,2,3,4 62 wall_torch emits_light emits_light,torch_oriented
30 Candle 50 5 61 candle emits_light
31 Stair 53 0,1,2,3,4,5,6,7 4 stair stair_oriented
32 Fence 85 0 4 fence
33 Lamp Block 89 19

View File

@ -77,5 +77,17 @@ def get_texture_id(block_id, block_data):
decl = by_id_data.get((block_id, block_data), default_decl)
return decl.linear_texture_index
def get_special(block_id, block_data):
decl = by_id_data.get((block_id, block_data), default_decl)
if "two_sided" in decl.properties:
return -1
if "torch_oriented" in decl.properties:
return 1
if "stair_oriented" in decl.properties:
return 2
return 0
if __name__ == "__main__":
print(sorted_custom_mesh)
from pprint import pprint
#print(sorted_custom_mesh)
pprint(sorted_decls)

View File

@ -1553,9 +1553,15 @@ vn -0.2920 0.6453 -0.7059
vn -0.2919 0.6454 -0.7059
vn -0.2921 0.6452 -0.7060
vn -0.3822 -0.0280 -0.9237
vt 0.000000 0.000000
vt 1.000000 0.000000
vt 1.000000 1.000000
vt 0.377875 0.161326
vt 0.592596 0.161326
vt 0.592596 0.376047
vt 0.363336 0.685699
vt 0.538233 0.685699
vt 0.538233 0.860595
vt 0.569816 0.668247
vt 0.784537 0.668247
vt 0.784537 0.882968
s 1
f 1/1/1 2/2/1 3/3/2
f 3/1/2 4/2/2 1/3/1
@ -1887,9 +1893,9 @@ f 269/1/164 192/2/164 158/3/164
f 158/1/164 157/2/164 269/3/164
f 192/1/165 193/2/165 159/3/166
f 159/1/166 158/2/166 192/3/165
f 193/1/167 194/2/167 160/3/168
f 160/1/168 159/2/168 193/3/167
f 160/1/169 194/2/170 411/3/90
f 193/4/167 194/5/167 160/6/168
f 160/4/168 159/5/168 193/6/167
f 160/4/169 194/5/170 411/6/90
f 161/1/171 195/2/172 253/3/101
f 253/1/101 127/2/104 161/3/171
f 162/1/173 196/2/174 195/3/172
@ -1988,9 +1994,9 @@ f 269/1/283 232/2/283 233/3/283
f 233/1/283 192/2/283 269/3/283
f 192/1/165 233/2/284 234/3/284
f 234/1/284 193/2/165 192/3/165
f 193/1/167 234/2/285 235/3/285
f 235/1/285 194/2/167 193/3/167
f 235/1/286 411/2/90 194/3/170
f 193/7/167 234/8/285 235/9/285
f 235/7/285 194/8/167 193/9/167
f 235/4/286 411/5/90 194/6/170
f 236/1/287 202/2/221 253/3/220
f 253/1/220 195/2/288 236/3/287
f 237/1/289 236/2/287 195/3/288
@ -2089,9 +2095,9 @@ f 157/1/396 158/2/396 295/3/396
f 295/1/396 510/2/396 157/3/396
f 158/1/166 159/2/166 511/3/397
f 511/1/397 295/2/397 158/3/166
f 159/1/168 160/2/168 296/3/398
f 296/1/398 511/2/398 159/3/168
f 296/1/399 160/2/169 411/3/90
f 159/4/168 160/5/168 296/6/398
f 296/4/398 511/5/398 159/6/168
f 296/4/399 160/5/169 411/6/90
f 161/1/400 127/2/335 279/3/338
f 279/1/338 297/2/401 161/3/400
f 162/1/402 161/2/400 297/3/401
@ -2190,9 +2196,9 @@ f 233/1/513 232/2/513 329/3/513
f 329/1/513 526/2/513 233/3/513
f 234/1/284 233/2/284 526/3/514
f 526/1/514 330/2/514 234/3/284
f 235/1/285 234/2/285 330/3/515
f 330/1/515 331/2/515 235/3/285
f 411/1/90 235/2/286 331/3/516
f 235/7/285 234/8/285 330/9/515
f 330/7/515 331/8/515 235/9/285
f 411/4/90 235/5/286 331/6/516
f 202/1/450 236/2/517 332/3/518
f 332/1/518 310/2/451 202/3/450
f 236/1/517 237/2/519 333/3/520
@ -2291,9 +2297,9 @@ f 403/1/625 404/2/625 406/3/625
f 406/1/625 405/2/625 403/3/625
f 405/1/626 406/2/627 408/3/627
f 408/1/627 407/2/626 405/3/626
f 407/1/628 408/2/629 410/3/629
f 410/1/629 409/2/628 407/3/628
f 410/1/630 411/2/90 409/3/631
f 407/4/628 408/5/629 410/6/629
f 410/4/629 409/5/628 407/6/628
f 410/4/630 411/5/90 409/6/631
f 412/1/632 343/2/563 344/3/562
f 344/1/562 413/2/633 412/3/632
f 414/1/634 412/2/632 413/3/633
@ -2392,9 +2398,9 @@ f 403/1/744 405/2/744 476/3/744
f 476/1/744 475/2/744 403/3/744
f 405/1/626 407/2/626 477/3/745
f 477/1/745 476/2/745 405/3/626
f 407/1/628 409/2/628 478/3/746
f 478/1/746 477/2/746 407/3/628
f 478/1/747 409/2/631 411/3/90
f 407/7/628 409/8/628 478/9/746
f 478/7/746 477/8/746 407/9/628
f 478/4/747 409/5/631 411/6/90
f 479/1/748 413/2/749 344/3/681
f 344/1/681 445/2/684 479/3/748
f 480/1/750 415/2/751 413/3/749
@ -2493,9 +2499,9 @@ f 404/1/859 510/2/859 295/3/859
f 295/1/859 406/2/859 404/3/859
f 406/1/627 295/2/397 511/3/397
f 511/1/397 408/2/627 406/3/627
f 408/1/629 511/2/398 296/3/398
f 296/1/398 410/2/629 408/3/629
f 296/1/399 411/2/90 410/3/630
f 408/4/629 511/5/398 296/6/398
f 296/4/398 410/5/629 408/6/629
f 296/4/399 411/5/90 410/6/630
f 412/1/860 297/2/861 279/3/798
f 279/1/798 343/2/797 412/3/860
f 414/1/862 298/2/863 297/3/861
@ -2594,9 +2600,9 @@ f 476/1/973 526/2/973 329/3/973
f 329/1/973 475/2/973 476/3/973
f 477/1/745 330/2/514 526/3/514
f 526/1/514 476/2/745 477/3/745
f 478/1/746 331/2/515 330/3/515
f 330/1/515 477/2/746 478/3/746
f 411/1/90 331/2/516 478/3/747
f 478/7/746 331/8/515 330/9/515
f 330/7/515 477/8/746 478/9/746
f 411/4/90 331/5/516 478/6/747
f 445/1/913 310/2/912 332/3/974
f 332/1/974 479/2/975 445/3/913
f 479/1/975 332/2/974 333/3/976

View File

@ -96,9 +96,11 @@ def build_block_configuration_table():
yield indices
def pack_instance_data(position, block_id, block_data, texture_id):
special = block_ids.get_special(block_id, block_data)
packed = struct.pack("<hhhhhhhh",
position[0], position[1], position[2], 0,
block_id, block_data, texture_id, 0)
block_id, block_data, texture_id, special)
return packed
def pack_light_data(position, block_id):

View File

@ -1,4 +1,4 @@
# Blender 4.5.7 LTS
# Blender 5.0.0
# www.blender.org
o Cube
v 1.000000 -1.000000 -1.000000

Binary file not shown.

File diff suppressed because one or more lines are too long

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

View File

@ -38,7 +38,7 @@ void main()
vec3 light_direction = normalize(Eye.xyz - position.xyz);
float diffuse = max(dot(normal.xyz, light_direction), 0.0);
if (normal.w > 1.0)
if (normal.w == 1.0) // two-sided
diffuse = 1.0;
out_color = color.xyz * diffuse;

View File

@ -8,12 +8,13 @@ in VS_OUT {
flat int BlockID;
flat int Data;
flat int TextureID;
flat int Special;
} fs_in;
layout (location = 0) out vec3 Position;
layout (location = 1) out vec4 Normal;
layout (location = 2) out vec3 Color;
layout (location = 3) out vec3 Block;
layout (location = 3) out vec4 Block;
uniform sampler2D TerrainSampler;
uniform vec3 MousePosition;
@ -22,16 +23,6 @@ uniform vec3 MousePosition2;
void main()
{
int texture_id = fs_in.TextureID;
if (fs_in.BlockID == 2) // grass
texture_id = 0;
if (fs_in.BlockID == 50 && fs_in.Data == 0) // ?
texture_id = 61;
if (fs_in.BlockID == 18)
texture_id = 11;
if (fs_in.BlockID == 21)
texture_id = 17;
if (fs_in.BlockID == 22)
texture_id = 16;
int terrain_x = texture_id % 8;
int terrain_y = texture_id / 8;
@ -44,10 +35,10 @@ void main()
return;
}
float two_sided = float(fs_in.BlockID == 31 || fs_in.BlockID == 37 || fs_in.BlockID == 38 || fs_in.BlockID == 39);
float two_sided = float(fs_in.Special == -1); // special
Position = fs_in.BlockPosition.xzy;
Normal = vec4(normalize(fs_in.Normal.xzy), two_sided * 2.0);
Normal = vec4(normalize(fs_in.Normal.xzy), two_sided);
Color = texture_color.xyz;
Block = vec3(fs_in.BlockID, fs_in.Data, fs_in.TextureID);
Block = vec4(fs_in.BlockID, fs_in.Data, fs_in.TextureID, fs_in.Special);
}

View File

@ -9,6 +9,7 @@ in vec3 BlockPosition;
in int BlockID;
in int Data;
in int TextureID;
in int Special;
out VS_OUT {
vec3 Position;
@ -18,13 +19,30 @@ out VS_OUT {
flat int BlockID;
flat int Data;
flat int TextureID;
flat int Special;
} vs_out;
uniform mat4 Transform;
vec3 orientation(vec3 position)
{
if (Special == 1) { // oriented torch
if (Data == 1)
return vec3(position.z, position.y, -position.x);
else if (Data == 2)
return vec3(-position.z, position.y, position.x);
else if (Data == 4)
return vec3(position.x, position.y, -position.z);
else
return position;
} else {
return position;
}
}
void main()
{
vec3 position = Position + BlockPosition; // world coordinates
vec3 position = orientation(Position) + BlockPosition; // world coordinates
vs_out.Position = position;
vs_out.BlockPosition = BlockPosition;
@ -33,6 +51,7 @@ void main()
vs_out.BlockID = BlockID;
vs_out.Data = Data;
vs_out.TextureID = TextureID;
vs_out.Special = Special;
gl_Position = Transform * vec4(position.xzy, 1.0);
}

View File

@ -36,7 +36,7 @@ namespace hud {
inline static float draw_vector(font::font const& ter_best, char * const buf, float y, char const * const label, XMVECTOR vec)
{
labeled_value<float>(buf, label, ": %5.2f %5.2f %5.2f", XMVectorGetX(vec), XMVectorGetY(vec), XMVectorGetZ(vec));
labeled_value<float>(buf, label, ": %5.2f %5.2f %5.2f %5.2f", XMVectorGetX(vec), XMVectorGetY(vec), XMVectorGetZ(vec), XMVectorGetW(vec));
font::draw_string(ter_best, buf, 10, y);
y += ter_best.desc->glyph_height;
return y;
@ -115,7 +115,7 @@ namespace hud {
font::draw_string(ter_best, "mouse:", 10, y);
y += ter_best.desc->glyph_height;
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat3((XMFLOAT3*)mouse_position));
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat3((XMFLOAT3*)mouse_block));
y = draw_vector(ter_best, buf, y, " position", XMLoadFloat4((XMFLOAT4*)mouse_position));
y = draw_vector(ter_best, buf, y, " block", XMLoadFloat4((XMFLOAT4*)mouse_block));
}
}

View File

@ -23,6 +23,7 @@ namespace minecraft {
unsigned int block_id;
unsigned int data;
unsigned int texture_id;
unsigned int special;
} attrib;
struct {
unsigned int transform;
@ -61,15 +62,17 @@ namespace minecraft {
location.attrib.block_id = glGetAttribLocation(program, "BlockID");
location.attrib.data = glGetAttribLocation(program, "Data");
location.attrib.texture_id = glGetAttribLocation(program, "TextureID");
location.attrib.special = glGetAttribLocation(program, "Special");
printf("minecraft program:\n");
printf(" attributes:\n position %u\n normal %u\n texture %u\n block_position %u\n block_id %u\n data %u\n texture_id %u\n",
printf(" attributes:\n position %u\n normal %u\n texture %u\n block_position %u\n block_id %u\n data %u\n texture_id %u\n special %u\n",
location.attrib.position,
location.attrib.normal,
location.attrib.texture,
location.attrib.block_position,
location.attrib.block_id,
location.attrib.data,
location.attrib.texture_id);
location.attrib.texture_id,
location.attrib.special);
location.uniform.transform = glGetUniformLocation(program, "Transform");
location.uniform.terrain_sampler = glGetUniformLocation(program, "TerrainSampler");
@ -114,6 +117,10 @@ namespace minecraft {
glVertexAttribIFormat(location.attrib.texture_id, 1, GL_SHORT, 12);
glVertexAttribBinding(location.attrib.texture_id, 1);
glEnableVertexAttribArray(location.attrib.special);
glVertexAttribIFormat(location.attrib.special, 1, GL_SHORT, 14);
glVertexAttribBinding(location.attrib.special, 1);
glBindVertexArray(0);
}

View File

@ -377,8 +377,8 @@ int clamp(int n, int high)
return n;
}
float mouse_position[3] = {};
float mouse_block[3] = {};
float mouse_position[4] = {};
float mouse_block[4] = {};
void update_mouse(int x, int y)
{
@ -392,7 +392,7 @@ void update_mouse(int x, int y)
geometry_buffer_pnc.height - y,
1, // width
1, // height
GL_RGB,
GL_RGBA,
GL_FLOAT,
(void*)&mouse_position);
@ -401,7 +401,7 @@ void update_mouse(int x, int y)
geometry_buffer_pnc.height - y,
1, // width
1, // height
GL_RGB,
GL_RGBA,
GL_FLOAT,
(void*)&mouse_block);
}