mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-06 14:15:41 +12:00
Switch to GL_TEXTURE_2D for lighting LUT
This commit is contained in:
parent
1b071b62fa
commit
a3886a948f
3 changed files with 15 additions and 16 deletions
|
@ -53,7 +53,7 @@ class RendererGL final : public Renderer {
|
|||
OpenGL::VertexBuffer dummyVBO;
|
||||
|
||||
OpenGL::Texture screenTexture;
|
||||
GLuint lightLUTTextureArray;
|
||||
OpenGL::Texture lightLUTTexture;
|
||||
OpenGL::Framebuffer screenFramebuffer;
|
||||
OpenGL::Texture blankTexture;
|
||||
|
||||
|
|
|
@ -124,7 +124,10 @@ void RendererGL::initGraphicsContextInternal() {
|
|||
const u32 screenTextureWidth = 400; // Top screen is 400 pixels wide, bottom is 320
|
||||
const u32 screenTextureHeight = 2 * 240; // Both screens are 240 pixels tall
|
||||
|
||||
glGenTextures(1, &lightLUTTextureArray);
|
||||
lightLUTTexture.create(256, Lights::LUT_Count, GL_R32F);
|
||||
lightLUTTexture.bind();
|
||||
lightLUTTexture.setMinFilter(OpenGL::Linear);
|
||||
lightLUTTexture.setMagFilter(OpenGL::Linear);
|
||||
|
||||
auto prevTexture = OpenGL::getTex2D();
|
||||
|
||||
|
@ -357,26 +360,22 @@ void RendererGL::bindTexturesToSlots() {
|
|||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glBindTexture(GL_TEXTURE_1D_ARRAY, lightLUTTextureArray);
|
||||
lightLUTTexture.bind();
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
void RendererGL::updateLightingLUT() {
|
||||
gpu.lightingLUTDirty = false;
|
||||
std::array<u16, GPU::LightingLutSize> u16_lightinglut;
|
||||
std::array<float, GPU::LightingLutSize> lightingLut;
|
||||
|
||||
for (int i = 0; i < gpu.lightingLUT.size(); i++) {
|
||||
uint64_t value = gpu.lightingLUT[i] & ((1 << 12) - 1);
|
||||
u16_lightinglut[i] = value * 65535 / 4095;
|
||||
uint64_t value = gpu.lightingLUT[i] & 0xFFF;
|
||||
lightingLut[i] = (float)(value << 4) / 65535.0f;
|
||||
}
|
||||
|
||||
glActiveTexture(GL_TEXTURE0 + 3);
|
||||
glBindTexture(GL_TEXTURE_1D_ARRAY, lightLUTTextureArray);
|
||||
glTexImage2D(GL_TEXTURE_1D_ARRAY, 0, GL_R16, 256, Lights::LUT_Count, 0, GL_RED, GL_UNSIGNED_SHORT, u16_lightinglut.data());
|
||||
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_1D_ARRAY, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
lightLUTTexture.bind();
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 256, Lights::LUT_Count, GL_RED, GL_FLOAT, lightingLut.data());
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ uniform bool u_depthmapEnable;
|
|||
uniform sampler2D u_tex0;
|
||||
uniform sampler2D u_tex1;
|
||||
uniform sampler2D u_tex2;
|
||||
uniform sampler1DArray u_tex_lighting_lut;
|
||||
uniform sampler2D u_tex_lighting_lut;
|
||||
|
||||
uniform uint u_picaRegs[0x200 - 0x48];
|
||||
|
||||
|
@ -145,9 +145,9 @@ vec4 tevCalculateCombiner(int tev_id) {
|
|||
#define RR_LUT 6u
|
||||
|
||||
float lutLookup(uint lut, uint light, float value) {
|
||||
if (lut >= FR_LUT && lut <= RR_LUT) lut -= 1;
|
||||
if (lut == SP_LUT) lut = light + 8;
|
||||
return texture(u_tex_lighting_lut, vec2(value, lut)).r;
|
||||
if (lut >= FR_LUT && lut <= RR_LUT) lut -= 1u;
|
||||
if (lut == SP_LUT) lut = light + 8u;
|
||||
return texelFetch(u_tex_lighting_lut, ivec2(int(value * 256.0), lut), 0).r;
|
||||
}
|
||||
|
||||
vec3 regToColor(uint reg) {
|
||||
|
|
Loading…
Add table
Reference in a new issue