Added mipmapping partially
This commit is contained in:
parent
34fee1005a
commit
6961152d34
@ -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. Динамический цвет тумана ---
|
||||
|
||||
@ -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);
|
||||
|
||||
@ -206,6 +206,12 @@ namespace ZL
|
||||
spaceshipTexture = std::make_unique<Texture>(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<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, -10, 10 });
|
||||
|
||||
|
||||
@ -198,6 +198,7 @@ namespace ZL {
|
||||
{
|
||||
if (stoneMapFB == nullptr)
|
||||
{
|
||||
//stoneMapFB = std::make_unique<FrameBuffer>(512, 512, true);
|
||||
stoneMapFB = std::make_unique<FrameBuffer>(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());
|
||||
|
||||
@ -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); // Âàæíî: óñòàíàâëèâàåì âüþïîðò ïîä ðàçìåð òåêñòóðû
|
||||
|
||||
@ -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; }
|
||||
|
||||
@ -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<GLsizei>(width),
|
||||
static_cast<GLsizei>(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<GLsizei>(texData.width), static_cast<GLsizei>(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<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)
|
||||
|
||||
@ -10,19 +10,25 @@
|
||||
namespace ZL
|
||||
{
|
||||
|
||||
struct TextureDataStruct
|
||||
{
|
||||
struct TextureDataStruct {
|
||||
size_t width;
|
||||
size_t height;
|
||||
std::vector<char> 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;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user