diff options
| author | 2016-05-26 17:35:12 -0400 | |
|---|---|---|
| committer | 2016-05-26 17:35:12 -0400 | |
| commit | 201a7af92a0076b53f7ddf8953d97e4c50d65fb4 (patch) | |
| tree | 7290768d035e211986e2e01d92cb330c2b41a488 /src | |
| parent | Merge pull request #1855 from MerryMage/memory-headers-20160526 (diff) | |
| parent | OpenGL: Set shader_dirty on lighting changes (diff) | |
| download | yuzu-201a7af92a0076b53f7ddf8953d97e4c50d65fb4.tar.gz yuzu-201a7af92a0076b53f7ddf8953d97e4c50d65fb4.tar.xz yuzu-201a7af92a0076b53f7ddf8953d97e4c50d65fb4.zip | |
Merge pull request #1846 from JayFoxRox/missing-dirty-lighting
OpenGL: Set shader_dirty on lighting changes
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/pica.h | 40 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 95 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 42 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 6 |
4 files changed, 140 insertions, 43 deletions
diff --git a/src/video_core/pica.h b/src/video_core/pica.h index 86c0a0096..544ea037f 100644 --- a/src/video_core/pica.h +++ b/src/video_core/pica.h | |||
| @@ -787,23 +787,21 @@ struct Regs { | |||
| 787 | LightColor diffuse; // material.diffuse * light.diffuse | 787 | LightColor diffuse; // material.diffuse * light.diffuse |
| 788 | LightColor ambient; // material.ambient * light.ambient | 788 | LightColor ambient; // material.ambient * light.ambient |
| 789 | 789 | ||
| 790 | struct { | 790 | // Encoded as 16-bit floating point |
| 791 | // Encoded as 16-bit floating point | 791 | union { |
| 792 | union { | 792 | BitField< 0, 16, u32> x; |
| 793 | BitField< 0, 16, u32> x; | 793 | BitField<16, 16, u32> y; |
| 794 | BitField<16, 16, u32> y; | 794 | }; |
| 795 | }; | 795 | union { |
| 796 | union { | 796 | BitField< 0, 16, u32> z; |
| 797 | BitField< 0, 16, u32> z; | 797 | }; |
| 798 | }; | ||
| 799 | 798 | ||
| 800 | INSERT_PADDING_WORDS(0x3); | 799 | INSERT_PADDING_WORDS(0x3); |
| 801 | 800 | ||
| 802 | union { | 801 | union { |
| 803 | BitField<0, 1, u32> directional; | 802 | BitField<0, 1, u32> directional; |
| 804 | BitField<1, 1, u32> two_sided_diffuse; // When disabled, clamp dot-product to 0 | 803 | BitField<1, 1, u32> two_sided_diffuse; // When disabled, clamp dot-product to 0 |
| 805 | }; | 804 | } config; |
| 806 | }; | ||
| 807 | 805 | ||
| 808 | BitField<0, 20, u32> dist_atten_bias; | 806 | BitField<0, 20, u32> dist_atten_bias; |
| 809 | BitField<0, 20, u32> dist_atten_scale; | 807 | BitField<0, 20, u32> dist_atten_scale; |
| @@ -824,7 +822,7 @@ struct Regs { | |||
| 824 | BitField<27, 1, u32> clamp_highlights; | 822 | BitField<27, 1, u32> clamp_highlights; |
| 825 | BitField<28, 2, LightingBumpMode> bump_mode; | 823 | BitField<28, 2, LightingBumpMode> bump_mode; |
| 826 | BitField<30, 1, u32> disable_bump_renorm; | 824 | BitField<30, 1, u32> disable_bump_renorm; |
| 827 | }; | 825 | } config0; |
| 828 | 826 | ||
| 829 | union { | 827 | union { |
| 830 | BitField<16, 1, u32> disable_lut_d0; | 828 | BitField<16, 1, u32> disable_lut_d0; |
| @@ -845,13 +843,13 @@ struct Regs { | |||
| 845 | BitField<29, 1, u32> disable_dist_atten_light_5; | 843 | BitField<29, 1, u32> disable_dist_atten_light_5; |
| 846 | BitField<30, 1, u32> disable_dist_atten_light_6; | 844 | BitField<30, 1, u32> disable_dist_atten_light_6; |
| 847 | BitField<31, 1, u32> disable_dist_atten_light_7; | 845 | BitField<31, 1, u32> disable_dist_atten_light_7; |
| 848 | }; | 846 | } config1; |
| 849 | 847 | ||
| 850 | bool IsDistAttenDisabled(unsigned index) const { | 848 | bool IsDistAttenDisabled(unsigned index) const { |
| 851 | const unsigned disable[] = { disable_dist_atten_light_0, disable_dist_atten_light_1, | 849 | const unsigned disable[] = { config1.disable_dist_atten_light_0, config1.disable_dist_atten_light_1, |
| 852 | disable_dist_atten_light_2, disable_dist_atten_light_3, | 850 | config1.disable_dist_atten_light_2, config1.disable_dist_atten_light_3, |
| 853 | disable_dist_atten_light_4, disable_dist_atten_light_5, | 851 | config1.disable_dist_atten_light_4, config1.disable_dist_atten_light_5, |
| 854 | disable_dist_atten_light_6, disable_dist_atten_light_7 }; | 852 | config1.disable_dist_atten_light_6, config1.disable_dist_atten_light_7 }; |
| 855 | return disable[index] != 0; | 853 | return disable[index] != 0; |
| 856 | } | 854 | } |
| 857 | 855 | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index bcd1ae78d..931c34a37 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -380,6 +380,17 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 380 | SyncCombinerColor(); | 380 | SyncCombinerColor(); |
| 381 | break; | 381 | break; |
| 382 | 382 | ||
| 383 | // Fragment lighting switches | ||
| 384 | case PICA_REG_INDEX(lighting.disable): | ||
| 385 | case PICA_REG_INDEX(lighting.num_lights): | ||
| 386 | case PICA_REG_INDEX(lighting.config0): | ||
| 387 | case PICA_REG_INDEX(lighting.config1): | ||
| 388 | case PICA_REG_INDEX(lighting.abs_lut_input): | ||
| 389 | case PICA_REG_INDEX(lighting.lut_input): | ||
| 390 | case PICA_REG_INDEX(lighting.lut_scale): | ||
| 391 | case PICA_REG_INDEX(lighting.light_enable): | ||
| 392 | break; | ||
| 393 | |||
| 383 | // Fragment lighting specular 0 color | 394 | // Fragment lighting specular 0 color |
| 384 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].specular_0, 0x140 + 0 * 0x10): | 395 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].specular_0, 0x140 + 0 * 0x10): |
| 385 | SyncLightSpecular0(0); | 396 | SyncLightSpecular0(0); |
| @@ -518,6 +529,70 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 518 | SyncLightPosition(7); | 529 | SyncLightPosition(7); |
| 519 | break; | 530 | break; |
| 520 | 531 | ||
| 532 | // Fragment lighting light source config | ||
| 533 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].config, 0x149 + 0 * 0x10): | ||
| 534 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].config, 0x149 + 1 * 0x10): | ||
| 535 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].config, 0x149 + 2 * 0x10): | ||
| 536 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].config, 0x149 + 3 * 0x10): | ||
| 537 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].config, 0x149 + 4 * 0x10): | ||
| 538 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].config, 0x149 + 5 * 0x10): | ||
| 539 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].config, 0x149 + 6 * 0x10): | ||
| 540 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].config, 0x149 + 7 * 0x10): | ||
| 541 | shader_dirty = true; | ||
| 542 | break; | ||
| 543 | |||
| 544 | // Fragment lighting distance attenuation bias | ||
| 545 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_bias, 0x014A + 0 * 0x10): | ||
| 546 | SyncLightDistanceAttenuationBias(0); | ||
| 547 | break; | ||
| 548 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_bias, 0x014A + 1 * 0x10): | ||
| 549 | SyncLightDistanceAttenuationBias(1); | ||
| 550 | break; | ||
| 551 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_bias, 0x014A + 2 * 0x10): | ||
| 552 | SyncLightDistanceAttenuationBias(2); | ||
| 553 | break; | ||
| 554 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_bias, 0x014A + 3 * 0x10): | ||
| 555 | SyncLightDistanceAttenuationBias(3); | ||
| 556 | break; | ||
| 557 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_bias, 0x014A + 4 * 0x10): | ||
| 558 | SyncLightDistanceAttenuationBias(4); | ||
| 559 | break; | ||
| 560 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_bias, 0x014A + 5 * 0x10): | ||
| 561 | SyncLightDistanceAttenuationBias(5); | ||
| 562 | break; | ||
| 563 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_bias, 0x014A + 6 * 0x10): | ||
| 564 | SyncLightDistanceAttenuationBias(6); | ||
| 565 | break; | ||
| 566 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_bias, 0x014A + 7 * 0x10): | ||
| 567 | SyncLightDistanceAttenuationBias(7); | ||
| 568 | break; | ||
| 569 | |||
| 570 | // Fragment lighting distance attenuation scale | ||
| 571 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].dist_atten_scale, 0x014B + 0 * 0x10): | ||
| 572 | SyncLightDistanceAttenuationScale(0); | ||
| 573 | break; | ||
| 574 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].dist_atten_scale, 0x014B + 1 * 0x10): | ||
| 575 | SyncLightDistanceAttenuationScale(1); | ||
| 576 | break; | ||
| 577 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].dist_atten_scale, 0x014B + 2 * 0x10): | ||
| 578 | SyncLightDistanceAttenuationScale(2); | ||
| 579 | break; | ||
| 580 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].dist_atten_scale, 0x014B + 3 * 0x10): | ||
| 581 | SyncLightDistanceAttenuationScale(3); | ||
| 582 | break; | ||
| 583 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].dist_atten_scale, 0x014B + 4 * 0x10): | ||
| 584 | SyncLightDistanceAttenuationScale(4); | ||
| 585 | break; | ||
| 586 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].dist_atten_scale, 0x014B + 5 * 0x10): | ||
| 587 | SyncLightDistanceAttenuationScale(5); | ||
| 588 | break; | ||
| 589 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].dist_atten_scale, 0x014B + 6 * 0x10): | ||
| 590 | SyncLightDistanceAttenuationScale(6); | ||
| 591 | break; | ||
| 592 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].dist_atten_scale, 0x014B + 7 * 0x10): | ||
| 593 | SyncLightDistanceAttenuationScale(7); | ||
| 594 | break; | ||
| 595 | |||
| 521 | // Fragment lighting global ambient color (emission + ambient * ambient) | 596 | // Fragment lighting global ambient color (emission + ambient * ambient) |
| 522 | case PICA_REG_INDEX_WORKAROUND(lighting.global_ambient, 0x1c0): | 597 | case PICA_REG_INDEX_WORKAROUND(lighting.global_ambient, 0x1c0): |
| 523 | SyncGlobalAmbient(); | 598 | SyncGlobalAmbient(); |
| @@ -896,6 +971,8 @@ void RasterizerOpenGL::SetShader() { | |||
| 896 | SyncLightDiffuse(light_index); | 971 | SyncLightDiffuse(light_index); |
| 897 | SyncLightAmbient(light_index); | 972 | SyncLightAmbient(light_index); |
| 898 | SyncLightPosition(light_index); | 973 | SyncLightPosition(light_index); |
| 974 | SyncLightDistanceAttenuationBias(light_index); | ||
| 975 | SyncLightDistanceAttenuationScale(light_index); | ||
| 899 | } | 976 | } |
| 900 | } | 977 | } |
| 901 | } | 978 | } |
| @@ -1105,3 +1182,21 @@ void RasterizerOpenGL::SyncLightPosition(int light_index) { | |||
| 1105 | uniform_block_data.dirty = true; | 1182 | uniform_block_data.dirty = true; |
| 1106 | } | 1183 | } |
| 1107 | } | 1184 | } |
| 1185 | |||
| 1186 | void RasterizerOpenGL::SyncLightDistanceAttenuationBias(int light_index) { | ||
| 1187 | GLfloat dist_atten_bias = Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_bias).ToFloat32(); | ||
| 1188 | |||
| 1189 | if (dist_atten_bias != uniform_block_data.data.light_src[light_index].dist_atten_bias) { | ||
| 1190 | uniform_block_data.data.light_src[light_index].dist_atten_bias = dist_atten_bias; | ||
| 1191 | uniform_block_data.dirty = true; | ||
| 1192 | } | ||
| 1193 | } | ||
| 1194 | |||
| 1195 | void RasterizerOpenGL::SyncLightDistanceAttenuationScale(int light_index) { | ||
| 1196 | GLfloat dist_atten_scale = Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_scale).ToFloat32(); | ||
| 1197 | |||
| 1198 | if (dist_atten_scale != uniform_block_data.data.light_src[light_index].dist_atten_scale) { | ||
| 1199 | uniform_block_data.data.light_src[light_index].dist_atten_scale = dist_atten_scale; | ||
| 1200 | uniform_block_data.dirty = true; | ||
| 1201 | } | ||
| 1202 | } | ||
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index d70369400..bb7f20161 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -89,49 +89,47 @@ union PicaShaderConfig { | |||
| 89 | unsigned num = regs.lighting.light_enable.GetNum(light_index); | 89 | unsigned num = regs.lighting.light_enable.GetNum(light_index); |
| 90 | const auto& light = regs.lighting.light[num]; | 90 | const auto& light = regs.lighting.light[num]; |
| 91 | state.lighting.light[light_index].num = num; | 91 | state.lighting.light[light_index].num = num; |
| 92 | state.lighting.light[light_index].directional = light.directional != 0; | 92 | state.lighting.light[light_index].directional = light.config.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.config.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.config1.disable_lut_d0 == 0; |
| 100 | state.lighting.lut_d0.abs_input = regs.lighting.abs_lut_input.disable_d0 == 0; | 98 | state.lighting.lut_d0.abs_input = regs.lighting.abs_lut_input.disable_d0 == 0; |
| 101 | state.lighting.lut_d0.type = regs.lighting.lut_input.d0.Value(); | 99 | state.lighting.lut_d0.type = regs.lighting.lut_input.d0.Value(); |
| 102 | state.lighting.lut_d0.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d0); | 100 | state.lighting.lut_d0.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d0); |
| 103 | 101 | ||
| 104 | state.lighting.lut_d1.enable = regs.lighting.disable_lut_d1 == 0; | 102 | state.lighting.lut_d1.enable = regs.lighting.config1.disable_lut_d1 == 0; |
| 105 | state.lighting.lut_d1.abs_input = regs.lighting.abs_lut_input.disable_d1 == 0; | 103 | state.lighting.lut_d1.abs_input = regs.lighting.abs_lut_input.disable_d1 == 0; |
| 106 | state.lighting.lut_d1.type = regs.lighting.lut_input.d1.Value(); | 104 | state.lighting.lut_d1.type = regs.lighting.lut_input.d1.Value(); |
| 107 | state.lighting.lut_d1.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d1); | 105 | state.lighting.lut_d1.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d1); |
| 108 | 106 | ||
| 109 | state.lighting.lut_fr.enable = regs.lighting.disable_lut_fr == 0; | 107 | state.lighting.lut_fr.enable = regs.lighting.config1.disable_lut_fr == 0; |
| 110 | state.lighting.lut_fr.abs_input = regs.lighting.abs_lut_input.disable_fr == 0; | 108 | state.lighting.lut_fr.abs_input = regs.lighting.abs_lut_input.disable_fr == 0; |
| 111 | state.lighting.lut_fr.type = regs.lighting.lut_input.fr.Value(); | 109 | state.lighting.lut_fr.type = regs.lighting.lut_input.fr.Value(); |
| 112 | state.lighting.lut_fr.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.fr); | 110 | state.lighting.lut_fr.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.fr); |
| 113 | 111 | ||
| 114 | state.lighting.lut_rr.enable = regs.lighting.disable_lut_rr == 0; | 112 | state.lighting.lut_rr.enable = regs.lighting.config1.disable_lut_rr == 0; |
| 115 | state.lighting.lut_rr.abs_input = regs.lighting.abs_lut_input.disable_rr == 0; | 113 | state.lighting.lut_rr.abs_input = regs.lighting.abs_lut_input.disable_rr == 0; |
| 116 | state.lighting.lut_rr.type = regs.lighting.lut_input.rr.Value(); | 114 | state.lighting.lut_rr.type = regs.lighting.lut_input.rr.Value(); |
| 117 | state.lighting.lut_rr.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rr); | 115 | state.lighting.lut_rr.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rr); |
| 118 | 116 | ||
| 119 | state.lighting.lut_rg.enable = regs.lighting.disable_lut_rg == 0; | 117 | state.lighting.lut_rg.enable = regs.lighting.config1.disable_lut_rg == 0; |
| 120 | state.lighting.lut_rg.abs_input = regs.lighting.abs_lut_input.disable_rg == 0; | 118 | state.lighting.lut_rg.abs_input = regs.lighting.abs_lut_input.disable_rg == 0; |
| 121 | state.lighting.lut_rg.type = regs.lighting.lut_input.rg.Value(); | 119 | state.lighting.lut_rg.type = regs.lighting.lut_input.rg.Value(); |
| 122 | state.lighting.lut_rg.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rg); | 120 | state.lighting.lut_rg.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rg); |
| 123 | 121 | ||
| 124 | state.lighting.lut_rb.enable = regs.lighting.disable_lut_rb == 0; | 122 | state.lighting.lut_rb.enable = regs.lighting.config1.disable_lut_rb == 0; |
| 125 | state.lighting.lut_rb.abs_input = regs.lighting.abs_lut_input.disable_rb == 0; | 123 | state.lighting.lut_rb.abs_input = regs.lighting.abs_lut_input.disable_rb == 0; |
| 126 | state.lighting.lut_rb.type = regs.lighting.lut_input.rb.Value(); | 124 | state.lighting.lut_rb.type = regs.lighting.lut_input.rb.Value(); |
| 127 | state.lighting.lut_rb.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rb); | 125 | state.lighting.lut_rb.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.rb); |
| 128 | 126 | ||
| 129 | state.lighting.config = regs.lighting.config; | 127 | state.lighting.config = regs.lighting.config0.config; |
| 130 | state.lighting.fresnel_selector = regs.lighting.fresnel_selector; | 128 | state.lighting.fresnel_selector = regs.lighting.config0.fresnel_selector; |
| 131 | state.lighting.bump_mode = regs.lighting.bump_mode; | 129 | state.lighting.bump_mode = regs.lighting.config0.bump_mode; |
| 132 | state.lighting.bump_selector = regs.lighting.bump_selector; | 130 | state.lighting.bump_selector = regs.lighting.config0.bump_selector; |
| 133 | state.lighting.bump_renorm = regs.lighting.disable_bump_renorm == 0; | 131 | state.lighting.bump_renorm = regs.lighting.config0.disable_bump_renorm == 0; |
| 134 | state.lighting.clamp_highlights = regs.lighting.clamp_highlights != 0; | 132 | state.lighting.clamp_highlights = regs.lighting.config0.clamp_highlights != 0; |
| 135 | 133 | ||
| 136 | return res; | 134 | return res; |
| 137 | } | 135 | } |
| @@ -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 { |