diff --git a/shaders/planet_land_desktop.fragment b/shaders/planet_land_desktop.fragment index aa1e657..c2c0526 100644 --- a/shaders/planet_land_desktop.fragment +++ b/shaders/planet_land_desktop.fragment @@ -30,7 +30,7 @@ void main() { vec3 normal = normalize(fragmentDir); // На планете-сфере нормаль совпадает с направлением от центра float diff = max(dot(normal, lightToSource), 0.0); - float ambient = 0.15; // Базовая освещенность ночной стороны + float ambient = 0.3; // Базовая освещенность ночной стороны float surfaceLightIntensity = diff + ambient; // --- 2. Динамический цвет тумана --- diff --git a/shaders/planet_stone_desktop.fragment b/shaders/planet_stone_desktop.fragment index 1bae2c5..0c76c98 100644 --- a/shaders/planet_stone_desktop.fragment +++ b/shaders/planet_stone_desktop.fragment @@ -30,7 +30,7 @@ void main() // Применяем shadowMask к диффузной составляющей // Если точка на планете в тени, то прямой свет (diff) обнуляется - float ambient = 0.15; + float ambient = 0.3; float lightIntensity = (diff * shadowMask); lightIntensity *= mix(0.2, 1.0, shadowMask); diff --git a/src/Game.cpp b/src/Game.cpp index da44a12..5028d65 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -206,6 +206,12 @@ namespace ZL spaceshipTexture = std::make_unique(CreateTextureDataFromPng("./resources/DefaultMaterial_BaseColor_shine.png", CONST_ZIP_FILE)); spaceshipBase = LoadFromTextFile02("./resources/spaceship006.txt", CONST_ZIP_FILE); spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix()); + + //spaceshipTexture = std::make_unique(CreateTextureDataFromPng("./resources/Untitled.001.png", CONST_ZIP_FILE)); + //spaceshipBase = LoadFromTextFile02("./resources/spaceshipnew001.txt", CONST_ZIP_FILE); + //spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(-M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix()); + + //spaceshipBase.Move(Vector3f{ -0.52998, -13, 0 }); //spaceshipBase.Move(Vector3f{ -0.52998, -10, 10 }); diff --git a/src/planet/PlanetObject.cpp b/src/planet/PlanetObject.cpp index 711246d..9458696 100644 --- a/src/planet/PlanetObject.cpp +++ b/src/planet/PlanetObject.cpp @@ -198,6 +198,7 @@ namespace ZL { { if (stoneMapFB == nullptr) { + //stoneMapFB = std::make_unique(512, 512, true); stoneMapFB = std::make_unique(512, 512); } stoneMapFB->Bind(); @@ -206,6 +207,8 @@ namespace ZL { stoneMapFB->Unbind(); + stoneMapFB->GenerateMipmaps(); + } //bakeStoneTexture(renderer); @@ -343,7 +346,6 @@ namespace ZL { renderer.RotateMatrix(Environment::inverseShipMatrix); renderer.TranslateMatrix(-Environment::shipPosition); - renderer.RenderUniform1f("uDistanceToPlanetSurface", dist); renderer.RenderUniform1f("uCurrentZFar", currentZFar); renderer.RenderUniform3fv("uViewPos", Environment::shipPosition.data()); diff --git a/src/render/FrameBuffer.cpp b/src/render/FrameBuffer.cpp index 1cc8462..2216fc5 100644 --- a/src/render/FrameBuffer.cpp +++ b/src/render/FrameBuffer.cpp @@ -4,24 +4,30 @@ namespace ZL { - FrameBuffer::FrameBuffer(int w, int h) : width(w), height(h) { - // 1. FBO + FrameBuffer::FrameBuffer(int w, int h, bool useMipmaps) + : width(w), height(h), useMipmaps(useMipmaps) { + glGenFramebuffers(1, &fbo); glBindFramebuffer(GL_FRAMEBUFFER, fbo); - // 2. , "" glGenTextures(1, &textureID); glBindTexture(GL_TEXTURE_2D, textureID); - // glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + + // + if (useMipmaps) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + // , "" + glGenerateMipmap(GL_TEXTURE_2D); + } + else { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - // 3. FBO glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0); - // if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) { std::cerr << "Error: Framebuffer is not complete!" << std::endl; } @@ -34,6 +40,13 @@ namespace ZL { glDeleteTextures(1, &textureID); } + void FrameBuffer::GenerateMipmaps() { + if (useMipmaps) { + glBindTexture(GL_TEXTURE_2D, textureID); + glGenerateMipmap(GL_TEXTURE_2D); + } + } + void FrameBuffer::Bind() { glBindFramebuffer(GL_FRAMEBUFFER, fbo); glViewport(0, 0, width, height); // : diff --git a/src/render/FrameBuffer.h b/src/render/FrameBuffer.h index 67afb26..051eded 100644 --- a/src/render/FrameBuffer.h +++ b/src/render/FrameBuffer.h @@ -9,17 +9,21 @@ namespace ZL { GLuint fbo = 0; GLuint textureID = 0; int width, height; + bool useMipmaps; // - public: - FrameBuffer(int w, int h); + // false + FrameBuffer(int w, int h, bool useMipmaps = false); ~FrameBuffer(); - // , VBOHolder FrameBuffer(const FrameBuffer&) = delete; FrameBuffer& operator=(const FrameBuffer&) = delete; - void Bind(); // - void Unbind(); // + void Bind(); + void Unbind(); + + // - + void GenerateMipmaps(); GLuint getTextureID() const { return textureID; } int getWidth() const { return width; } diff --git a/src/render/TextureManager.cpp b/src/render/TextureManager.cpp index 1805953..da31542 100644 --- a/src/render/TextureManager.cpp +++ b/src/render/TextureManager.cpp @@ -8,44 +8,46 @@ namespace ZL { - Texture::Texture(const TextureDataStruct& texData) - { - + Texture::Texture(const TextureDataStruct& texData) { width = texData.width; height = texData.height; glGenTextures(1, &texID); - - if (texID == 0) - { + if (texID == 0) { throw std::runtime_error("glGenTextures did not work"); } glBindTexture(GL_TEXTURE_2D, texID); - CheckGlError(); + // + if (texData.mipmap == TextureDataStruct::GENERATE) { + // + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); + } + else { + // ( ) + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + } + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); - glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); + CheckGlError(); + + // (Level 0) + GLint format = (texData.bitSize == TextureDataStruct::BS_24BIT) ? GL_RGB : GL_RGBA; + + glTexImage2D(GL_TEXTURE_2D, 0, format, + static_cast(width), + static_cast(height), + 0, format, GL_UNSIGNED_BYTE, texData.data.data()); CheckGlError(); - //This should be only for Windows - //glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE); - - CheckGlError(); - - if (texData.bitSize == TextureDataStruct::BS_24BIT) - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast(texData.width), static_cast(texData.height), 0, GL_RGB, GL_UNSIGNED_BYTE, &texData.data[0]); + // -, + if (texData.mipmap == TextureDataStruct::GENERATE) { + glGenerateMipmap(GL_TEXTURE_2D); + CheckGlError(); } - else - { - glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast(texData.width), static_cast(texData.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, &texData.data[0]); - } - - CheckGlError(); - } Texture::Texture(const std::array& texDataArray) diff --git a/src/render/TextureManager.h b/src/render/TextureManager.h index 2386b2e..e5ea9c1 100644 --- a/src/render/TextureManager.h +++ b/src/render/TextureManager.h @@ -10,19 +10,25 @@ namespace ZL { - struct TextureDataStruct - { + struct TextureDataStruct { size_t width; size_t height; std::vector data; + enum BitSize { BS_24BIT, BS_32BIT }; - BitSize bitSize; - }; + // - + enum MipmapType { + NONE, // - (GL_LINEAR) + GENERATE // (GL_LINEAR_MIPMAP_LINEAR) + }; + BitSize bitSize; + MipmapType mipmap = GENERATE; // + }; class Texture { size_t width = 0;