Added mipmapping partially
This commit is contained in:
parent
34fee1005a
commit
6961152d34
@ -30,7 +30,7 @@ void main() {
|
|||||||
vec3 normal = normalize(fragmentDir); // На планете-сфере нормаль совпадает с направлением от центра
|
vec3 normal = normalize(fragmentDir); // На планете-сфере нормаль совпадает с направлением от центра
|
||||||
|
|
||||||
float diff = max(dot(normal, lightToSource), 0.0);
|
float diff = max(dot(normal, lightToSource), 0.0);
|
||||||
float ambient = 0.15; // Базовая освещенность ночной стороны
|
float ambient = 0.3; // Базовая освещенность ночной стороны
|
||||||
float surfaceLightIntensity = diff + ambient;
|
float surfaceLightIntensity = diff + ambient;
|
||||||
|
|
||||||
// --- 2. Динамический цвет тумана ---
|
// --- 2. Динамический цвет тумана ---
|
||||||
|
|||||||
@ -30,7 +30,7 @@ void main()
|
|||||||
|
|
||||||
// Применяем shadowMask к диффузной составляющей
|
// Применяем shadowMask к диффузной составляющей
|
||||||
// Если точка на планете в тени, то прямой свет (diff) обнуляется
|
// Если точка на планете в тени, то прямой свет (diff) обнуляется
|
||||||
float ambient = 0.15;
|
float ambient = 0.3;
|
||||||
float lightIntensity = (diff * shadowMask);
|
float lightIntensity = (diff * shadowMask);
|
||||||
|
|
||||||
lightIntensity *= mix(0.2, 1.0, shadowMask);
|
lightIntensity *= mix(0.2, 1.0, shadowMask);
|
||||||
|
|||||||
@ -206,6 +206,12 @@ namespace ZL
|
|||||||
spaceshipTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/DefaultMaterial_BaseColor_shine.png", CONST_ZIP_FILE));
|
spaceshipTexture = std::make_unique<Texture>(CreateTextureDataFromPng("./resources/DefaultMaterial_BaseColor_shine.png", CONST_ZIP_FILE));
|
||||||
spaceshipBase = LoadFromTextFile02("./resources/spaceship006.txt", 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());
|
spaceshipBase.RotateByMatrix(Eigen::Quaternionf(Eigen::AngleAxisf(M_PI / 2.0, Eigen::Vector3f::UnitY())).toRotationMatrix());// QuatFromRotateAroundY(M_PI / 2.0).toRotationMatrix());
|
||||||
|
|
||||||
|
//spaceshipTexture = std::make_unique<Texture>(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, -13, 0 });
|
||||||
//spaceshipBase.Move(Vector3f{ -0.52998, -10, 10 });
|
//spaceshipBase.Move(Vector3f{ -0.52998, -10, 10 });
|
||||||
|
|
||||||
|
|||||||
@ -198,6 +198,7 @@ namespace ZL {
|
|||||||
{
|
{
|
||||||
if (stoneMapFB == nullptr)
|
if (stoneMapFB == nullptr)
|
||||||
{
|
{
|
||||||
|
//stoneMapFB = std::make_unique<FrameBuffer>(512, 512, true);
|
||||||
stoneMapFB = std::make_unique<FrameBuffer>(512, 512);
|
stoneMapFB = std::make_unique<FrameBuffer>(512, 512);
|
||||||
}
|
}
|
||||||
stoneMapFB->Bind();
|
stoneMapFB->Bind();
|
||||||
@ -206,6 +207,8 @@ namespace ZL {
|
|||||||
|
|
||||||
stoneMapFB->Unbind();
|
stoneMapFB->Unbind();
|
||||||
|
|
||||||
|
stoneMapFB->GenerateMipmaps();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//bakeStoneTexture(renderer);
|
//bakeStoneTexture(renderer);
|
||||||
@ -343,7 +346,6 @@ namespace ZL {
|
|||||||
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
renderer.RotateMatrix(Environment::inverseShipMatrix);
|
||||||
renderer.TranslateMatrix(-Environment::shipPosition);
|
renderer.TranslateMatrix(-Environment::shipPosition);
|
||||||
|
|
||||||
|
|
||||||
renderer.RenderUniform1f("uDistanceToPlanetSurface", dist);
|
renderer.RenderUniform1f("uDistanceToPlanetSurface", dist);
|
||||||
renderer.RenderUniform1f("uCurrentZFar", currentZFar);
|
renderer.RenderUniform1f("uCurrentZFar", currentZFar);
|
||||||
renderer.RenderUniform3fv("uViewPos", Environment::shipPosition.data());
|
renderer.RenderUniform3fv("uViewPos", Environment::shipPosition.data());
|
||||||
|
|||||||
@ -4,24 +4,30 @@
|
|||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
FrameBuffer::FrameBuffer(int w, int h) : width(w), height(h) {
|
FrameBuffer::FrameBuffer(int w, int h, bool useMipmaps)
|
||||||
// 1. Создаем FBO
|
: width(w), height(h), useMipmaps(useMipmaps) {
|
||||||
|
|
||||||
glGenFramebuffers(1, &fbo);
|
glGenFramebuffers(1, &fbo);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
|
|
||||||
// 2. Создаем текстуру, куда будем "фотографировать"
|
|
||||||
glGenTextures(1, &textureID);
|
glGenTextures(1, &textureID);
|
||||||
glBindTexture(GL_TEXTURE_2D, textureID);
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
|
|
||||||
// Устанавливаем параметры текстуры
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
|
||||||
|
|
||||||
|
// Íàñòðàèâàåì ôèëüòðàöèþ
|
||||||
|
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_MIN_FILTER, GL_LINEAR);
|
||||||
|
}
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_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);
|
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, textureID, 0);
|
||||||
|
|
||||||
// Проверка готовности
|
|
||||||
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||||
std::cerr << "Error: Framebuffer is not complete!" << std::endl;
|
std::cerr << "Error: Framebuffer is not complete!" << std::endl;
|
||||||
}
|
}
|
||||||
@ -34,6 +40,13 @@ namespace ZL {
|
|||||||
glDeleteTextures(1, &textureID);
|
glDeleteTextures(1, &textureID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FrameBuffer::GenerateMipmaps() {
|
||||||
|
if (useMipmaps) {
|
||||||
|
glBindTexture(GL_TEXTURE_2D, textureID);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FrameBuffer::Bind() {
|
void FrameBuffer::Bind() {
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
||||||
glViewport(0, 0, width, height); // Âàæíî: óñòàíàâëèâàåì âüþïîðò ïîä ðàçìåð òåêñòóðû
|
glViewport(0, 0, width, height); // Âàæíî: óñòàíàâëèâàåì âüþïîðò ïîä ðàçìåð òåêñòóðû
|
||||||
|
|||||||
@ -9,17 +9,21 @@ namespace ZL {
|
|||||||
GLuint fbo = 0;
|
GLuint fbo = 0;
|
||||||
GLuint textureID = 0;
|
GLuint textureID = 0;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
bool useMipmaps; // Флаг использования мип-мапов
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FrameBuffer(int w, int h);
|
// Добавляем параметр в конструктор по умолчанию false
|
||||||
|
FrameBuffer(int w, int h, bool useMipmaps = false);
|
||||||
~FrameBuffer();
|
~FrameBuffer();
|
||||||
|
|
||||||
// Запрещаем копирование, как в VBOHolder
|
|
||||||
FrameBuffer(const FrameBuffer&) = delete;
|
FrameBuffer(const FrameBuffer&) = delete;
|
||||||
FrameBuffer& operator=(const FrameBuffer&) = delete;
|
FrameBuffer& operator=(const FrameBuffer&) = delete;
|
||||||
|
|
||||||
void Bind(); // Начать рендер в этот буфер
|
void Bind();
|
||||||
void Unbind(); // Вернуться к обычному рендеру в экран
|
void Unbind();
|
||||||
|
|
||||||
|
// Метод для принудительной генерации мип-мапов после рендера
|
||||||
|
void GenerateMipmaps();
|
||||||
|
|
||||||
GLuint getTextureID() const { return textureID; }
|
GLuint getTextureID() const { return textureID; }
|
||||||
int getWidth() const { return width; }
|
int getWidth() const { return width; }
|
||||||
|
|||||||
@ -8,44 +8,46 @@
|
|||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
|
|
||||||
Texture::Texture(const TextureDataStruct& texData)
|
Texture::Texture(const TextureDataStruct& texData) {
|
||||||
{
|
|
||||||
|
|
||||||
width = texData.width;
|
width = texData.width;
|
||||||
height = texData.height;
|
height = texData.height;
|
||||||
|
|
||||||
glGenTextures(1, &texID);
|
glGenTextures(1, &texID);
|
||||||
|
if (texID == 0) {
|
||||||
if (texID == 0)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("glGenTextures did not work");
|
throw std::runtime_error("glGenTextures did not work");
|
||||||
}
|
}
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, texID);
|
glBindTexture(GL_TEXTURE_2D, texID);
|
||||||
|
|
||||||
CheckGlError();
|
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_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<GLsizei>(width),
|
||||||
|
static_cast<GLsizei>(height),
|
||||||
|
0, format, GL_UNSIGNED_BYTE, texData.data.data());
|
||||||
|
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
//This should be only for Windows
|
// Ãåíåðàöèÿ ìèï-ìàïîâ, åñëè ýòî íåîáõîäèìî
|
||||||
//glTexParameteri(GL_TEXTURE_2D, GL_GENERATE_MIPMAP, GL_TRUE);
|
if (texData.mipmap == TextureDataStruct::GENERATE) {
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
CheckGlError();
|
CheckGlError();
|
||||||
|
|
||||||
if (texData.bitSize == TextureDataStruct::BS_24BIT)
|
|
||||||
{
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, static_cast<GLsizei>(texData.width), static_cast<GLsizei>(texData.height), 0, GL_RGB, GL_UNSIGNED_BYTE, &texData.data[0]);
|
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, static_cast<GLsizei>(texData.width), static_cast<GLsizei>(texData.height), 0, GL_RGBA, GL_UNSIGNED_BYTE, &texData.data[0]);
|
|
||||||
}
|
|
||||||
|
|
||||||
CheckGlError();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture::Texture(const std::array<TextureDataStruct, 6>& texDataArray)
|
Texture::Texture(const std::array<TextureDataStruct, 6>& texDataArray)
|
||||||
|
|||||||
@ -10,19 +10,25 @@
|
|||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
|
|
||||||
struct TextureDataStruct
|
struct TextureDataStruct {
|
||||||
{
|
|
||||||
size_t width;
|
size_t width;
|
||||||
size_t height;
|
size_t height;
|
||||||
std::vector<char> data;
|
std::vector<char> data;
|
||||||
|
|
||||||
enum BitSize {
|
enum BitSize {
|
||||||
BS_24BIT,
|
BS_24BIT,
|
||||||
BS_32BIT
|
BS_32BIT
|
||||||
};
|
};
|
||||||
|
|
||||||
BitSize bitSize;
|
// Новое перечисление для управления мип-маппингом
|
||||||
|
enum MipmapType {
|
||||||
|
NONE, // Без мип-мапов (GL_LINEAR)
|
||||||
|
GENERATE // Автоматическая генерация (GL_LINEAR_MIPMAP_LINEAR)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
BitSize bitSize;
|
||||||
|
MipmapType mipmap = GENERATE; // По умолчанию включено
|
||||||
|
};
|
||||||
class Texture
|
class Texture
|
||||||
{
|
{
|
||||||
size_t width = 0;
|
size_t width = 0;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user