diff options
| author | 2017-05-25 20:15:12 +0300 | |
|---|---|---|
| committer | 2017-05-30 10:54:58 +0300 | |
| commit | 686cbf3ac6503755337dd683bf22dfaa07b21c67 (patch) | |
| tree | 0d8ea8a1ae4f1d90f057b1b1219b96c2cd0e0c69 /src | |
| parent | pica: prepare registers for spotlight (diff) | |
| download | yuzu-686cbf3ac6503755337dd683bf22dfaa07b21c67.tar.gz yuzu-686cbf3ac6503755337dd683bf22dfaa07b21c67.tar.xz yuzu-686cbf3ac6503755337dd683bf22dfaa07b21c67.zip | |
gl_rasterizer: sync spot light status
Diffstat (limited to 'src')
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 45 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 6 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 9 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.h | 3 |
4 files changed, 61 insertions, 2 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index aa9b831dd..57d5e8253 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -735,6 +735,40 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 735 | SyncLightPosition(7); | 735 | SyncLightPosition(7); |
| 736 | break; | 736 | break; |
| 737 | 737 | ||
| 738 | // Fragment spot lighting direction | ||
| 739 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].spot_x, 0x146 + 0 * 0x10): | ||
| 740 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].spot_z, 0x147 + 0 * 0x10): | ||
| 741 | SyncLightSpotDirection(0); | ||
| 742 | break; | ||
| 743 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].spot_x, 0x146 + 1 * 0x10): | ||
| 744 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].spot_z, 0x147 + 1 * 0x10): | ||
| 745 | SyncLightSpotDirection(1); | ||
| 746 | break; | ||
| 747 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].spot_x, 0x146 + 2 * 0x10): | ||
| 748 | case PICA_REG_INDEX_WORKAROUND(lighting.light[2].spot_z, 0x147 + 2 * 0x10): | ||
| 749 | SyncLightSpotDirection(2); | ||
| 750 | break; | ||
| 751 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].spot_x, 0x146 + 3 * 0x10): | ||
| 752 | case PICA_REG_INDEX_WORKAROUND(lighting.light[3].spot_z, 0x147 + 3 * 0x10): | ||
| 753 | SyncLightSpotDirection(3); | ||
| 754 | break; | ||
| 755 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].spot_x, 0x146 + 4 * 0x10): | ||
| 756 | case PICA_REG_INDEX_WORKAROUND(lighting.light[4].spot_z, 0x147 + 4 * 0x10): | ||
| 757 | SyncLightSpotDirection(4); | ||
| 758 | break; | ||
| 759 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].spot_x, 0x146 + 5 * 0x10): | ||
| 760 | case PICA_REG_INDEX_WORKAROUND(lighting.light[5].spot_z, 0x147 + 5 * 0x10): | ||
| 761 | SyncLightSpotDirection(5); | ||
| 762 | break; | ||
| 763 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].spot_x, 0x146 + 6 * 0x10): | ||
| 764 | case PICA_REG_INDEX_WORKAROUND(lighting.light[6].spot_z, 0x147 + 6 * 0x10): | ||
| 765 | SyncLightSpotDirection(6); | ||
| 766 | break; | ||
| 767 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].spot_x, 0x146 + 7 * 0x10): | ||
| 768 | case PICA_REG_INDEX_WORKAROUND(lighting.light[7].spot_z, 0x147 + 7 * 0x10): | ||
| 769 | SyncLightSpotDirection(7); | ||
| 770 | break; | ||
| 771 | |||
| 738 | // Fragment lighting light source config | 772 | // Fragment lighting light source config |
| 739 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].config, 0x149 + 0 * 0x10): | 773 | case PICA_REG_INDEX_WORKAROUND(lighting.light[0].config, 0x149 + 0 * 0x10): |
| 740 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].config, 0x149 + 1 * 0x10): | 774 | case PICA_REG_INDEX_WORKAROUND(lighting.light[1].config, 0x149 + 1 * 0x10): |
| @@ -1595,6 +1629,17 @@ void RasterizerOpenGL::SyncLightPosition(int light_index) { | |||
| 1595 | } | 1629 | } |
| 1596 | } | 1630 | } |
| 1597 | 1631 | ||
| 1632 | void RasterizerOpenGL::SyncLightSpotDirection(int light_index) { | ||
| 1633 | const auto& light = Pica::g_state.regs.lighting.light[light_index]; | ||
| 1634 | GLvec3 spot_direction = {light.spot_x / 2047.0f, light.spot_y / 2047.0f, | ||
| 1635 | light.spot_z / 2047.0f}; | ||
| 1636 | |||
| 1637 | if (spot_direction != uniform_block_data.data.light_src[light_index].spot_direction) { | ||
| 1638 | uniform_block_data.data.light_src[light_index].spot_direction = spot_direction; | ||
| 1639 | uniform_block_data.dirty = true; | ||
| 1640 | } | ||
| 1641 | } | ||
| 1642 | |||
| 1598 | void RasterizerOpenGL::SyncLightDistanceAttenuationBias(int light_index) { | 1643 | void RasterizerOpenGL::SyncLightDistanceAttenuationBias(int light_index) { |
| 1599 | GLfloat dist_atten_bias = | 1644 | GLfloat dist_atten_bias = |
| 1600 | Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_bias) | 1645 | Pica::float20::FromRaw(Pica::g_state.regs.lighting.light[light_index].dist_atten_bias) |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index a9ad7d660..d9a3e9d1c 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -125,6 +125,7 @@ private: | |||
| 125 | alignas(16) GLvec3 diffuse; | 125 | alignas(16) GLvec3 diffuse; |
| 126 | alignas(16) GLvec3 ambient; | 126 | alignas(16) GLvec3 ambient; |
| 127 | alignas(16) GLvec3 position; | 127 | alignas(16) GLvec3 position; |
| 128 | alignas(16) GLvec3 spot_direction; // negated | ||
| 128 | GLfloat dist_atten_bias; | 129 | GLfloat dist_atten_bias; |
| 129 | GLfloat dist_atten_scale; | 130 | GLfloat dist_atten_scale; |
| 130 | }; | 131 | }; |
| @@ -153,7 +154,7 @@ private: | |||
| 153 | }; | 154 | }; |
| 154 | 155 | ||
| 155 | static_assert( | 156 | static_assert( |
| 156 | sizeof(UniformData) == 0x3E0, | 157 | sizeof(UniformData) == 0x460, |
| 157 | "The size of the UniformData structure has changed, update the structure in the shader"); | 158 | "The size of the UniformData structure has changed, update the structure in the shader"); |
| 158 | static_assert(sizeof(UniformData) < 16384, | 159 | static_assert(sizeof(UniformData) < 16384, |
| 159 | "UniformData structure must be less than 16kb as per the OpenGL spec"); | 160 | "UniformData structure must be less than 16kb as per the OpenGL spec"); |
| @@ -241,6 +242,9 @@ private: | |||
| 241 | /// Syncs the specified light's position to match the PICA register | 242 | /// Syncs the specified light's position to match the PICA register |
| 242 | void SyncLightPosition(int light_index); | 243 | void SyncLightPosition(int light_index); |
| 243 | 244 | ||
| 245 | /// Syncs the specified spot light direcition to match the PICA register | ||
| 246 | void SyncLightSpotDirection(int light_index); | ||
| 247 | |||
| 244 | /// Syncs the specified light's distance attenuation bias to match the PICA register | 248 | /// Syncs the specified light's distance attenuation bias to match the PICA register |
| 245 | void SyncLightDistanceAttenuationBias(int light_index); | 249 | void SyncLightDistanceAttenuationBias(int light_index); |
| 246 | 250 | ||
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 600119321..fe23be340 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -75,6 +75,8 @@ PicaShaderConfig PicaShaderConfig::BuildFromRegs(const Pica::Regs& regs) { | |||
| 75 | state.lighting.light[light_index].two_sided_diffuse = light.config.two_sided_diffuse != 0; | 75 | state.lighting.light[light_index].two_sided_diffuse = light.config.two_sided_diffuse != 0; |
| 76 | state.lighting.light[light_index].dist_atten_enable = | 76 | state.lighting.light[light_index].dist_atten_enable = |
| 77 | !regs.lighting.IsDistAttenDisabled(num); | 77 | !regs.lighting.IsDistAttenDisabled(num); |
| 78 | state.lighting.light[light_index].spot_atten_enable = | ||
| 79 | !regs.lighting.IsSpotAttenDisabled(num); | ||
| 78 | } | 80 | } |
| 79 | 81 | ||
| 80 | state.lighting.lut_d0.enable = regs.lighting.config1.disable_lut_d0 == 0; | 82 | state.lighting.lut_d0.enable = regs.lighting.config1.disable_lut_d0 == 0; |
| @@ -87,6 +89,12 @@ PicaShaderConfig PicaShaderConfig::BuildFromRegs(const Pica::Regs& regs) { | |||
| 87 | state.lighting.lut_d1.type = regs.lighting.lut_input.d1.Value(); | 89 | state.lighting.lut_d1.type = regs.lighting.lut_input.d1.Value(); |
| 88 | state.lighting.lut_d1.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d1); | 90 | state.lighting.lut_d1.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.d1); |
| 89 | 91 | ||
| 92 | // this is a dummy field due to lack of the corresponding register | ||
| 93 | state.lighting.lut_sp.enable = true; | ||
| 94 | state.lighting.lut_sp.abs_input = regs.lighting.abs_lut_input.disable_sp == 0; | ||
| 95 | state.lighting.lut_sp.type = regs.lighting.lut_input.sp.Value(); | ||
| 96 | state.lighting.lut_sp.scale = regs.lighting.lut_scale.GetScale(regs.lighting.lut_scale.sp); | ||
| 97 | |||
| 90 | state.lighting.lut_fr.enable = regs.lighting.config1.disable_lut_fr == 0; | 98 | state.lighting.lut_fr.enable = regs.lighting.config1.disable_lut_fr == 0; |
| 91 | state.lighting.lut_fr.abs_input = regs.lighting.abs_lut_input.disable_fr == 0; | 99 | state.lighting.lut_fr.abs_input = regs.lighting.abs_lut_input.disable_fr == 0; |
| 92 | state.lighting.lut_fr.type = regs.lighting.lut_input.fr.Value(); | 100 | state.lighting.lut_fr.type = regs.lighting.lut_input.fr.Value(); |
| @@ -968,6 +976,7 @@ struct LightSrc { | |||
| 968 | vec3 diffuse; | 976 | vec3 diffuse; |
| 969 | vec3 ambient; | 977 | vec3 ambient; |
| 970 | vec3 position; | 978 | vec3 position; |
| 979 | vec3 spot_direction; | ||
| 971 | float dist_atten_bias; | 980 | float dist_atten_bias; |
| 972 | float dist_atten_scale; | 981 | float dist_atten_scale; |
| 973 | }; | 982 | }; |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.h b/src/video_core/renderer_opengl/gl_shader_gen.h index ea6d216d1..9c90eadf9 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.h +++ b/src/video_core/renderer_opengl/gl_shader_gen.h | |||
| @@ -93,6 +93,7 @@ union PicaShaderConfig { | |||
| 93 | bool directional; | 93 | bool directional; |
| 94 | bool two_sided_diffuse; | 94 | bool two_sided_diffuse; |
| 95 | bool dist_atten_enable; | 95 | bool dist_atten_enable; |
| 96 | bool spot_atten_enable; | ||
| 96 | } light[8]; | 97 | } light[8]; |
| 97 | 98 | ||
| 98 | bool enable; | 99 | bool enable; |
| @@ -110,7 +111,7 @@ union PicaShaderConfig { | |||
| 110 | bool abs_input; | 111 | bool abs_input; |
| 111 | Pica::LightingRegs::LightingLutInput type; | 112 | Pica::LightingRegs::LightingLutInput type; |
| 112 | float scale; | 113 | float scale; |
| 113 | } lut_d0, lut_d1, lut_fr, lut_rr, lut_rg, lut_rb; | 114 | } lut_d0, lut_d1, lut_sp, lut_fr, lut_rr, lut_rg, lut_rb; |
| 114 | } lighting; | 115 | } lighting; |
| 115 | 116 | ||
| 116 | struct { | 117 | struct { |