Skip to content

Commit

Permalink
More work on the texture subsampling. The texture class needs a split
Browse files Browse the repository at this point in the history
into OpenGL texture stuff and raw texture buffer stuff; I will resolve
this in an upcoming refactoring.
  • Loading branch information
Zang3th committed Jul 12, 2024
1 parent cf5fdd4 commit 927d85a
Show file tree
Hide file tree
Showing 10 changed files with 49 additions and 15 deletions.
6 changes: 3 additions & 3 deletions Apps/Liquefied/LiquefiedApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Liq
//Textures
Engine::ResourceManager::LoadTextureToBuffer("TurbineTexture", "../Res/Assets/Textures/Liquefied/Turbine_512.png");
Engine::ResourceManager::LoadTextureToBuffer("ObstacleTexture", "../Res/Assets/Textures/Liquefied/Box_512.png");
Engine::ResourceManager::LoadTextureToBuffer("TestTexture", "../Res/Assets/Textures/Liquefied/Test_8.png");
Engine::ResourceManager::LoadTextureToBuffer("TestTexture", "../Res/Assets/Textures/Liquefied/Test_1C_1G_8Px.png");
}

void LiquefiedApp::AddBorderCells() const
Expand Down Expand Up @@ -147,7 +147,7 @@ namespace Liq
}

//Else overwrite objects/sprites/textures with default gray
color = {0.5f, 0.5f, 0.5f};
// color = {0.5f, 0.5f, 0.5f};
}
else
{
Expand Down Expand Up @@ -232,7 +232,7 @@ namespace Liq
{
Engine::PROFILE_SCOPE("Visualize grid");

RenderSmoke();
// RenderSmoke();
_gridRenderer->UpdateGpuStorage();
_gridRenderer->Flush(nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion Engine/Application/GlobalParams.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ namespace Engine
inline static bool pauseSimulation = true;
inline static bool resetSimulation = false;
inline static bool activateDebugging = false;
inline static bool renderObjects = false;
inline static bool renderObjects = true;
inline static Integrator integratorChoice = Integrator::ForwardEuler;
inline static Visualization visualizationChoice = Visualization::Greyscale;

Expand Down
11 changes: 10 additions & 1 deletion Engine/Core/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,13 @@ namespace Engine
const ColorEntry color = ColorLUT::ParaView[idx];
return {color.r, color.g, color.b};
}
}

glm::vec3 Utility::TransformVec3uTo3f(const glm::uvec3& vec)
{
return {
(float)vec.x / 255.0f,
(float)vec.y / 255.0f,
(float)vec.z / 255.0f,
};
}
}
3 changes: 2 additions & 1 deletion Engine/Core/Utility.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ namespace Engine
static glm::vec3 GetColor_Scientic(float value, float min, float max);
static glm::vec3 GetColor_BlackBody(float scalar);
static glm::vec3 GetColor_ParaView(float scalar);
static glm::vec3 TransformVec3uTo3f(const glm::uvec3& vec);
};
}
}
22 changes: 14 additions & 8 deletions Engine/Rendering/Renderer/GridRenderer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include "GridRenderer.hpp"
#include "Utility.hpp"

namespace Engine
{
Expand Down Expand Up @@ -128,7 +129,7 @@ namespace Engine

if(width != height || width % size != 0 || height % size != 0)
{
Logger::Error("Failed", "Subsampling", "Dimensions or format unsupported!");
Logger::Error("Failed", "Subsampling", "Dimensions or format unsupported");
return;
}

Expand All @@ -139,24 +140,29 @@ namespace Engine
uint32 sampleAmount = width / size;

glm::uvec3 subsampledColor = {0, 0, 0};
glm::uvec2 gridPos = pos;
bool success = false;
uint32 count = 0;

//Go over the image in pxSample steps
//Go over the image in sampleAmount steps
for(uint32 x = 0; x < width; x += sampleAmount)
{
for(uint32 y = 0; y < height; y += sampleAmount)
{
success = tex->Subsample(x, y, sampleAmount, &subsampledColor);
if(success)
{
Logger::Print("Color " + std::to_string(count) + ": "
+ std::to_string(subsampledColor.x) + ", "
+ std::to_string(subsampledColor.y) + ", "
+ std::to_string(subsampledColor.z));
glm::vec3 color = Utility::TransformVec3uTo3f(subsampledColor);
Logger::Print("Color (" + std::to_string(gridPos.x) + ", "
+ std::to_string(gridPos.y) + ") : "
+ std::to_string(color.x) + ", "
+ std::to_string(color.y) + ", "
+ std::to_string(color.z));
Set(gridPos.x, gridPos.y, color);
}
count++;
gridPos.y++;
}
gridPos.x++;
gridPos.y = pos.y; //Reset y-position
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,9 @@ namespace Engine
*(_imgBuffer + (y * _width * 3) + (x * 3) + 1) = (unsigned char)(color.y * 255);
*(_imgBuffer + (y * _width * 3) + (x * 3) + 2) = (unsigned char)(color.z * 255);
}
{
Logger::Error("Failed", "Modification", "Array access out of bounds");
}
}
else
{
Expand All @@ -208,6 +211,9 @@ namespace Engine
*(_imgBuffer + (y * _width * 3) + (x * 3) + 1) = *(_backupBuffer + (y * _width * 3) + (x * 3) + 1);
*(_imgBuffer + (y * _width * 3) + (x * 3) + 2) = *(_backupBuffer + (y * _width * 3) + (x * 3) + 2);
}
{
Logger::Error("Failed", "Modification", "Array access out of bounds");
}
}
else
{
Expand Down Expand Up @@ -250,14 +256,24 @@ namespace Engine
return false;
}

*colorOut = GetPxColorRaw(xpos, ypos);
return true;

uint32 pxAmount = sampleAmount * sampleAmount;
glm::uvec3 totalColor = {0, 0, 0};

for(uint32 x = 0; x < sampleAmount; x++)
{
for(uint32 y = 0; y < sampleAmount; y++)
{
totalColor += GetPxColorRaw(xpos + x, ypos + y);
if((int32)(xpos + x) < _width && (int32)(ypos + y)< _height)
{
totalColor += GetPxColorRaw(xpos + x, ypos + y);
}
else
{
Logger::Error("Failed", "Subsampling", "Array access out of bounds");
}
}
}

Expand Down
File renamed without changes.
1 change: 1 addition & 0 deletions Engine/Rendering/Resources/TextureBuffer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: Implement
1 change: 1 addition & 0 deletions Engine/Rendering/Resources/TextureBuffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// TODO: Implement
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 927d85a

Please sign in to comment.