diff --git a/Binaries/Data/shaders/texture_bake/frag.glsl b/Binaries/Data/shaders/texture_bake/frag.glsl new file mode 100644 index 0000000000..dc803c003a --- /dev/null +++ b/Binaries/Data/shaders/texture_bake/frag.glsl @@ -0,0 +1,80 @@ +#version 430 core +out vec4 FragColor; + +#define NUM_TEXTURE_LAYERS 8 + +uniform vec3 _LightPosition; +uniform vec3 _LightColor; + +in float height; +in float Distance; +in vec3 FragPos; +in vec3 Normal; +in vec2 TexCoord; + +uniform sampler2D _DiffuseTextures[NUM_TEXTURE_LAYERS]; +uniform vec3 _DiffuseTexturesHeights[NUM_TEXTURE_LAYERS]; +uniform vec3 _DiffuseTexturesData[NUM_TEXTURE_LAYERS]; +uniform float _SeaLevel; + + +vec2 hash( vec2 p ) // replace this by something better +{ + p = vec2( dot(p,vec2(127.1,311.7)), dot(p,vec2(269.5,183.3)) ); + return -1.0 + 2.0*fract(sin(p)*43758.5453123); +} + +float noise( in vec2 p ) +{ + const float K1 = 0.366025404; // (sqrt(3)-1)/2; + const float K2 = 0.211324865; // (3-sqrt(3))/6; + + vec2 i = floor( p + (p.x+p.y)*K1 ); + vec2 a = p - i + (i.x+i.y)*K2; + float m = step(a.y,a.x); + vec2 o = vec2(m,1.0-m); + vec2 b = a - o + K2; + vec2 c = a - 1.0 + 2.0*K2; + vec3 h = max( 0.5-vec3(dot(a,a), dot(b,b), dot(c,c) ), 0.0 ); + vec3 n = h*h*h*h*vec3( dot(a,hash(i+0.0)), dot(b,hash(i+o)), dot(c,hash(i+1.0))); + return dot( n, vec3(70.0) ); +} + + +float getTextureInfluence(int i, vec2 coord) { +float h = height + noise(coord*_DiffuseTexturesData[i].x)*_DiffuseTexturesData[i].y; + float midVal = (_DiffuseTexturesHeights[i].x + _DiffuseTexturesHeights[i].y)/2; + float p = 0; + if(h < midVal) + p = _DiffuseTexturesHeights[i].x - height; + if(h >= midVal) + p =height - _DiffuseTexturesHeights[i].y; + + return pow(2.713, -_DiffuseTexturesData[i].z*p); +} + +vec4 GetTextureColorBasedOnHeight(vec2 coord){ + vec4 accum = vec4(0.0); + float total_influence = 0.0; + + for(int i=0; i < NUM_TEXTURE_LAYERS ; i++){ + float texture_influence = getTextureInfluence(i, coord*_DiffuseTexturesHeights[i].z); + + total_influence += texture_influence; + accum += texture(_DiffuseTextures[i], coord*_DiffuseTexturesHeights[i].z) * texture_influence; + } + + if(total_influence > 0) { + accum /= total_influence ; + } + return accum; +} + + +void main() +{ + + vec3 objectColor = vec3(1, 1, 1); + objectColor = GetTextureColorBasedOnHeight(TexCoord).xyz; + FragColor = vec4(objectColor, 1.0f); +} \ No newline at end of file diff --git a/Binaries/Data/shaders/texture_bake/geom.glsl b/Binaries/Data/shaders/texture_bake/geom.glsl new file mode 100644 index 0000000000..cdc8dfbdca --- /dev/null +++ b/Binaries/Data/shaders/texture_bake/geom.glsl @@ -0,0 +1,55 @@ +#version 430 core + +layout(triangles) in; +layout(triangle_strip, max_vertices = 3) out; + +uniform mat4 _PV; + +out float height; +out float Distance; +out vec3 FragPos; +out vec3 Normal; +out vec2 TexCoord; + +in DATA +{ + float height; + vec3 FragPos; + vec3 Normal; + float distance; + vec2 TexCoord; +} data_in[]; + +const vec4 clipPlane = vec4(0, -1, 0, 5); + +void main() +{ + gl_Position = _PV * gl_in[0].gl_Position; + //gl_ClipDistance[0] = dot(gl_Position, clipPlane); + Normal = data_in[0].Normal; + height = data_in[0].height; + Distance = data_in[0].distance; + TexCoord = data_in[0].TexCoord; + FragPos = data_in[0].FragPos; + EmitVertex(); + + gl_Position = _PV * gl_in[1].gl_Position; + //gl_ClipDistance[0] = dot(gl_Position, clipPlane); + height = data_in[1].height; + Distance = data_in[1].distance; + Normal = data_in[1].Normal; + TexCoord = data_in[1].TexCoord; + FragPos = data_in[1].FragPos; + EmitVertex(); + + gl_Position = _PV * gl_in[2].gl_Position; + //gl_ClipDistance[0] = dot(gl_Position, clipPlane); + height = data_in[2].height; + Distance = data_in[2].distance; + Normal = data_in[2].Normal; + TexCoord = data_in[2].TexCoord; + FragPos = data_in[2].FragPos; + EmitVertex(); + + EndPrimitive(); +} \ No newline at end of file diff --git a/Binaries/Data/shaders/texture_bake/vert.glsl b/Binaries/Data/shaders/texture_bake/vert.glsl new file mode 100644 index 0000000000..f9d5903d70 --- /dev/null +++ b/Binaries/Data/shaders/texture_bake/vert.glsl @@ -0,0 +1,29 @@ +#version 430 core +layout (location = 0) in vec3 aPos; +layout (location = 1) in vec3 aNorm; +layout (location = 2) in vec2 aTexCoord; + +uniform mat4 _Model; +uniform mat4 _PV; + +out DATA +{ + float height; + vec3 FragPos; + vec3 Normal; + float distance; + vec2 TexCoord; +} data_out; + + + +void main() +{ + gl_Position = vec4(0, aPos.x, aPos.z, 1.0); + data_out.height = aPos.y; + data_out.FragPos = vec3(aPos.x, aPos.y, aPos.z); + data_out.Normal = vec3(aNorm.x, aNorm.y, aNorm.z); + data_out.TexCoord = aTexCoord; +// data_out.distance = sqrt(_CameraPos, gl_Position.xyz); + data_out.distance = 0; +} \ No newline at end of file diff --git a/Binaries/TerraForge3D.exe b/Binaries/TerraForge3D.exe index a985c0aa3c..e1ad4c7424 100644 Binary files a/Binaries/TerraForge3D.exe and b/Binaries/TerraForge3D.exe differ diff --git a/src/Base/ExportTexture.cpp b/src/Base/ExportTexture.cpp new file mode 100644 index 0000000000..74fb3e529a --- /dev/null +++ b/src/Base/ExportTexture.cpp @@ -0,0 +1,26 @@ +#include "ExportTexture.h" + +#include +#include + +void ExportTexture(int fbo, std::string path, int w, int h) +{ + if (path.size() < 3) + return; + + if (path.find(".png") == std::string::npos) + path += ".png"; + + unsigned char* data = new unsigned char[w * h * 3]; + + glReadBuffer(GL_COLOR_ATTACHMENT0); + glBindFramebuffer(GL_FRAMEBUFFER, fbo); + glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE, data); + glBindFramebuffer(GL_FRAMEBUFFER, 0); + + stbi_flip_vertically_on_write(true); + + stbi_write_png(path.c_str(), w, h, 3, data, w * 3); + + delete[] data; +} diff --git a/src/Base/ExportTexture.h b/src/Base/ExportTexture.h new file mode 100644 index 0000000000..853d05d941 --- /dev/null +++ b/src/Base/ExportTexture.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void ExportTexture(int fbo, std::string path, int w, int h); \ No newline at end of file diff --git a/src/Base/FrameBuffer.cpp b/src/Base/FrameBuffer.cpp index c453eb68a2..b9ebd2fbca 100644 --- a/src/Base/FrameBuffer.cpp +++ b/src/Base/FrameBuffer.cpp @@ -2,19 +2,21 @@ #include -FrameBuffer::FrameBuffer() +FrameBuffer::FrameBuffer(int w, int h) { + width = w; + height = h; glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); glGenTextures(1, &colorTexture); glBindTexture(GL_TEXTURE_2D, colorTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 800, 600, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, w, h, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorTexture, 0); glGenTextures(1, &depthTexture); glBindTexture(GL_TEXTURE_2D, depthTexture); - glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, 800, 600, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); + glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, w, h, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); @@ -32,6 +34,7 @@ FrameBuffer::~FrameBuffer() void FrameBuffer::Begin() { + glViewport(0, 0, width, height); glBindFramebuffer(GL_FRAMEBUFFER, fbo); } diff --git a/src/Base/FrameBuffer.h b/src/Base/FrameBuffer.h index 69bc902ff8..21b9b68048 100644 --- a/src/Base/FrameBuffer.h +++ b/src/Base/FrameBuffer.h @@ -6,7 +6,7 @@ class FrameBuffer { public: - FrameBuffer(); + FrameBuffer(int width = 800, int height = 600); ~FrameBuffer(); void Begin(); @@ -18,4 +18,5 @@ class FrameBuffer { private: uint32_t colorTexture, depthTexture, fbo; + int width, height; }; diff --git a/src/Main.cpp b/src/Main.cpp index 017cf5bf67..0fa795f447 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -59,10 +60,10 @@ static Model sea("Sea"); static Model grid("Grid"); -static FrameBuffer* reflectionfbo; +static FrameBuffer* reflectionfbo, * textureFBO; static Application* myApp; -static Shader* shd, * meshNormalsShader, * wireframeShader, * waterShader; +static Shader* shd, * meshNormalsShader, * wireframeShader, * waterShader, * textureBakeShader; static Camera camera; static Stats s_Stats; static ActiveWindows activeWindows; @@ -97,14 +98,15 @@ static bool autoSave = false; static bool isExploreMode = false; static bool isIExploreMode = false; static bool showFoliage = true; +static bool isTextureBake = false; static std::atomic isRemeshing = false; static std::atomic isRuinning = true; -static Texture2D* diffuse, * normal, * gridTex, *waterDudvMap, *waterNormal; +static Texture2D* diffuse, * normal, * gridTex, * waterDudvMap, * waterNormal; static uint32_t vao, vbo, ebo; - + static float noiseStrength = 1.0f; static int resolution = 256; static float mouseSpeed = 25; @@ -295,10 +297,13 @@ static void ResetShader() { bool res = false; if (shd) delete shd; + if (textureBakeShader) + delete textureBakeShader; if (!wireframeShader) wireframeShader = new Shader(GetDefaultVertexShaderSource(), GetDefaultFragmentShaderSource(), GetWireframeGeometryShaderSource()); if (!waterShader) waterShader = new Shader(ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\water\\vert.glsl", &res), ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\water\\frag.glsl", &res), ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\water\\geom.glsl", &res)); + textureBakeShader = new Shader(ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\texture_bake\\vert.glsl", &res), ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\texture_bake\\frag.glsl", &res), ReadShaderSourceFile(GetExecutableDir() + "\\Data\\shaders\\texture_bake\\geom.glsl", &res)); shd = new Shader(GetVertexShaderSource(), GetFragmentShaderSource(), GetGeometryShaderSource()); } @@ -361,78 +366,114 @@ static void GenerateMesh() grid.UploadToGPU(); } -static void DoTheRederThing(float deltaTime, bool renderWater = false) { +static void DoTheRederThing(float deltaTime, bool renderWater = false, bool bakeTexture = false) { static float time; time += deltaTime; camera.UpdateCamera(CameraPosition, CameraRotation); Shader* shader; - if (skyboxEnabled) - RenderSky(camera.view, camera.pers); - glEnable(GL_DEPTH_TEST); - glEnable(GL_BLEND); - glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); - if (wireFrameMode) - shader = wireframeShader; - else - shader = shd; - shader->Bind(); - shader->SetTime(&time); - shader->SetMPV(camera.pv); - shader->SetUniformMat4("_Model", terrain.modelMatrix); - shader->SetLightCol(LightColor); - shader->SetLightPos(LightPosition); - float tmp[3]; - tmp[0] = viewportMousePosX; - tmp[1] = viewportMousePosY; - tmp[2] = ImGui::GetIO().MouseDown[0]; - shader->SetUniform3f("_MousePos", tmp); - tmp[0] = 800; - tmp[1] = 600; - tmp[2] = 1; - shader->SetUniform3f("_Resolution", tmp); - shader->SetUniform3f("_CameraPos", CameraPosition); - shader->SetUniformf("_SeaLevel", seaLevel); - shader->SetUniformf("_CameraNear", camera.near); - shader->SetUniformf("_CameraFar", camera.far); - UpdateDiffuseTexturesUBO(shader->GetNativeShader(), "_DiffuseTextures"); - terrain.Render(); - - if (showFoliage) - RenderFoliage(shader, camera); - - // For Future - //gridTex->Bind(5); - //grid->Render(); - - - if (showSea && renderWater) { - waterShader->Bind(); - waterShader->SetTime(&time); - waterShader->SetUniformf("_SeaAlpha", seaAlpha); - waterShader->SetUniformf("_SeaDistScale", seaDistortionScale); - waterShader->SetUniformf("_SeaDistStrength", seaDistortionStength); - waterShader->SetUniformf("_SeaReflectivity", seaReflectivity); - waterShader->SetUniformf("_SeaLevel", seaLevel); - waterShader->SetUniformf("_SeaWaveSpeed", seaWaveSpeed); - glActiveTexture(7); - glBindTexture(GL_TEXTURE_2D, reflectionfbo->GetColorTexture()); - waterShader->SetUniformi("_ReflectionTexture", 7); - if(waterDudvMap) - waterDudvMap->Bind(8); - waterShader->SetUniformi("_DuDvMap", 8); - if (waterNormal) - waterNormal->Bind(9); - waterShader->SetUniformi("_NormalMap", 9); - sea.position.y = seaLevel; - sea.Update(); - glm::mat4 tmp = glm::translate(camera.pv, glm::vec3(0, seaLevel, 0)); - waterShader->SetUniform3f("_SeaColor", SeaColor); - waterShader->SetMPV(tmp); - waterShader->SetLightCol(LightColor); - waterShader->SetLightPos(LightPosition); - sea.Render(); + // Texture Bake + if (isTextureBake) + { + Camera cam; + float CameraP[3] = { 0.0f, 0.0f, CameraPosition[2] }; + float CameraR[3] = { 5185.0f, 0.0f, 0.0f }; + cam.far = 1000; + cam.aspect = 1; + cam.UpdateCamera(CameraP, CameraR); + shader = textureBakeShader; + shader->Bind(); + shader->SetTime(&time); + shader->SetMPV(cam.pv); + shader->SetUniformMat4("_Model", terrain.modelMatrix); + shader->SetLightCol(LightColor); + shader->SetLightPos(LightPosition); + float tmp[3]; + tmp[0] = 1024; + tmp[1] = 1024; + tmp[2] = 1; + shader->SetUniform3f("_Resolution", tmp); + shader->SetUniform3f("_CameraPos", CameraPosition); + shader->SetUniformf("_SeaLevel", seaLevel); + shader->SetUniformf("_CameraNear", camera.near); + shader->SetUniformf("_CameraFar", camera.far); + UpdateDiffuseTexturesUBO(shader->GetNativeShader(), "_DiffuseTextures"); + terrain.Render(); } + else { + if (skyboxEnabled) + RenderSky(camera.view, camera.pers); + glEnable(GL_DEPTH_TEST); + glEnable(GL_BLEND); + glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); + if (wireFrameMode) + shader = wireframeShader; + else + shader = shd; + shader->Bind(); + shader->SetTime(&time); + shader->SetMPV(camera.pv); + shader->SetUniformMat4("_Model", terrain.modelMatrix); + shader->SetLightCol(LightColor); + shader->SetLightPos(LightPosition); + float tmp[3]; + tmp[0] = viewportMousePosX; + tmp[1] = viewportMousePosY; + tmp[2] = ImGui::GetIO().MouseDown[0]; + shader->SetUniform3f("_MousePos", tmp); + tmp[0] = 800; + tmp[1] = 600; + tmp[2] = 1; + shader->SetUniform3f("_Resolution", tmp); + shader->SetUniform3f("_CameraPos", CameraPosition); + shader->SetUniformf("_SeaLevel", seaLevel); + shader->SetUniformf("_CameraNear", camera.near); + shader->SetUniformf("_CameraFar", camera.far); + UpdateDiffuseTexturesUBO(shader->GetNativeShader(), "_DiffuseTextures"); + terrain.Render(); + + + if (showFoliage) + RenderFoliage(shader, camera); + + + + + // For Future + //gridTex->Bind(5); + //grid->Render(); + + + if (showSea && renderWater) { + waterShader->Bind(); + waterShader->SetTime(&time); + waterShader->SetUniformf("_SeaAlpha", seaAlpha); + waterShader->SetUniformf("_SeaDistScale", seaDistortionScale); + waterShader->SetUniformf("_SeaDistStrength", seaDistortionStength); + waterShader->SetUniformf("_SeaReflectivity", seaReflectivity); + waterShader->SetUniformf("_SeaLevel", seaLevel); + waterShader->SetUniformf("_SeaWaveSpeed", seaWaveSpeed); + glActiveTexture(7); + glBindTexture(GL_TEXTURE_2D, reflectionfbo->GetColorTexture()); + waterShader->SetUniformi("_ReflectionTexture", 7); + if (waterDudvMap) + waterDudvMap->Bind(8); + waterShader->SetUniformi("_DuDvMap", 8); + if (waterNormal) + waterNormal->Bind(9); + waterShader->SetUniformi("_NormalMap", 9); + sea.position.y = seaLevel; + sea.Update(); + glm::mat4 tmp = glm::translate(camera.pv, glm::vec3(0, seaLevel, 0)); + waterShader->SetUniform3f("_SeaColor", SeaColor); + waterShader->SetMPV(tmp); + waterShader->SetLightCol(LightColor); + waterShader->SetLightPos(LightPosition); + sea.Render(); + } + } + + } @@ -451,6 +492,7 @@ static void ShowTerrainControls() ImGui::Checkbox("Show Foliage", &showFoliage); ImGui::Checkbox("Infinite Explorer Mode", &isIExploreMode); ImGui::Checkbox("Explorer Mode", &isExploreMode); + ImGui::Checkbox("Texture Bake Mode", &isTextureBake); ImGui::NewLine(); if (ImGui::Button("Update Mesh")) RegenerateMesh(); @@ -479,6 +521,13 @@ static void ShowTerrainControls() if (ImGui::Button("Filter Settings")) { activeWindows.filtersManager = true; } + + if (ImGui::Button("Export Frame")) { + if(isTextureBake) + ExportTexture(textureFBO->GetRendererID() , ShowSaveFileDialog(".png"), 1024, 1024); + else + ExportTexture(GetViewportFramebufferId(), ShowSaveFileDialog(".png"), 800, 600); + } ImGui::Separator(); if (ImGui::Button("Change Mode##4584")) { @@ -614,7 +663,10 @@ static void ShowMainScene() { } ImVec2 wsize = ImGui::GetWindowSize(); - ImGui::Image((ImTextureID)GetViewportFramebufferColorTextureId(), wsize, ImVec2(0, 1), ImVec2(1, 0)); + if (isTextureBake) + ImGui::Image((ImTextureID)textureFBO->GetColorTexture(), wsize, ImVec2(0, 1), ImVec2(1, 0)); + else + ImGui::Image((ImTextureID)GetViewportFramebufferColorTextureId(), wsize, ImVec2(0, 1), ImVec2(1, 0)); //ImGui::Image((ImTextureID)reflectionfbo->GetDepthTexture(), wsize, ImVec2(0, 1), ImVec2(1, 0)); ImGui::EndChild(); } @@ -1205,7 +1257,7 @@ static void ShowMenu() { } ImGui::EndMainMenuBar(); - } + } } static void ShowErrorModal() { @@ -1232,7 +1284,7 @@ static void ShowSeaSettings() { ImGui::Text("DuDv Map"); ImGui::SameLine(); - if (ImGui::ImageButton((ImTextureID)waterDudvMap->GetRendererID(), ImVec2(50, 50))){ + if (ImGui::ImageButton((ImTextureID)waterDudvMap->GetRendererID(), ImVec2(50, 50))) { std::string fileName = ShowOpenFileDialog(L".png\0"); if (fileName.size() > 3) { delete waterDudvMap; @@ -1373,7 +1425,6 @@ class MyApp : public Application noiseLayersTmp.clear(); } - if (!isExploreMode) { if (reqTexRfrsh) { if (diffuse) @@ -1453,20 +1504,28 @@ class MyApp : public Application } } + if (isTextureBake) { + textureFBO->Begin(); + glViewport(0, 0, 1024, 1024); // This should be 4096 instead of 1024 but my computer is too weak to go for 4096 + GetWindow()->Clear(); + DoTheRederThing(deltatime, false, true); + } + else { + reflectionfbo->Begin(); + glViewport(0, 0, 800, 600); + GetWindow()->Clear(); + s_Stats.deltaTime = deltatime; + DoTheRederThing(deltatime); + + glBindFramebuffer(GL_FRAMEBUFFER, GetViewportFramebufferId()); + glViewport(0, 0, 800, 600); + GetWindow()->Clear(); + DoTheRederThing(deltatime, true); + } - reflectionfbo->Begin(); - glViewport(0, 0, 800, 600); - GetWindow()->Clear(); - s_Stats.deltaTime = deltatime; - DoTheRederThing(deltatime); - - glBindFramebuffer(GL_FRAMEBUFFER, GetViewportFramebufferId()); - glViewport(0, 0, 800, 600); - GetWindow()->Clear(); - DoTheRederThing(deltatime, true); - - glBindFramebuffer(GL_FRAMEBUFFER, 0); + glBindFramebuffer(GL_FRAMEBUFFER, 0); RenderImGui(); + if (autoUpdate) RegenerateMesh(); @@ -1481,7 +1540,7 @@ class MyApp : public Application expH = isExploreMode; - + reflectionfbo->Begin(); @@ -1498,7 +1557,7 @@ class MyApp : public Application GetWindow()->Clear(); s_Stats.deltaTime = deltatime; UpdateExplorerControls(CameraPosition, CameraRotation, isIExploreMode, &nLOffsetX, &nLOffsetY); - DoTheRederThing(deltatime); + DoTheRederThing(deltatime, true); if ((glfwGetKey(GetWindow()->GetNativeWindow(), GLFW_KEY_ESCAPE))) { @@ -1514,6 +1573,8 @@ class MyApp : public Application RegenerateMesh(); } + + if (glfwGetKey(GetWindow()->GetNativeWindow(), GLFW_KEY_I)) nLOffsetY -= 0.01f; @@ -1638,7 +1699,7 @@ class MyApp : public Application io.MouseWheel = (float)y; }); GetWindow()->SetClearColor({ 0.1f, 0.1f, 0.1f }); - GenerateMesh(); + GenerateMesh(); glEnable(GL_DEPTH_TEST); LightPosition[1] = -0.3f; CameraPosition[1] = 0.2f; @@ -1648,7 +1709,7 @@ class MyApp : public Application scale = 1; noiseLayersTmp.push_back(NoiseLayer()); Log("Started Up App!"); - + if (loadFile.size() > 0) { Log("Loading File from " + loadFile); OpenSaveFile(loadFile); @@ -1667,11 +1728,11 @@ class MyApp : public Application waterNormalMap = "DEFAULT"; Log("Loaded Water DUDV Map from " + GetExecutableDir() + "\\Data\\textures\\water_normal.png"); reflectionfbo = new FrameBuffer(); - + textureFBO = new FrameBuffer(1024, 1024); // This should be 4096 instead of 1024 but my computer is too weak to go for 4096 LoadTextureThumbs(); // For Debug Only - autoUpdate = true; + autoUpdate = true; } void OnEnd() diff --git a/src/TextureBake.cpp b/src/TextureBake.cpp deleted file mode 100644 index 4bcbeacef3..0000000000 --- a/src/TextureBake.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include "TextureBake.h" -#include -#include -#include -#include -#include - -Texture2D* BakeTexture(Model* model) -{ - int res = model->mesh->res; - unsigned char* data = new unsigned char[res*res*3]; - Texture2D* tex = new Texture2D(res, res); - for (int x = 0; x < res; x++) { - for (int y = 0; y < res; y++) { - float elev = (model->mesh->GetElevation(x, y) + model->mesh->minHeight)/(model->mesh->maxHeight); - data[x * res + y * 3 + 0] = (unsigned char)(elev * 255); - data[x * res + y * 3 + 1] = (unsigned char)(elev * 255); - data[x * res + y * 3 + 2] =(unsigned char)( elev * 255); - } - } - tex->SetData(data, res * res * 3); - delete[] data; - return tex; -} diff --git a/src/TextureBake.h b/src/TextureBake.h deleted file mode 100644 index 594888f204..0000000000 --- a/src/TextureBake.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once -#include -#include - -Texture2D* BakeTexture(Model* model); - diff --git a/src/TextureSettings.cpp b/src/TextureSettings.cpp index 6d455215b1..5203345738 100644 --- a/src/TextureSettings.cpp +++ b/src/TextureSettings.cpp @@ -6,7 +6,6 @@ #include #include #include -#include #include bool* reqrfrsh; @@ -17,7 +16,8 @@ uint32_t diffuseUBOLocCache = -1; uint32_t diffuseUBO; Texture2D* diffuse; Model* model; -Texture2D* tmp; + +int tmp; struct TextureLayer { Texture2D* texture; @@ -225,6 +225,7 @@ void ShowTextureSettings(bool* pOpen) { ImGui::Begin("Texture Settings", pOpen); ShowOpenTextureModal(); + uint32_t id = diffuse ? diffuse->GetRendererID() : 0; //ImGui::Image((ImTextureID)(id), ImVec2(200, 200));