diff options
author | Jannik Vogel <email@jannikvogel.de> | 2016-05-21 01:04:57 +0200 |
---|---|---|
committer | Jannik Vogel <email@jannikvogel.de> | 2016-06-07 00:06:28 +0200 |
commit | a12571c709c5af840bb89c43344bd982a496f21a (patch) | |
tree | 12af20634c98eb2bfa86aaafdf06f8f87e7f7095 /src/video_core/renderer_opengl/gl_shader_gen.cpp | |
parent | Rasterizer: Implement fog (diff) | |
download | yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar.gz yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar.bz2 yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar.lz yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar.xz yuzu-a12571c709c5af840bb89c43344bd982a496f21a.tar.zst yuzu-a12571c709c5af840bb89c43344bd982a496f21a.zip |
Diffstat (limited to '')
-rw-r--r-- | src/video_core/renderer_opengl/gl_shader_gen.cpp | 34 |
1 files changed, 29 insertions, 5 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp index ea7ab2883..3bace7f01 100644 --- a/src/video_core/renderer_opengl/gl_shader_gen.cpp +++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp @@ -555,6 +555,7 @@ layout (std140) uniform shader_data { int alphatest_ref; float depth_scale; float depth_offset; + vec3 fog_color; vec3 lighting_global_ambient; LightSrc light_src[NUM_LIGHTS]; vec4 const_color[NUM_TEV_STAGES]; @@ -563,6 +564,7 @@ layout (std140) uniform shader_data { uniform sampler2D tex[3]; uniform sampler1D lut[6]; +uniform usampler1D fog_lut; // Rotate the vector v by the quaternion q vec3 quaternion_rotate(vec4 q, vec3 v) { @@ -580,6 +582,12 @@ vec4 secondary_fragment_color = vec4(0.0); return out; } + 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"; + } + if (state.lighting.enable) WriteLighting(out, config); @@ -596,14 +604,30 @@ vec4 secondary_fragment_color = vec4(0.0); out += ") discard;\n"; } - out += "color = last_tex_env_out;\n"; + // Append fog combiner + if (state.fog_mode == Regs::FogMode::Fog) { + // Get index into fog LUT + if (state.fog_flip) { + out += "float fog_index = (1.0 - depth) * 128.0;\n"; + } else { + out += "float fog_index = depth * 128.0;\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"; + // Generate clamped fog factor from LUT for given fog index + out += "float fog_i = clamp(floor(fog_index), 0.0, 127.0);\n"; + out += "float fog_f = fog_index - fog_i;\n"; + out += "uint fog_lut_entry = texelFetch(fog_lut, int(fog_i), 0).r;\n"; + out += "float fog_lut_entry_difference = float(int((fog_lut_entry & 0x1FFFU) << 19U) >> 19);\n"; // Extract signed difference + out += "float fog_lut_entry_value = float((fog_lut_entry >> 13U) & 0x7FFU);\n"; + out += "float fog_factor = (fog_lut_entry_value + fog_lut_entry_difference * fog_f) / 2047.0;\n"; + out += "fog_factor = clamp(fog_factor, 0.0, 1.0);\n"; + + // Blend the fog + out += "last_tex_env_out.rgb = mix(fog_color.rgb, last_tex_env_out.rgb, fog_factor);\n"; } + out += "gl_FragDepth = depth;\n"; + out += "color = last_tex_env_out;\n"; out += "}"; |