use another method to load BRDF LUT texture
This commit is contained in:
@ -18,6 +18,7 @@ namespace Prism
|
|||||||
case TextureFormat::RGB: return GL_RGB;
|
case TextureFormat::RGB: return GL_RGB;
|
||||||
case TextureFormat::RGBA: return GL_RGBA;
|
case TextureFormat::RGBA: return GL_RGBA;
|
||||||
case TextureFormat::RGBA16F: return GL_RGBA16F;
|
case TextureFormat::RGBA16F: return GL_RGBA16F;
|
||||||
|
case TextureFormat::RG8: return GL_RG8;
|
||||||
case TextureFormat::RG16F: return GL_RG16F;
|
case TextureFormat::RG16F: return GL_RG16F;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
@ -28,6 +29,7 @@ namespace Prism
|
|||||||
case TextureFormat::RGB: return GL_RGB8;
|
case TextureFormat::RGB: return GL_RGB8;
|
||||||
case TextureFormat::RGBA: return GL_RGBA8;
|
case TextureFormat::RGBA: return GL_RGBA8;
|
||||||
case TextureFormat::RGBA16F: return GL_RGBA16F;
|
case TextureFormat::RGBA16F: return GL_RGBA16F;
|
||||||
|
case TextureFormat::RG8: return GL_RG8;
|
||||||
case TextureFormat::RG16F: return GL_RG16F;
|
case TextureFormat::RG16F: return GL_RG16F;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
@ -38,6 +40,7 @@ namespace Prism
|
|||||||
case TextureFormat::RGB: return GL_RGB;
|
case TextureFormat::RGB: return GL_RGB;
|
||||||
case TextureFormat::RGBA: return GL_RGBA;
|
case TextureFormat::RGBA: return GL_RGBA;
|
||||||
case TextureFormat::RGBA16F: return GL_RGBA;
|
case TextureFormat::RGBA16F: return GL_RGBA;
|
||||||
|
case TextureFormat::RG8: return GL_RG;
|
||||||
case TextureFormat::RG16F: return GL_RG;
|
case TextureFormat::RG16F: return GL_RG;
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
@ -137,47 +140,6 @@ namespace Prism
|
|||||||
OpenGLTexture2D::OpenGLTexture2D(const std::string& path, bool srgb, bool isLUT)
|
OpenGLTexture2D::OpenGLTexture2D(const std::string& path, bool srgb, bool isLUT)
|
||||||
: m_FilePath(path)
|
: m_FilePath(path)
|
||||||
{
|
{
|
||||||
|
|
||||||
if (isLUT)
|
|
||||||
{
|
|
||||||
int width, height, channels;
|
|
||||||
float* data = stbi_loadf(path.c_str(), &width, &height, &channels, 2);
|
|
||||||
if (!data)
|
|
||||||
{
|
|
||||||
PM_CORE_ERROR("Failed to load BRDF LUT: {0}", path);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
m_Loaded = true;
|
|
||||||
m_Width = width;
|
|
||||||
m_Height = height;
|
|
||||||
m_Format = TextureFormat::RG16F;
|
|
||||||
m_IsHDR = true;
|
|
||||||
m_ImageData.Data = (byte*)data;
|
|
||||||
|
|
||||||
Ref<OpenGLTexture2D> instance = this;
|
|
||||||
Renderer::Submit([instance, width, height]() mutable
|
|
||||||
{
|
|
||||||
glCreateTextures(GL_TEXTURE_2D, 1, &instance->m_RendererID);
|
|
||||||
|
|
||||||
// 内部格式:双通道 16 位浮点
|
|
||||||
glTextureStorage2D(instance->m_RendererID, 1, GL_RG16F, width, height);
|
|
||||||
|
|
||||||
// 包裹模式必须为 CLAMP_TO_EDGE,防止 LUT 边缘插值错误
|
|
||||||
glTextureParameteri(instance->m_RendererID, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
||||||
glTextureParameteri(instance->m_RendererID, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
||||||
|
|
||||||
// LUT 不需要 mipmap,使用线性过滤即可
|
|
||||||
glTextureParameteri(instance->m_RendererID, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
||||||
glTextureParameteri(instance->m_RendererID, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
||||||
|
|
||||||
// 上传数据:紧密排列的 RG 浮点数组
|
|
||||||
glTextureSubImage2D(instance->m_RendererID, 0, 0, 0,
|
|
||||||
width, height, GL_RG, GL_FLOAT, instance->m_ImageData.Data);
|
|
||||||
|
|
||||||
stbi_image_free(instance->m_ImageData.Data);
|
|
||||||
});
|
|
||||||
}else
|
|
||||||
{
|
{
|
||||||
int width, height, channels;
|
int width, height, channels;
|
||||||
if (stbi_is_hdr(path.c_str()))
|
if (stbi_is_hdr(path.c_str()))
|
||||||
@ -203,7 +165,7 @@ namespace Prism
|
|||||||
m_Height = height;
|
m_Height = height;
|
||||||
|
|
||||||
Ref<OpenGLTexture2D> instance = this;
|
Ref<OpenGLTexture2D> instance = this;
|
||||||
Renderer::Submit([instance, srgb]() mutable {
|
Renderer::Submit([instance, srgb, isLUT]() mutable {
|
||||||
// TODO: Consolidate properly
|
// TODO: Consolidate properly
|
||||||
if (srgb)
|
if (srgb)
|
||||||
{
|
{
|
||||||
@ -221,20 +183,32 @@ namespace Prism
|
|||||||
glGenTextures(1, &instance->m_RendererID);
|
glGenTextures(1, &instance->m_RendererID);
|
||||||
glBindTexture(GL_TEXTURE_2D, instance->m_RendererID);
|
glBindTexture(GL_TEXTURE_2D, instance->m_RendererID);
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
|
||||||
|
if (isLUT)
|
||||||
|
{
|
||||||
|
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_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
const GLint wrap = instance->m_Wrap == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
const GLint wrap = instance->m_Wrap == TextureWrap::Clamp ? GL_CLAMP_TO_EDGE : GL_REPEAT;
|
||||||
|
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, wrap);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, wrap);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, wrap);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_R, wrap);
|
||||||
|
}
|
||||||
|
|
||||||
GLenum internalFormat = PrismToOpenGLTextureFormat(instance->m_Format);
|
GLenum internalFormat = PrismToOpenGLTextureFormat(instance->m_Format);
|
||||||
GLenum format = srgb ? GL_SRGB8 : (instance->m_IsHDR ? GL_RGB : PrismToOpenGLTextureFormat(instance->m_Format)); // HDR = GL_RGB for now
|
GLenum format = srgb ? GL_SRGB8 : (instance->m_IsHDR ? GL_RGB : PrismToOpenGLTextureFormat(instance->m_Format)); // HDR = GL_RGB for now
|
||||||
GLenum type = internalFormat == GL_RGBA16F ? GL_FLOAT : GL_UNSIGNED_BYTE;
|
GLenum type = internalFormat == GL_RGBA16F ? GL_FLOAT : GL_UNSIGNED_BYTE;
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, (GLint)internalFormat, (GLint)instance->m_Width, (GLint)instance->m_Height, 0, format, type, instance->m_ImageData.Data);
|
glTexImage2D(GL_TEXTURE_2D, 0, (GLint)internalFormat, (GLint)instance->m_Width, (GLint)instance->m_Height, 0, format, type, instance->m_ImageData.Data);
|
||||||
|
|
||||||
|
if (!isLUT)
|
||||||
glGenerateMipmap(GL_TEXTURE_2D);
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
|||||||
@ -19,7 +19,8 @@ namespace Prism
|
|||||||
RGB = 1,
|
RGB = 1,
|
||||||
RGBA = 2,
|
RGBA = 2,
|
||||||
RGBA16F = 3,
|
RGBA16F = 3,
|
||||||
RG16F = 4,
|
RG8 = 4,
|
||||||
|
RG16F = 5,
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class TextureWrap
|
enum class TextureWrap
|
||||||
|
|||||||
Reference in New Issue
Block a user