diff options
| author | 2016-05-23 22:53:53 +0200 | |
|---|---|---|
| committer | 2016-05-23 23:28:13 +0200 | |
| commit | 068bd6f7286e551ac13853dea5a28377b3d286d9 (patch) | |
| tree | 8e722ea5fb84f32a2e80a4224cb828183c8881b1 /src | |
| parent | Merge pull request #1837 from wwylele/sync-trap (diff) | |
| download | yuzu-068bd6f7286e551ac13853dea5a28377b3d286d9.tar.gz yuzu-068bd6f7286e551ac13853dea5a28377b3d286d9.tar.xz yuzu-068bd6f7286e551ac13853dea5a28377b3d286d9.zip | |
OpenGL: Use uniforms for dist_atten_bias and dist_atten_scale
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 72 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 14 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 6 |
3 files changed, 84 insertions, 8 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index bcd1ae78d..a2a314c6b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -518,6 +518,58 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 518 | SyncLightPosition(7); | 518 | SyncLightPosition(7); |
| 519 | break; | 519 | break; |
| 520 | 520 | ||
| 521 | // Fragment lighting distance attenuation bias | ||
| 522 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_bias, 0x014A + 0 * 0x10): | ||
| 523 | SyncLightDistanceAttenuationBias(0); | ||
| 524 | break; | ||
| 525 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_bias, 0x014A + 1 * 0x10): | ||
| 526 | SyncLightDistanceAttenuationBias(1); | ||
| 527 | break; | ||
| 528 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_bias, 0x014A + 2 * 0x10): | ||
| 529 | SyncLightDistanceAttenuationBias(2); | ||
| 530 | break; | ||
| 531 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_bias, 0x014A + 3 * 0x10): | ||
| 532 | SyncLightDistanceAttenuationBias(3); | ||
| 533 | break; | ||
| 534 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_bias, 0x014A + 4 * 0x10): | ||
| 535 | SyncLightDistanceAttenuationBias(4); | ||
| 536 | break; | ||
| 537 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_bias, 0x014A + 5 * 0x10): | ||
| 538 | SyncLightDistanceAttenuationBias(5); | ||
| 539 | break; | ||
| 540 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_bias, 0x014A + 6 * 0x10): | ||
| 541 | SyncLightDistanceAttenuationBias(6); | ||
| 542 | break; | ||
| 543 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_bias, 0x014A + 7 * 0x10): | ||
| 544 | SyncLightDistanceAttenuationBias(7); | ||
| 545 | break; | ||
| 546 | |||
| 547 | // Fragment lighting distance attenuation scale | ||
| 548 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_scale, 0x014B + 0 * 0x10): | ||
| 549 | SyncLightDistanceAttenuationScale(0); | ||
| 550 | break; | ||
| 551 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_scale, 0x014B + 1 * 0x10): | ||
| 552 | SyncLightDistanceAttenuationScale(1); | ||
| 553 | break; | ||
| 554 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_scale, 0x014B + 2 * 0x10): | ||
| 555 | SyncLightDistanceAttenuationScale(2); | ||
| 556 | break; | ||
| 557 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_scale, 0x014B + 3 * 0x10): | ||
| 558 | SyncLightDistanceAttenuationScale(3); | ||
| 559 | break; | ||
| 560 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_scale, 0x014B + 4 * 0x10): | ||
| 561 | SyncLightDistanceAttenuationScale(4); | ||
| 562 | break; | ||
| 563 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_scale, 0x014B + 5 * 0x10): | ||
| 564 | SyncLightDistanceAttenuationScale(5); | ||
| 565 | break; | ||
| 566 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_scale, 0x014B + 6 * 0x10): | ||
| 567 | SyncLightDistanceAttenuationScale(6); | ||
| 568 | break; | ||
| 569 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_scale, 0x014B + 7 * 0x10): | ||
| 570 | SyncLightDistanceAttenuationScale(7); | ||
| 571 | break; | ||
| 572 | |||
| 521 | // Fragment lighting global ambient color (emission + ambient * ambient) | 573 | // Fragment lighting global ambient color (emission + ambient * ambient) |
| 522 | case PICA_REG_INDEX_WORKAROUND(lighting.global_ambient, 0x1c0): | 574 | case PICA_REG_INDEX_WORKAROUND(lighting.global_ambient, 0x1c0): |
| 523 | SyncGlobalAmbient(); | 575 | SyncGlobalAmbient(); |
| @@ -896,6 +948,8 @@ void RasterizerOpenGL::SetShader() { | |||
| 896 | SyncLightDiffuse(light_index); | 948 | SyncLightDiffuse(light_index); |
| 897 | SyncLightAmbient(light_index); | 949 | SyncLightAmbient(light_index); |
| 898 | SyncLightPosition(light_index); | 950 | SyncLightPosition(light_index); |
| 951 | SyncLightDistanceAttenuationBias(light_index); | ||
| 952 | SyncLightDistanceAttenuationScale(light_index); | ||
| 899 | } | 953 | } |
| 900 | } | 954 | } |
| 901 | } | 955 | } |
| @@ -1105,3 +1159,21 @@ void RasterizerOpenGL::SyncLightPosition(int light_index) { | |||
| 1105 | uniform_block_data.dirty = true; | 1159 | uniform_block_data.dirty = true; |
| 1106 | } | 1160 | } |
| 1107 | } | 1161 | } |
| 1162 | |||
| 1163 | void RasterizerOpenGL::SyncLightDistanceAttenuationBias(int light_index) { | ||
| 1164 | GLfloat dist_atten_bias = Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_bias).ToFloat32(); | ||
| 1165 | |||
| 1166 | if (dist_atten_bias != uniform_block_data.data.light_src[light_index].dist_atten_bias) { | ||
| 1167 | uniform_block_data.data.light_src[light_index].dist_atten_bias = dist_atten_bias; | ||
| 1168 | uniform_block_data.dirty = true; | ||
| 1169 | } | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | void RasterizerOpenGL::SyncLightDistanceAttenuationScale(int light_index) { | ||
| 1173 | GLfloat dist_atten_scale = Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_scale).ToFloat32(); | ||
| 1174 | |||
| 1175 | if (dist_atten_scale != uniform_block_data.data.light_src[light_index].dist_atten_scale) { | ||
| 1176 | uniform_block_data.data.light_src[light_index].dist_atten_scale = dist_atten_scale; | ||
| 1177 | uniform_block_data.dirty = true; | ||
| 1178 | } | ||
| 1179 | } | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index d70369400..052aad139 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -92,8 +92,6 @@ union PicaShaderConfig { | |||
| 92 | state.lighting.light[light_index].directional = light.directional != 0; | 92 | state.lighting.light[light_index].directional = light.directional != 0; |
| 93 | state.lighting.light[light_index].two_sided_diffuse = light.two_sided_diffuse != 0; | 93 | state.lighting.light[light_index].two_sided_diffuse = light.two_sided_diffuse != 0; |
| 94 | state.lighting.light[light_index].dist_atten_enable = !regs.lighting.IsDistAttenDisabled(num); | 94 | state.lighting.light[light_index].dist_atten_enable = !regs.lighting.IsDistAttenDisabled(num); |
| 95 | state.lighting.light[light_index].dist_atten_bias = Pica::float20::FromRaw(light.dist_atten_bias).ToFloat32(); | ||
| 96 | state.lighting.light[light_index].dist_atten_scale = Pica::float20::FromRaw(light.dist_atten_scale).ToFloat32(); | ||
| 97 | } | 95 | } |
| 98 | 96 | ||
| 99 | state.lighting.lut_d0.enable = regs.lighting.disable_lut_d0 == 0; | 97 | state.lighting.lut_d0.enable = regs.lighting.disable_lut_d0 == 0; |
| @@ -184,8 +182,6 @@ union PicaShaderConfig { | |||
| 184 | bool directional; | 182 | bool directional; |
| 185 | bool two_sided_diffuse; | 183 | bool two_sided_diffuse; |
| 186 | bool dist_atten_enable; | 184 | bool dist_atten_enable; |
| 187 | GLfloat dist_atten_scale; | ||
| 188 | GLfloat dist_atten_bias; | ||
| 189 | } light[8]; | 185 | } light[8]; |
| 190 | 186 | ||
| 191 | bool enable; | 187 | bool enable; |
| @@ -316,6 +312,8 @@ private: | |||
| 316 | alignas(16) GLvec3 diffuse; | 312 | alignas(16) GLvec3 diffuse; |
| 317 | alignas(16) GLvec3 ambient; | 313 | alignas(16) GLvec3 ambient; |
| 318 | alignas(16) GLvec3 position; | 314 | alignas(16) GLvec3 position; |
| 315 | GLfloat dist_atten_bias; | ||
| 316 | GLfloat dist_atten_scale; | ||
| 319 | }; | 317 | }; |
| 320 | 318 | ||
| 321 | /// Uniform structure for the Uniform Buffer Object, all members must be 16-byte aligned | 319 | /// Uniform structure for the Uniform Buffer Object, all members must be 16-byte aligned |
| @@ -330,7 +328,7 @@ private: | |||
| 330 | LightSrc light_src[8]; | 328 | LightSrc light_src[8]; |
| 331 | }; | 329 | }; |
| 332 | 330 | ||
| 333 | static_assert(sizeof(UniformData) == 0x310, "The size of the UniformData structure has changed, update the structure in the shader"); | 331 | static_assert(sizeof(UniformData) == 0x390, "The size of the UniformData structure has changed, update the structure in the shader"); |
| 334 | static_assert(sizeof(UniformData) < 16384, "UniformData structure must be less than 16kb as per the OpenGL spec"); | 332 | static_assert(sizeof(UniformData) < 16384, "UniformData structure must be less than 16kb as per the OpenGL spec"); |
| 335 | 333 | ||
| 336 | /// Sets the OpenGL shader in accordance with the current PICA register state | 334 | /// Sets the OpenGL shader in accordance with the current PICA register state |
| @@ -402,6 +400,12 @@ private: | |||
| 402 | /// Syncs the specified light's position to match the PICA register | 400 | /// Syncs the specified light's position to match the PICA register |
| 403 | void SyncLightPosition(int light_index); | 401 | void SyncLightPosition(int light_index); |
| 404 | 402 | ||
| 403 | /// Syncs the specified light's distance attenuation bias to match the PICA register | ||
| 404 | void SyncLightDistanceAttenuationBias(int light_index); | ||
| 405 | |||
| 406 | /// Syncs the specified light's distance attenuation scale to match the PICA register | ||
| 407 | void SyncLightDistanceAttenuationScale(int light_index); | ||
| 408 | |||
| 405 | OpenGLState state; | 409 | OpenGLState state; |
| 406 | 410 | ||
| 407 | RasterizerCacheOpenGL res_cache; | 411 | RasterizerCacheOpenGL res_cache; |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 71d60e69c..8332e722d 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -439,9 +439,7 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) { | |||
| 439 | // If enabled, compute distance attenuation value | 439 | // If enabled, compute distance attenuation value |
| 440 | std::string dist_atten = "1.0"; | 440 | std::string dist_atten = "1.0"; |
| 441 | if (light_config.dist_atten_enable) { | 441 | if (light_config.dist_atten_enable) { |
| 442 | std::string scale = std::to_string(light_config.dist_atten_scale); | 442 | std::string index = "(" + light_src + ".dist_atten_scale * length(-view - " + light_src + ".position) + " + light_src + ".dist_atten_bias)"; |
| 443 | std::string bias = std::to_string(light_config.dist_atten_bias); | ||
| 444 | std::string index = "(" + scale + " * length(-view - " + light_src + ".position) + " + bias + ")"; | ||
| 445 | index = "((clamp(" + index + ", 0.0, FLOAT_255)))"; | 443 | index = "((clamp(" + index + ", 0.0, FLOAT_255)))"; |
| 446 | const unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); | 444 | const unsigned lut_num = ((unsigned)Regs::LightingSampler::DistanceAttenuation + light_config.num); |
| 447 | dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index); | 445 | dist_atten = GetLutValue((Regs::LightingSampler)lut_num, index); |
| @@ -549,6 +547,8 @@ struct LightSrc { | |||
| 549 | vec3 diffuse; | 547 | vec3 diffuse; |
| 550 | vec3 ambient; | 548 | vec3 ambient; |
| 551 | vec3 position; | 549 | vec3 position; |
| 550 | float dist_atten_bias; | ||
| 551 | float dist_atten_scale; | ||
| 552 | }; | 552 | }; |
| 553 | 553 | ||
| 554 | layout (std140) uniform shader_data { | 554 | layout (std140) uniform shader_data { |