Atlas margin setting support
This commit is contained in:
@@ -43,6 +43,10 @@ struct ProceduralTextureComponent {
|
||||
// Texture size (default 512x512)
|
||||
int textureSize = 512;
|
||||
|
||||
// UV margin for texture mapping (default 0.01, range 0.01-0.025)
|
||||
// Used to prevent color bleeding by adding padding around UV coordinates
|
||||
float uvMargin = 0.01f;
|
||||
|
||||
// Whether the texture needs regeneration
|
||||
bool dirty = true;
|
||||
|
||||
|
||||
@@ -2480,8 +2480,8 @@ void CellGridSystem::buildDistrictPlaza(flecs::entity entity,
|
||||
const TextureRectInfo *rect =
|
||||
texture.getNamedRect(district.textureRectName);
|
||||
if (rect) {
|
||||
// Apply UV mapping with 0.01 margin
|
||||
const float margin = 0.01f;
|
||||
// Apply UV mapping with configurable margin
|
||||
const float margin = texture.uvMargin;
|
||||
float uRange = (rect->u2 - rect->u1) *
|
||||
(1.0f - 2.0f * margin);
|
||||
float vRange = (rect->v2 - rect->v1) *
|
||||
@@ -2851,7 +2851,8 @@ void CellGridSystem::buildLotBase(flecs::entity entity, LotComponent &lot)
|
||||
const TextureRectInfo *rect =
|
||||
texture.getNamedRect(textureRectToUse);
|
||||
if (rect) {
|
||||
const float margin = 0.01f;
|
||||
// Apply UV mapping with configurable margin
|
||||
const float margin = texture.uvMargin;
|
||||
float uRange = (rect->u2 - rect->u1) *
|
||||
(1.0f - 2.0f * margin);
|
||||
float vRange = (rect->v2 - rect->v1) *
|
||||
@@ -3046,8 +3047,8 @@ void CellGridSystem::applyUVMappingToBuffer(Procedural::TriangleBuffer &tb,
|
||||
std::to_string(rect->u2) + " v=" + std::to_string(rect->v1) +
|
||||
"-" + std::to_string(rect->v2));
|
||||
|
||||
// Apply texture rectangle UV mapping
|
||||
const float margin = 0.01f;
|
||||
// Apply texture rectangle UV mapping with configurable margin
|
||||
const float margin = texture.uvMargin;
|
||||
float uRange = (rect->u2 - rect->u1) * (1.0f - 2.0f * margin);
|
||||
float vRange = (rect->v2 - rect->v1) * (1.0f - 2.0f * margin);
|
||||
float uOffset = rect->u1 + (rect->u2 - rect->u1) * margin;
|
||||
|
||||
@@ -204,8 +204,8 @@ void ProceduralMeshSystem::applyUVMapping(Procedural::TriangleBuffer* buffer,
|
||||
const TextureRectInfo* rect = texture.getNamedRect(rectName);
|
||||
if (!rect) return;
|
||||
|
||||
// Calculate UV mapping with margin
|
||||
const float margin = 0.01f;
|
||||
// Calculate UV mapping with configurable margin
|
||||
const float margin = texture.uvMargin;
|
||||
float uRange = (rect->u2 - rect->u1) * (1.0f - 2.0f * margin);
|
||||
float vRange = (rect->v2 - rect->v1) * (1.0f - 2.0f * margin);
|
||||
float uOffset = rect->u1 + (rect->u2 - rect->u1) * margin;
|
||||
|
||||
@@ -1043,6 +1043,7 @@ nlohmann::json SceneSerializer::serializeProceduralTexture(flecs::entity entity)
|
||||
|
||||
json["textureName"] = texture.textureName;
|
||||
json["textureSize"] = texture.textureSize;
|
||||
json["uvMargin"] = texture.uvMargin;
|
||||
|
||||
// Serialize colors array
|
||||
nlohmann::json colorsJson = nlohmann::json::array();
|
||||
@@ -1079,6 +1080,7 @@ void SceneSerializer::deserializeProceduralTexture(flecs::entity entity, const n
|
||||
|
||||
texture.textureName = json.value("textureName", "");
|
||||
texture.textureSize = json.value("textureSize", 512);
|
||||
texture.uvMargin = json.value("uvMargin", 0.01f);
|
||||
|
||||
// Deserialize colors array
|
||||
if (json.contains("colors") && json["colors"].is_array()) {
|
||||
|
||||
@@ -252,6 +252,19 @@ bool ProceduralTextureEditor::renderComponent(flecs::entity entity, ProceduralTe
|
||||
modified = true;
|
||||
}
|
||||
|
||||
// UV Margin control to prevent color bleeding
|
||||
ImGui::Separator();
|
||||
ImGui::Text("UV Margin (prevents color bleeding):");
|
||||
if (ImGui::DragFloat("Margin", &texture.uvMargin, 0.001f, 0.01f, 0.025f, "%.3f")) {
|
||||
// Clamp to valid range
|
||||
if (texture.uvMargin < 0.01f) texture.uvMargin = 0.01f;
|
||||
if (texture.uvMargin > 0.025f) texture.uvMargin = 0.025f;
|
||||
texture.markDirty();
|
||||
modified = true;
|
||||
}
|
||||
ImGui::TextDisabled("Default: 0.010, Range: 0.010-0.025, Step: 0.001");
|
||||
ImGui::TextDisabled("Higher values = more padding, less color bleeding");
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
// Color grid
|
||||
|
||||
@@ -235,7 +235,7 @@ bool TriangleBufferEditor::renderComponent(flecs::entity entity, TriangleBufferC
|
||||
ImGui::Text("Texture Mapping:");
|
||||
renderTextureSelector(entity, tb);
|
||||
renderRectSelector(entity, tb);
|
||||
ImGui::TextDisabled("UVs will be mapped to rectangle with 0.01 margin");
|
||||
ImGui::TextDisabled("UVs will be mapped to rectangle with margin from texture");
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user