From 440f25d7d87c818574cf6a205698b3b024cb53ff Mon Sep 17 00:00:00 2001 From: h4570 Date: Thu, 28 Jul 2022 10:52:38 +0200 Subject: [PATCH] fix tex coords to full numbers --- .../data/mcpip_multi_tex_block_data.cpp | 52 +++++++++--------- .../data/mcpip_single_tex_block_data.cpp | 52 +++++++++--------- tutorials/01-hello/inc/tutorial_01.hpp | 1 + tutorials/01-hello/src/tutorial_01.cpp | 54 ++++++++++--------- 4 files changed, 80 insertions(+), 79 deletions(-) diff --git a/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_multi_tex_block_data.cpp b/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_multi_tex_block_data.cpp index 37f43e8..ab03991 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_multi_tex_block_data.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_multi_tex_block_data.cpp @@ -54,37 +54,35 @@ void McpipMultiTexBlockData::allocateTempData() { tempVerts[23].set(1.0F, 1.0F, 1.0F); tempTexCoords = new Tyra::Vec4[tempVertsStsCount]; - tempTexCoords[0].set(0.062721F, 0.813282F, 1.0F, 0.0F); - tempTexCoords[1].set(0.062721F, 0.875327F, 1.0F, 0.0F); - tempTexCoords[2].set(0.000676F, 0.875327F, 1.0F, 0.0F); - tempTexCoords[3].set(0.000676F, 0.813282F, 1.0F, 0.0F); - tempTexCoords[4].set(0.062095F, 0.750461F, 1.0F, 0.0F); - tempTexCoords[5].set(0.062095F, 0.812244F, 1.0F, 0.0F); - tempTexCoords[6].set(0.000311F, 0.812244F, 1.0F, 0.0F); - tempTexCoords[7].set(0.000311F, 0.750461F, 1.0F, 0.0F); - tempTexCoords[8].set(0.062629F, 0.687779F, 1.0F, 0.0F); - tempTexCoords[9].set(0.000000F, 0.687779F, 1.0F, 0.0F); - tempTexCoords[10].set(0.000000F, 0.624816F, 1.0F, 0.0F); - tempTexCoords[11].set(0.062629F, 0.624816F, 1.0F, 0.0F); - tempTexCoords[12].set(0.062667F, 0.626382F, 1.0F, 0.0F); - tempTexCoords[13].set(0.000000F, 0.626382F, 1.0F, 0.0F); - tempTexCoords[14].set(0.000000F, 0.561642F, 1.0F, 0.0F); - tempTexCoords[15].set(0.062667F, 0.561642F, 1.0F, 0.0F); - tempTexCoords[16].set(0.000000F, 0.937621F, 1.0F, 0.0F); - tempTexCoords[17].set(0.000000F, 0.875134F, 1.0F, 0.0F); - tempTexCoords[18].set(0.062128F, 0.875134F, 1.0F, 0.0F); - tempTexCoords[19].set(0.062128F, 0.937621F, 1.0F, 0.0F); - tempTexCoords[20].set(0.000000F, 0.937223F, 1.0F, 0.0F); - tempTexCoords[21].set(0.062223F, 0.937223F, 1.0F, 0.0F); - tempTexCoords[22].set(0.062223F, 0.999641F, 1.0F, 0.0F); - tempTexCoords[23].set(0.000000F, 0.999641F, 1.0F, 0.0F); + // Y = 1.0F - Y + tempTexCoords[0].set(0.0625F, 0.1875F, 1.0000F, 0.0000F); + tempTexCoords[1].set(0.0625F, 0.1250F, 1.0000F, 0.0000F); + tempTexCoords[2].set(0.0000F, 0.1250F, 1.0000F, 0.0000F); + tempTexCoords[3].set(0.0000F, 0.1875F, 1.0000F, 0.0000F); + tempTexCoords[4].set(0.0625F, 0.2500F, 1.0000F, 0.0000F); + tempTexCoords[5].set(0.0625F, 0.1875F, 1.0000F, 0.0000F); + tempTexCoords[6].set(0.0000F, 0.1875F, 1.0000F, 0.0000F); + tempTexCoords[7].set(0.0000F, 0.2500F, 1.0000F, 0.0000F); + tempTexCoords[8].set(0.0625F, 0.3125F, 1.0000F, 0.0000F); + tempTexCoords[9].set(0.0000F, 0.3125F, 1.0000F, 0.0000F); + tempTexCoords[10].set(0.0000F, 0.3750F, 1.0000F, 0.0000F); + tempTexCoords[11].set(0.0625F, 0.3750F, 1.0000F, 0.0000F); + tempTexCoords[12].set(0.0625F, 0.3750F, 1.0000F, 0.0000F); + tempTexCoords[13].set(0.0000F, 0.3750F, 1.0000F, 0.0000F); + tempTexCoords[14].set(0.0000F, 0.4375F, 1.0000F, 0.0000F); + tempTexCoords[15].set(0.0625F, 0.4375F, 1.0000F, 0.0000F); + tempTexCoords[16].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[17].set(0.0000F, 0.1250F, 1.0000F, 0.0000F); + tempTexCoords[18].set(0.0625F, 0.1250F, 1.0000F, 0.0000F); + tempTexCoords[19].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[20].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[21].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[22].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[23].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); // Because 16 blocks can fit in single column of 256x256 tex atlas offset = 1.0F / 16.0F; - for (u32 i = 0; i < tempVertsStsCount; i++) - tempTexCoords[i].y = 1.0F - tempTexCoords[i].y; - tempVertFaces = new u32[36]; tempTexCoordsFaces = new u32[36]; diff --git a/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_single_tex_block_data.cpp b/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_single_tex_block_data.cpp index 826b556..b7dc03d 100644 --- a/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_single_tex_block_data.cpp +++ b/engine/src/renderer/3d/pipeline/minecraft/data/mcpip_single_tex_block_data.cpp @@ -54,37 +54,35 @@ void McpipSingleTexBlockData::allocateTempData() { tempVerts[23].set(1.0F, 1.0F, 1.0F); tempTexCoords = new Tyra::Vec4[tempVertsStsCount]; - tempTexCoords[0].set(0.000618F, 0.937685F, 1.0F, 0.0F); - tempTexCoords[1].set(0.062592F, 0.937685F, 1.0F, 0.0F); - tempTexCoords[2].set(0.062592F, 0.999658F, 1.0F, 0.0F); - tempTexCoords[3].set(0.000618F, 0.999658F, 1.0F, 0.0F); - tempTexCoords[4].set(0.062608F, 0.937379F, 1.0F, 0.0F); - tempTexCoords[5].set(0.062576F, 0.999352F, 1.0F, 0.0F); - tempTexCoords[6].set(0.000602F, 0.999320F, 1.0F, 0.0F); - tempTexCoords[7].set(0.000634F, 0.937346F, 1.0F, 0.0F); - tempTexCoords[8].set(0.062592F, 0.937381F, 1.0F, 0.0F); - tempTexCoords[9].set(0.062592F, 0.999354F, 1.0F, 0.0F); - tempTexCoords[10].set(0.000618F, 0.999354F, 1.0F, 0.0F); - tempTexCoords[11].set(0.000618F, 0.937381F, 1.0F, 0.0F); - tempTexCoords[12].set(0.062618F, 0.937600F, 1.0F, 0.0F); - tempTexCoords[13].set(0.062618F, 0.999542F, 1.0F, 0.0F); - tempTexCoords[14].set(0.000603F, 0.999576F, 1.0F, 0.0F); - tempTexCoords[15].set(0.000616F, 0.937585F, 1.0F, 0.0F); - tempTexCoords[16].set(0.062561F, 0.937533F, 1.0F, 0.0F); - tempTexCoords[17].set(0.062561F, 0.999446F, 1.0F, 0.0F); - tempTexCoords[18].set(0.000649F, 0.999446F, 1.0F, 0.0F); - tempTexCoords[19].set(0.000649F, 0.937533F, 1.0F, 0.0F); - tempTexCoords[20].set(0.000556F, 0.937533F, 1.0F, 0.0F); - tempTexCoords[21].set(0.062530F, 0.937533F, 1.0F, 0.0F); - tempTexCoords[22].set(0.062530F, 0.999506F, 1.0F, 0.0F); - tempTexCoords[23].set(0.000556F, 0.999506F, 1.0F, 0.0F); + // Y = 1.0F - Y + tempTexCoords[0].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[1].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[2].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[3].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[4].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[5].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[6].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[7].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[8].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[9].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[10].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[11].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[12].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[13].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[14].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[15].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[16].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[17].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[18].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[19].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[20].set(0.0000F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[21].set(0.0625F, 0.0625F, 1.0000F, 0.0000F); + tempTexCoords[22].set(0.0625F, 0.0000F, 1.0000F, 0.0000F); + tempTexCoords[23].set(0.0000F, 0.0000F, 1.0000F, 0.0000F); // Because 16 blocks can fit in single column of 256x256 tex atlas offset = 1.0F / 16.0F; - for (u32 i = 0; i < tempVertsStsCount; i++) - tempTexCoords[i].y = 1.0F - tempTexCoords[i].y; - tempVertFaces = new u32[36]; tempTexCoordsFaces = new u32[36]; diff --git a/tutorials/01-hello/inc/tutorial_01.hpp b/tutorials/01-hello/inc/tutorial_01.hpp index 2abff01..24a0281 100644 --- a/tutorials/01-hello/inc/tutorial_01.hpp +++ b/tutorials/01-hello/inc/tutorial_01.hpp @@ -51,6 +51,7 @@ class Tutorial01 : public Game { DynPipOptions* dynOptions; Texture* warriorTex; Texture* blocksTex; + Texture* blocksTex2; u32 blocksCount; McpipBlock* blocks; diff --git a/tutorials/01-hello/src/tutorial_01.cpp b/tutorials/01-hello/src/tutorial_01.cpp index f91a1c4..bddafa8 100644 --- a/tutorials/01-hello/src/tutorial_01.cpp +++ b/tutorials/01-hello/src/tutorial_01.cpp @@ -85,6 +85,8 @@ void Tutorial01 ::init() { blocksTex = engine->renderer.core.texture.repository.add( FileUtils::fromCwd("blocks.png")); + blocksTex2 = engine->renderer.core.texture.repository.add( + FileUtils::fromCwd("texture_atlas.png")); mcPip.setRenderer(&engine->renderer.core); dynpip.setRenderer(&engine->renderer.core); @@ -95,8 +97,8 @@ void Tutorial01 ::init() { for (u32 i = 0; i < picturesCount; i++) pictures[i] = get2DPicture(&engine->renderer); - u32 rows = 16; // 64 - u32 columns = 16; // 64 + u32 rows = 2; // 64 + u32 columns = 2; // 64 blocksCount = rows * columns; float offset = 4.0F; @@ -112,10 +114,12 @@ void Tutorial01 ::init() { translations[i].translateX(row * offset - center); translations[i].translateY(column * offset - center); - translations[i].translateZ(-50.0F); + translations[i].translateZ(-10.0F); - u32 randRow = rand() % (rows + 1); - u32 randColumn = rand() % (columns + 1); + // u32 randRow = rand() % (rows + 1); + // u32 randColumn = rand() % (columns + 1); + u32 randRow = 0; + u32 randColumn = 0; blocks[i].textureOffset = Vec4(mcPip.getTextureOffset() * randRow, @@ -145,9 +149,9 @@ void Tutorial01 ::loop() { engine->renderer.beginFrame(CameraInfo3D(&cameraPosition, &cameraLookAt)); { for (u32 i = 0; i < blocksCount; i++) { - rotations[i].rotateX(0.04F); - rotations[i].rotateY(0.01F); - rotations[i].rotateZ(0.01F); + // rotations[i].rotateX(0.04F); + rotations[i].rotateY(0.04F); + // rotations[i].rotateZ(0.01F); blocks[i].model = translations[i] * rotations[i] * scales[i]; } @@ -155,26 +159,26 @@ void Tutorial01 ::loop() { for (u32 i = 0; i < picturesCount; i++) engine->renderer.renderer2D.render(pictures[i]); - engine->renderer.renderer3D.usePipeline(&stapip); - { - stapip.render(staticMesh, staOptions); - stapip.render(skybox, skyboxOptions); - } + // engine->renderer.renderer3D.usePipeline(&stapip); + // { + // stapip.render(staticMesh, staOptions); + // stapip.render(skybox, skyboxOptions); + // } - engine->renderer.renderer3D.usePipeline(&dynpip); - { - dynpip.render(cube); - Threading::switchThread(); - for (u8 i = 0; i < warriorsCount; i++) { - dynpip.render(warriors[i], dynOptions); - if (i == 5) Threading::switchThread(); - if (i == 10) Threading::switchThread(); - if (i == 15) Threading::switchThread(); - } - } + // engine->renderer.renderer3D.usePipeline(&dynpip); + // { + // dynpip.render(cube); + // Threading::switchThread(); + // for (u8 i = 0; i < warriorsCount; i++) { + // dynpip.render(warriors[i], dynOptions); + // if (i == 5) Threading::switchThread(); + // if (i == 10) Threading::switchThread(); + // if (i == 15) Threading::switchThread(); + // } + // } engine->renderer.renderer3D.usePipeline(&mcPip); - { mcPip.render(blocks, blocksCount, blocksTex); } + { mcPip.render(blocks, blocksCount, blocksTex2, true); } } engine->renderer.endFrame(); }