diff options
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.cpp | 11 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_rasterizer.h | 5 | ||||
| -rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 11 |
3 files changed, 23 insertions, 4 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp index 5fc885961..d1d9beccb 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.cpp +++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp | |||
| @@ -260,6 +260,11 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) { | |||
| 260 | SyncDepthModifiers(); | 260 | SyncDepthModifiers(); |
| 261 | break; | 261 | break; |
| 262 | 262 | ||
| 263 | // Depth buffering | ||
| 264 | case PICA_REG_INDEX(depthmap_enable): | ||
| 265 | shader_dirty = true; | ||
| 266 | break; | ||
| 267 | |||
| 263 | // Blending | 268 | // Blending |
| 264 | case PICA_REG_INDEX(output_merger.alphablend_enable): | 269 | case PICA_REG_INDEX(output_merger.alphablend_enable): |
| 265 | SyncBlendEnabled(); | 270 | SyncBlendEnabled(); |
| @@ -910,10 +915,10 @@ void RasterizerOpenGL::SyncCullMode() { | |||
| 910 | } | 915 | } |
| 911 | 916 | ||
| 912 | void RasterizerOpenGL::SyncDepthModifiers() { | 917 | void RasterizerOpenGL::SyncDepthModifiers() { |
| 913 | float depth_scale = -Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_range).ToFloat32(); | 918 | float depth_scale = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_range).ToFloat32(); |
| 914 | float depth_offset = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_near_plane).ToFloat32() / 2.0f; | 919 | float depth_offset = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_near_plane).ToFloat32(); |
| 915 | 920 | ||
| 916 | // TODO: Implement scale modifier | 921 | uniform_block_data.data.depth_scale = depth_scale; |
| 917 | uniform_block_data.data.depth_offset = depth_offset; | 922 | uniform_block_data.data.depth_offset = depth_offset; |
| 918 | uniform_block_data.dirty = true; | 923 | uniform_block_data.dirty = true; |
| 919 | } | 924 | } |
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h index 4f9a032fb..6fdb7f61b 100644 --- a/src/video_core/renderer_opengl/gl_rasterizer.h +++ b/src/video_core/renderer_opengl/gl_rasterizer.h | |||
| @@ -56,6 +56,8 @@ union PicaShaderConfig { | |||
| 56 | 56 | ||
| 57 | const auto& regs = Pica::g_state.regs; | 57 | const auto& regs = Pica::g_state.regs; |
| 58 | 58 | ||
| 59 | state.depthmap_enable = regs.depthmap_enable; | ||
| 60 | |||
| 59 | state.alpha_test_func = regs.output_merger.alpha_test.enable ? | 61 | state.alpha_test_func = regs.output_merger.alpha_test.enable ? |
| 60 | regs.output_merger.alpha_test.func.Value() : Pica::Regs::CompareFunc::Always; | 62 | regs.output_merger.alpha_test.func.Value() : Pica::Regs::CompareFunc::Always; |
| 61 | 63 | ||
| @@ -171,6 +173,8 @@ union PicaShaderConfig { | |||
| 171 | std::array<TevStageConfigRaw, 6> tev_stages; | 173 | std::array<TevStageConfigRaw, 6> tev_stages; |
| 172 | u8 combiner_buffer_input; | 174 | u8 combiner_buffer_input; |
| 173 | 175 | ||
| 176 | Pica::Regs::DepthBuffering depthmap_enable; | ||
| 177 | |||
| 174 | struct { | 178 | struct { |
| 175 | struct { | 179 | struct { |
| 176 | unsigned num; | 180 | unsigned num; |
| @@ -315,6 +319,7 @@ private: | |||
| 315 | GLvec4 const_color[6]; | 319 | GLvec4 const_color[6]; |
| 316 | GLvec4 tev_combiner_buffer_color; | 320 | GLvec4 tev_combiner_buffer_color; |
| 317 | GLint alphatest_ref; | 321 | GLint alphatest_ref; |
| 322 | GLfloat depth_scale; | ||
| 318 | GLfloat depth_offset; | 323 | GLfloat depth_offset; |
| 319 | alignas(16) GLvec3 lighting_global_ambient; | 324 | alignas(16) GLvec3 lighting_global_ambient; |
| 320 | LightSrc light_src[8]; | 325 | LightSrc light_src[8]; |
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index 0890adb12..0c3153e8f 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp | |||
| @@ -540,6 +540,7 @@ layout (std140) uniform shader_data { | |||
| 540 | vec4 const_color[NUM_TEV_STAGES]; | 540 | vec4 const_color[NUM_TEV_STAGES]; |
| 541 | vec4 tev_combiner_buffer_color; | 541 | vec4 tev_combiner_buffer_color; |
| 542 | int alphatest_ref; | 542 | int alphatest_ref; |
| 543 | float depth_scale; | ||
| 543 | float depth_offset; | 544 | float depth_offset; |
| 544 | vec3 lighting_global_ambient; | 545 | vec3 lighting_global_ambient; |
| 545 | LightSrc light_src[NUM_LIGHTS]; | 546 | LightSrc light_src[NUM_LIGHTS]; |
| @@ -581,7 +582,15 @@ vec4 secondary_fragment_color = vec4(0.0); | |||
| 581 | } | 582 | } |
| 582 | 583 | ||
| 583 | out += "color = last_tex_env_out;\n"; | 584 | out += "color = last_tex_env_out;\n"; |
| 584 | out += "gl_FragDepth = gl_FragCoord.z + depth_offset;\n}"; | 585 | |
| 586 | out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n"; | ||
| 587 | out += "float depth = z_over_w * depth_scale + depth_offset;\n"; | ||
| 588 | if (state.depthmap_enable == Pica::Regs::DepthBuffering::WBuffering) { | ||
| 589 | out += "depth /= gl_FragCoord.w;\n"; | ||
| 590 | } | ||
| 591 | out += "gl_FragDepth = depth;\n"; | ||
| 592 | |||
| 593 | out += "}"; | ||
| 585 | 594 | ||
| 586 | return out; | 595 | return out; |
| 587 | } | 596 | } |