summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/video_core/pica_state.h8
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp29
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h3
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp10
-rw-r--r--src/video_core/renderer_opengl/gl_state.cpp10
-rw-r--r--src/video_core/renderer_opengl/gl_state.h2
-rw-r--r--src/video_core/swrasterizer/rasterizer.cpp3
7 files changed, 34 insertions, 31 deletions
diff --git a/src/video_core/pica_state.h b/src/video_core/pica_state.h
index 3b00df0b3..2d23d34e6 100644
--- a/src/video_core/pica_state.h
+++ b/src/video_core/pica_state.h
@@ -111,6 +111,14 @@ struct State {
111 111
112 BitField<0, 13, s32> difference; // 1.1.11 fixed point 112 BitField<0, 13, s32> difference; // 1.1.11 fixed point
113 BitField<13, 11, u32> value; // 0.0.11 fixed point 113 BitField<13, 11, u32> value; // 0.0.11 fixed point
114
115 float ToFloat() const {
116 return static_cast<float>(value) / 2047.0f;
117 }
118
119 float DiffToFloat() const {
120 return static_cast<float>(difference) / 2047.0f;
121 }
114 }; 122 };
115 123
116 std::array<LutEntry, 128> lut; 124 std::array<LutEntry, 128> lut;
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 8b7991c04..ff3f69ba3 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -94,10 +94,10 @@ RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
94 framebuffer.Create(); 94 framebuffer.Create();
95 95
96 // Allocate and bind lighting lut textures 96 // Allocate and bind lighting lut textures
97 lighting_lut_buffer.Create(); 97 lighting_lut.Create();
98 state.lighting_lut.texture_buffer = lighting_lut.handle; 98 state.lighting_lut.texture_buffer = lighting_lut.handle;
99 state.Apply(); 99 state.Apply();
100 lighting_lut.Create(); 100 lighting_lut_buffer.Create();
101 glBindBuffer(GL_TEXTURE_BUFFER, lighting_lut_buffer.handle); 101 glBindBuffer(GL_TEXTURE_BUFFER, lighting_lut_buffer.handle);
102 glBufferData(GL_TEXTURE_BUFFER, 102 glBufferData(GL_TEXTURE_BUFFER,
103 sizeof(GLfloat) * 2 * 256 * Pica::LightingRegs::NumLightingSampler, nullptr, 103 sizeof(GLfloat) * 2 * 256 * Pica::LightingRegs::NumLightingSampler, nullptr,
@@ -106,16 +106,14 @@ RasterizerOpenGL::RasterizerOpenGL() : shader_dirty(true) {
106 glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, lighting_lut_buffer.handle); 106 glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, lighting_lut_buffer.handle);
107 107
108 // Setup the LUT for the fog 108 // Setup the LUT for the fog
109 { 109 fog_lut.Create();
110 fog_lut.Create(); 110 state.fog_lut.texture_buffer = fog_lut.handle;
111 state.fog_lut.texture_1d = fog_lut.handle;
112 }
113 state.Apply(); 111 state.Apply();
114 112 fog_lut_buffer.Create();
113 glBindBuffer(GL_TEXTURE_BUFFER, fog_lut_buffer.handle);
114 glBufferData(GL_TEXTURE_BUFFER, sizeof(GLfloat) * 2 * 128, nullptr, GL_DYNAMIC_DRAW);
115 glActiveTexture(TextureUnits::FogLUT.Enum()); 115 glActiveTexture(TextureUnits::FogLUT.Enum());
116 glTexImage1D(GL_TEXTURE_1D, 0, GL_R32UI, 128, 0, GL_RED_INTEGER, GL_UNSIGNED_INT, nullptr); 116 glTexBuffer(GL_TEXTURE_BUFFER, GL_RG32F, fog_lut_buffer.handle);
117 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
118 glTexParameteri(GL_TEXTURE_1D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
119 117
120 // Setup the noise LUT for proctex 118 // Setup the noise LUT for proctex
121 proctex_noise_lut.Create(); 119 proctex_noise_lut.Create();
@@ -1356,16 +1354,17 @@ void RasterizerOpenGL::SyncFogColor() {
1356} 1354}
1357 1355
1358void RasterizerOpenGL::SyncFogLUT() { 1356void RasterizerOpenGL::SyncFogLUT() {
1359 std::array<GLuint, 128> new_data; 1357 std::array<GLvec2, 128> new_data;
1360 1358
1361 std::transform(Pica::g_state.fog.lut.begin(), Pica::g_state.fog.lut.end(), new_data.begin(), 1359 std::transform(Pica::g_state.fog.lut.begin(), Pica::g_state.fog.lut.end(), new_data.begin(),
1362 [](const auto& entry) { return entry.raw; }); 1360 [](const auto& entry) {
1361 return GLvec2{entry.ToFloat(), entry.DiffToFloat()};
1362 });
1363 1363
1364 if (new_data != fog_lut_data) { 1364 if (new_data != fog_lut_data) {
1365 fog_lut_data = new_data; 1365 fog_lut_data = new_data;
1366 glActiveTexture(TextureUnits::FogLUT.Enum()); 1366 glBindBuffer(GL_TEXTURE_BUFFER, fog_lut_buffer.handle);
1367 glTexSubImage1D(GL_TEXTURE_1D, 0, 0, 128, GL_RED_INTEGER, GL_UNSIGNED_INT, 1367 glBufferSubData(GL_TEXTURE_BUFFER, 0, new_data.size() * sizeof(GLvec2), new_data.data());
1368 fog_lut_data.data());
1369 } 1368 }
1370} 1369}
1371 1370
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 79acd4230..a433c1d4a 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.h
+++ b/src/video_core/renderer_opengl/gl_rasterizer.h
@@ -283,8 +283,9 @@ private:
283 OGLTexture lighting_lut; 283 OGLTexture lighting_lut;
284 std::array<std::array<GLvec2, 256>, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{}; 284 std::array<std::array<GLvec2, 256>, Pica::LightingRegs::NumLightingSampler> lighting_lut_data{};
285 285
286 OGLBuffer fog_lut_buffer;
286 OGLTexture fog_lut; 287 OGLTexture fog_lut;
287 std::array<GLuint, 128> fog_lut_data{}; 288 std::array<GLvec2, 128> fog_lut_data{};
288 289
289 OGLTexture proctex_noise_lut; 290 OGLTexture proctex_noise_lut;
290 std::array<GLvec2, 128> proctex_noise_lut_data{}; 291 std::array<GLvec2, 128> proctex_noise_lut_data{};
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index 0c7c4dd5c..c93b108fb 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -1052,7 +1052,7 @@ layout (std140) uniform shader_data {
1052 1052
1053uniform sampler2D tex[3]; 1053uniform sampler2D tex[3];
1054uniform samplerBuffer lighting_lut; 1054uniform samplerBuffer lighting_lut;
1055uniform usampler1D fog_lut; 1055uniform samplerBuffer fog_lut;
1056uniform sampler1D proctex_noise_lut; 1056uniform sampler1D proctex_noise_lut;
1057uniform sampler1D proctex_color_map; 1057uniform sampler1D proctex_color_map;
1058uniform sampler1D proctex_alpha_map; 1058uniform sampler1D proctex_alpha_map;
@@ -1145,12 +1145,8 @@ vec4 secondary_fragment_color = vec4(0.0);
1145 // Generate clamped fog factor from LUT for given fog index 1145 // Generate clamped fog factor from LUT for given fog index
1146 out += "float fog_i = clamp(floor(fog_index), 0.0, 127.0);\n"; 1146 out += "float fog_i = clamp(floor(fog_index), 0.0, 127.0);\n";
1147 out += "float fog_f = fog_index - fog_i;\n"; 1147 out += "float fog_f = fog_index - fog_i;\n";
1148 out += "uint fog_lut_entry = texelFetch(fog_lut, int(fog_i), 0).r;\n"; 1148 out += "vec2 fog_lut_entry = texelFetch(fog_lut, int(fog_i)).rg;\n";
1149 out += "float fog_lut_entry_difference = float(int((fog_lut_entry & 0x1FFFU) << 19U) >> " 1149 out += "float fog_factor = fog_lut_entry.r + fog_lut_entry.g * fog_f;\n";
1150 "19);\n"; // Extract signed difference
1151 out += "float fog_lut_entry_value = float((fog_lut_entry >> 13U) & 0x7FFU);\n";
1152 out += "float fog_factor = (fog_lut_entry_value + fog_lut_entry_difference * fog_f) / "
1153 "2047.0;\n";
1154 out += "fog_factor = clamp(fog_factor, 0.0, 1.0);\n"; 1150 out += "fog_factor = clamp(fog_factor, 0.0, 1.0);\n";
1155 1151
1156 // Blend the fog 1152 // Blend the fog
diff --git a/src/video_core/renderer_opengl/gl_state.cpp b/src/video_core/renderer_opengl/gl_state.cpp
index 14e63115c..eface2dea 100644
--- a/src/video_core/renderer_opengl/gl_state.cpp
+++ b/src/video_core/renderer_opengl/gl_state.cpp
@@ -54,7 +54,7 @@ OpenGLState::OpenGLState() {
54 54
55 lighting_lut.texture_buffer = 0; 55 lighting_lut.texture_buffer = 0;
56 56
57 fog_lut.texture_1d = 0; 57 fog_lut.texture_buffer = 0;
58 58
59 proctex_lut.texture_1d = 0; 59 proctex_lut.texture_1d = 0;
60 proctex_diff_lut.texture_1d = 0; 60 proctex_diff_lut.texture_1d = 0;
@@ -198,9 +198,9 @@ void OpenGLState::Apply() const {
198 } 198 }
199 199
200 // Fog LUT 200 // Fog LUT
201 if (fog_lut.texture_1d != cur_state.fog_lut.texture_1d) { 201 if (fog_lut.texture_buffer != cur_state.fog_lut.texture_buffer) {
202 glActiveTexture(TextureUnits::FogLUT.Enum()); 202 glActiveTexture(TextureUnits::FogLUT.Enum());
203 glBindTexture(GL_TEXTURE_1D, fog_lut.texture_1d); 203 glBindTexture(GL_TEXTURE_BUFFER, fog_lut.texture_buffer);
204 } 204 }
205 205
206 // ProcTex Noise LUT 206 // ProcTex Noise LUT
@@ -272,8 +272,8 @@ void OpenGLState::ResetTexture(GLuint handle) {
272 } 272 }
273 if (cur_state.lighting_lut.texture_buffer == handle) 273 if (cur_state.lighting_lut.texture_buffer == handle)
274 cur_state.lighting_lut.texture_buffer = 0; 274 cur_state.lighting_lut.texture_buffer = 0;
275 if (cur_state.fog_lut.texture_1d == handle) 275 if (cur_state.fog_lut.texture_buffer == handle)
276 cur_state.fog_lut.texture_1d = 0; 276 cur_state.fog_lut.texture_buffer = 0;
277 if (cur_state.proctex_noise_lut.texture_1d == handle) 277 if (cur_state.proctex_noise_lut.texture_1d == handle)
278 cur_state.proctex_noise_lut.texture_1d = 0; 278 cur_state.proctex_noise_lut.texture_1d = 0;
279 if (cur_state.proctex_color_map.texture_1d == handle) 279 if (cur_state.proctex_color_map.texture_1d == handle)
diff --git a/src/video_core/renderer_opengl/gl_state.h b/src/video_core/renderer_opengl/gl_state.h
index bb0218708..1efcf0811 100644
--- a/src/video_core/renderer_opengl/gl_state.h
+++ b/src/video_core/renderer_opengl/gl_state.h
@@ -91,7 +91,7 @@ public:
91 } lighting_lut; 91 } lighting_lut;
92 92
93 struct { 93 struct {
94 GLuint texture_1d; // GL_TEXTURE_BINDING_1D 94 GLuint texture_buffer; // GL_TEXTURE_BINDING_BUFFER
95 } fog_lut; 95 } fog_lut;
96 96
97 struct { 97 struct {
diff --git a/src/video_core/swrasterizer/rasterizer.cpp b/src/video_core/swrasterizer/rasterizer.cpp
index cd7b6c39d..512e81c08 100644
--- a/src/video_core/swrasterizer/rasterizer.cpp
+++ b/src/video_core/swrasterizer/rasterizer.cpp
@@ -584,8 +584,7 @@ static void ProcessTriangleInternal(const Vertex& v0, const Vertex& v1, const Ve
584 float fog_i = MathUtil::Clamp(floorf(fog_index), 0.0f, 127.0f); 584 float fog_i = MathUtil::Clamp(floorf(fog_index), 0.0f, 127.0f);
585 float fog_f = fog_index - fog_i; 585 float fog_f = fog_index - fog_i;
586 const auto& fog_lut_entry = g_state.fog.lut[static_cast<unsigned int>(fog_i)]; 586 const auto& fog_lut_entry = g_state.fog.lut[static_cast<unsigned int>(fog_i)];
587 float fog_factor = (fog_lut_entry.value + fog_lut_entry.difference * fog_f) / 587 float fog_factor = fog_lut_entry.ToFloat() + fog_lut_entry.DiffToFloat() * fog_f;
588 2047.0f; // This is signed fixed point 1.11
589 fog_factor = MathUtil::Clamp(fog_factor, 0.0f, 1.0f); 588 fog_factor = MathUtil::Clamp(fog_factor, 0.0f, 1.0f);
590 589
591 // Blend the fog 590 // Blend the fog