summaryrefslogtreecommitdiffstats
path: root/src/video_core/renderer_opengl/gl_shader_gen.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/video_core/renderer_opengl/gl_shader_gen.cpp')
-rw-r--r--src/video_core/renderer_opengl/gl_shader_gen.cpp28
1 files changed, 20 insertions, 8 deletions
diff --git a/src/video_core/renderer_opengl/gl_shader_gen.cpp b/src/video_core/renderer_opengl/gl_shader_gen.cpp
index ae67aab05..c536e61e1 100644
--- a/src/video_core/renderer_opengl/gl_shader_gen.cpp
+++ b/src/video_core/renderer_opengl/gl_shader_gen.cpp
@@ -8,6 +8,7 @@
#include "common/assert.h"
#include "common/bit_field.h"
#include "common/logging/log.h"
+#include "core/core.h"
#include "video_core/regs_framebuffer.h"
#include "video_core/regs_lighting.h"
#include "video_core/regs_rasterizer.h"
@@ -594,8 +595,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
// Note: even if the normal vector is modified by normal map, which is not the
// normal of the tangent plane anymore, the half angle vector is still projected
// using the modified normal vector.
- std::string half_angle_proj = "normalize(half_vector) - normal / dot(normal, "
- "normal) * dot(normal, normalize(half_vector))";
+ std::string half_angle_proj =
+ "normalize(half_vector) - normal * dot(normal, normalize(half_vector))";
// Note: the half angle vector projection is confirmed not normalized before the dot
// product. The result is in fact not cos(phi) as the name suggested.
index = "dot(" + half_angle_proj + ", tangent)";
@@ -750,7 +751,8 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
}
// Fresnel
- if (lighting.lut_fr.enable &&
+ // Note: only the last entry in the light slots applies the Fresnel factor
+ if (light_index == lighting.src_num - 1 && lighting.lut_fr.enable &&
LightingRegs::IsLightingSamplerSupported(lighting.config,
LightingRegs::LightingSampler::Fresnel)) {
// Lookup fresnel LUT value
@@ -759,17 +761,17 @@ static void WriteLighting(std::string& out, const PicaShaderConfig& config) {
lighting.lut_fr.type, lighting.lut_fr.abs_input);
value = "(" + std::to_string(lighting.lut_fr.scale) + " * " + value + ")";
- // Enabled for difffuse lighting alpha component
+ // Enabled for diffuse lighting alpha component
if (lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::PrimaryAlpha ||
lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- out += "diffuse_sum.a *= " + value + ";\n";
+ out += "diffuse_sum.a = " + value + ";\n";
}
// Enabled for the specular lighting alpha component
if (lighting.fresnel_selector ==
LightingRegs::LightingFresnelSelector::SecondaryAlpha ||
lighting.fresnel_selector == LightingRegs::LightingFresnelSelector::Both) {
- out += "specular_sum.a *= " + value + ";\n";
+ out += "specular_sum.a = " + value + ";\n";
}
}
@@ -1112,7 +1114,10 @@ vec4 secondary_fragment_color = vec4(0.0);
"gl_FragCoord.y < scissor_y2)) discard;\n";
}
- out += "float z_over_w = 1.0 - gl_FragCoord.z * 2.0;\n";
+ // After perspective divide, OpenGL transform z_over_w from [-1, 1] to [near, far]. Here we use
+ // default near = 0 and far = 1, and undo the transformation to get the original z_over_w, then
+ // do our own transformation according to PICA specification.
+ out += "float z_over_w = 2.0 * gl_FragCoord.z - 1.0;\n";
out += "float depth = z_over_w * depth_scale + depth_offset;\n";
if (state.depthmap_enable == RasterizerRegs::DepthBuffering::WBuffering) {
out += "depth /= gl_FragCoord.w;\n";
@@ -1152,6 +1157,11 @@ vec4 secondary_fragment_color = vec4(0.0);
// Blend the fog
out += "last_tex_env_out.rgb = mix(fog_color.rgb, last_tex_env_out.rgb, fog_factor);\n";
+ } else if (state.fog_mode == TexturingRegs::FogMode::Gas) {
+ Core::Telemetry().AddField(Telemetry::FieldType::Session, "VideoCore_Pica_UseGasMode",
+ true);
+ LOG_CRITICAL(Render_OpenGL, "Unimplemented gas mode");
+ UNIMPLEMENTED();
}
out += "gl_FragDepth = depth;\n";
@@ -1195,7 +1205,9 @@ void main() {
texcoord0_w = vert_texcoord0_w;
normquat = vert_normquat;
view = vert_view;
- gl_Position = vec4(vert_position.x, vert_position.y, -vert_position.z, vert_position.w);
+ gl_Position = vert_position;
+ gl_ClipDistance[0] = -vert_position.z; // fixed PICA clipping plane z <= 0
+ // TODO (wwylele): calculate gl_ClipDistance[1] from user-defined clipping plane
}
)";