summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2016-05-11 05:00:40 +0200
committerbunnei <bunneidev@gmail.com>2016-05-11 05:00:40 +0200
commit86ecbdfa4de5654fb1f3e998921af8db1d5373cf (patch)
treea1fa859a3e2a8183eb7b3d367c41aa91a747b39f /src/video_core/renderer_opengl
parentMerge pull request #1774 from lioncash/warn (diff)
parentOpenGL: Implement W-Buffers and fix depth-mapping (diff)
downloadyuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar.gz
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar.bz2
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar.lz
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar.xz
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.tar.zst
yuzu-86ecbdfa4de5654fb1f3e998921af8db1d5373cf.zip
Diffstat (limited to 'src/video_core/renderer_opengl')
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.cpp13
-rw-r--r--src/video_core/renderer_opengl/gl_rasterizer.h5
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp11
3 files changed, 24 insertions, 5 deletions
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.cpp b/src/video_core/renderer_opengl/gl_rasterizer.cpp
index 0b471dfd2..d1d9beccb 100644
--- a/src/video_core/renderer_opengl/gl_rasterizer.cpp
+++ b/src/video_core/renderer_opengl/gl_rasterizer.cpp
@@ -256,10 +256,15 @@ void RasterizerOpenGL::NotifyPicaRegisterChanged(u32 id) {
// Depth modifiers
case PICA_REG_INDEX(viewport_depth_range):
- case PICA_REG_INDEX(viewport_depth_far_plane):
+ case PICA_REG_INDEX(viewport_depth_near_plane):
SyncDepthModifiers();
break;
+ // Depth buffering
+ case PICA_REG_INDEX(depthmap_enable):
+ shader_dirty = true;
+ break;
+
// Blending
case PICA_REG_INDEX(output_merger.alphablend_enable):
SyncBlendEnabled();
@@ -910,10 +915,10 @@ void RasterizerOpenGL::SyncCullMode() {
}
void RasterizerOpenGL::SyncDepthModifiers() {
- float depth_scale = -Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_range).ToFloat32();
- float depth_offset = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_far_plane).ToFloat32() / 2.0f;
+ float depth_scale = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_range).ToFloat32();
+ float depth_offset = Pica::float24::FromRaw(Pica::g_state.regs.viewport_depth_near_plane).ToFloat32();
- // TODO: Implement scale modifier
+ uniform_block_data.data.depth_scale = depth_scale;
uniform_block_data.data.depth_offset = depth_offset;
uniform_block_data.dirty = true;
}
diff --git a/src/video_core/renderer_opengl/gl_rasterizer.h b/src/video_core/renderer_opengl/gl_rasterizer.h
index 5afcf296d..b9315ed33 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 {
const auto& regs = Pica::g_state.regs;
+ state.depthmap_enable = regs.depthmap_enable;
+
state.alpha_test_func = regs.output_merger.alpha_test.enable ?
regs.output_merger.alpha_test.func.Value() : Pica::Regs::CompareFunc::Always;
@@ -171,6 +173,8 @@ union PicaShaderConfig {
std::array<TevStageConfigRaw, 6> tev_stages;
u8 combiner_buffer_input;
+ Pica::Regs::DepthBuffering depthmap_enable;
+
struct {
struct {
unsigned num;
@@ -315,6 +319,7 @@ private:
GLvec4 const_color[6];
GLvec4 tev_combiner_buffer_color;
GLint alphatest_ref;
+ GLfloat depth_scale;
GLfloat depth_offset;
alignas(16) GLvec3 lighting_global_ambient;
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 {
vec4 const_color[NUM_TEV_STAGES];
vec4 tev_combiner_buffer_color;
int alphatest_ref;
+ float depth_scale;
float depth_offset;
vec3 lighting_global_ambient;
LightSrc light_src[NUM_LIGHTS];
@@ -581,7 +582,15 @@ vec4 secondary_fragment_color = vec4(0.0);
}
out += "color = last_tex_env_out;\n";
- out += "gl_FragDepth = gl_FragCoord.z + depth_offset;\n}";
+
+ out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n";
+ out += "float depth = z_over_w * depth_scale + depth_offset;\n";
+ if (state.depthmap_enable == Pica::Regs::DepthBuffering::WBuffering) {
+ out += "depth /= gl_FragCoord.w;\n";
+ }
+ out += "gl_FragDepth = depth;\n";
+
+ out += "}";
return out;
}