Fix Jak 2 scissoring (#2257)

fixes #2255 and hopefully didn't break Jak 1
This commit is contained in:
ManDude 2023-02-26 00:09:35 +00:00 committed by GitHub
parent 8a363c2fc9
commit 618455500d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
22 changed files with 26 additions and 41 deletions

View File

@ -6,8 +6,10 @@
#include "game/graphics/pipelines/opengl.h"
Shader::Shader(const std::string& shader_name, GameVersion version) {
std::string height_scale = version == GameVersion::Jak1 ? "1.0" : "0.5";
Shader::Shader(const std::string& shader_name, GameVersion version) : m_name(shader_name) {
const std::string height_scale = version == GameVersion::Jak1 ? "1.0" : "0.5";
const std::string scissor_height = version == GameVersion::Jak1 ? "448.0" : "416.0";
const std::string scissor_adjust = "512.0 / " + scissor_height;
// read the shader source
auto vert_src =
file_util::read_text_file(file_util::get_file_path({shader_folder, shader_name + ".vert"}));
@ -15,6 +17,8 @@ Shader::Shader(const std::string& shader_name, GameVersion version) {
file_util::read_text_file(file_util::get_file_path({shader_folder, shader_name + ".frag"}));
vert_src = std::regex_replace(vert_src, std::regex("HEIGHT_SCALE"), height_scale);
vert_src = std::regex_replace(vert_src, std::regex("SCISSOR_HEIGHT"), scissor_height);
vert_src = std::regex_replace(vert_src, std::regex("SCISSOR_ADJUST"), "(" + scissor_adjust + ")");
m_vert_shader = glCreateShader(GL_VERTEX_SHADER);
const char* src = vert_src.c_str();

View File

@ -15,6 +15,7 @@ class Shader {
u64 id() const { return m_program; }
private:
std::string m_name;
u64 m_frag_shader = 0;
u64 m_vert_shader = 0;
u64 m_program = 0;

View File

@ -68,7 +68,7 @@ void main() {
gl_Position = transformed;
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
// wireframe check
if (wireframe == 0) {

View File

@ -9,6 +9,6 @@ out vec4 fragment_color;
void main() {
gl_Position = vec4((position_in.x - 0.5) * 16., -(position_in.y - 0.5) * 32, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color = vec4(1.0, 0, 0, 0.7);
}

View File

@ -18,7 +18,7 @@ void main() {
-(position_in.y - 0x8000) / 0x800,
position_in.z / 0x800000 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color = vec4(rgba_in.x, rgba_in.y, rgba_in.z, rgba_in.w * 2.);
tex_coord = tex_coord_in;
tex_info = byte_info.xy;

View File

@ -11,6 +11,6 @@ void main() {
// Note: position.y is multiplied by 32 instead of 16 to undo the half-height for interlacing stuff.
gl_Position = vec4((position_in.x - 0.5) * 16., -(position_in.y - 0.5) * 32 * HEIGHT_SCALE, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color = vec4(rgba_in.x, rgba_in.y, rgba_in.z, rgba_in.w * 2.);
}

View File

@ -15,7 +15,7 @@ out flat uvec4 tex_info;
void main() {
gl_Position = vec4((position_in.x - 0.5) * 16., -(position_in.y - 0.5) * 32 * HEIGHT_SCALE, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color = vec4(rgba_in.x, rgba_in.y, rgba_in.z, rgba_in.w * 2.);
tex_coord = tex_coord_in;
tex_info = tex_info_in;

View File

@ -16,8 +16,6 @@ uniform mat4 perspective_matrix;
uniform vec4 fade;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
// output
out vec3 vtx_color;
out vec2 vtx_st;
@ -123,7 +121,7 @@ void main() {
transformed.x /= (256);
transformed.y /= -(128);
transformed.xyz *= transformed.w;
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;

View File

@ -19,8 +19,6 @@ out float fog;
out flat uvec2 tex_info;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
void main() {
// lq.xy vf22, 0(vi10) texture load?
// lq_buffer(Mask::xy, vu.vf22, vu.vi10);
@ -81,7 +79,7 @@ void main() {
gl_Position = transformed;
// scissoring area adjust
gl_Position.y *= SCISSOR_ADJUST;
gl_Position.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
fragment_color = vec4(rgba_in.rgb, rgba_in.a * 2);
tex_info = byte_info.xy;

View File

@ -9,8 +9,6 @@ out vec4 fragment_color;
out vec2 uv_texture;
out float discard_flag;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
layout (binding = 1) uniform sampler2D probe_tex;
@ -23,7 +21,7 @@ void main() {
transformed.y /= -(128);
transformed.xyz *= transformed.w;
// scissoring area adjust
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;
fragment_color = rgba_in;
uv_texture = uv_texture_in;

View File

@ -5,8 +5,6 @@ layout (location = 1) in vec4 rgba_in;
out vec4 fragment_color;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
void main() {
vec4 transformed = position_in;
transformed.xy -= (2048.);
@ -16,7 +14,7 @@ void main() {
transformed.y /= -(128);
transformed.xyz *= transformed.w;
// scissoring area adjust
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;
fragment_color = rgba_in;

View File

@ -9,5 +9,5 @@ out vec2 tex_coord;
void main() {
gl_Position = vec4((position_in.xy * 2) - 1.f, 0.f, 1.f);
tex_coord.x = uv.x / 512;
tex_coord.y = 1.f - ((uv.y + 16) / 448);
tex_coord.y = 1.f - (uv.y / SCISSOR_HEIGHT);
}

View File

@ -6,6 +6,6 @@ layout (location = 2) in vec2 uv;
void main() {
float x = (uv.x / 512) * 2 - 1;
float y = -(((uv.y + 16) / 448) * 2 - 1);
float y = 1.f - ((uv.y / SCISSOR_HEIGHT) * 2);
gl_Position = vec4(x, y, 0, 1.f);
}

View File

@ -23,8 +23,6 @@ uniform vec4 fog_constants;
uniform mat4 perspective_matrix;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
// output
out vec4 vtx_color;
out vec2 vtx_st;
@ -107,7 +105,7 @@ void main() {
transformed.x /= (256);
transformed.y /= -(128);
transformed.xyz *= transformed.w;
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;

View File

@ -9,14 +9,12 @@ out vec4 fragment_color;
out vec3 tex_coord;
out float fog;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
uniform int bucket;
void main() {
gl_Position = vec4((position_in.x - 0.5) * 16., -(position_in.y - 0.5) * 32, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= SCISSOR_ADJUST;
gl_Position.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
fragment_color = vec4(rgba_in.rgb, rgba_in.a * 2);
tex_coord = tex_coord_in;
fog = 255 - fog_in;

View File

@ -6,5 +6,5 @@ void main() {
// Note: position.y is multiplied by 32 instead of 16 to undo the half-height for interlacing stuff.
gl_Position = vec4((position_in.x - 0.5) * 16., -(position_in.y - 0.5) * 32, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
}

View File

@ -16,8 +16,6 @@ out vec4 fragment_color;
out vec3 tex_coord;
out float fogginess;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
void main() {
@ -62,7 +60,7 @@ void main() {
// hack
transformed.xyz *= transformed.w;
// scissoring area adjust
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;
// time of day lookup

View File

@ -10,7 +10,7 @@ noperspective out vec3 tex_coord;
void main() {
gl_Position = vec4((position_in.x - 0.5) * 16. , -(position_in.y - 0.5) * 32, position_in.z * 2 - 1., 1.0);
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color = vec4(rgba_in.x, rgba_in.y, rgba_in.z, rgba_in.a * 2);
tex_coord = tex_coord_in;
}

View File

@ -28,8 +28,6 @@ out flat vec4 fragment_color;
out vec3 tex_coord;
out flat uvec2 tex_info;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
vec4 matrix_transform(mat4 mtx, vec3 pt) {
return mtx[3]
+ mtx[0] * pt.x
@ -169,7 +167,7 @@ void main() {
// hack
transformed.xyz *= transformed.w;
// scissoring area adjust
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;
fragment_color *= 2;

View File

@ -172,7 +172,7 @@ void main() {
gl_Position = transformed;
// scissoring area adjust
gl_Position.y *= 512.0/448.0;
gl_Position.y *= SCISSOR_ADJUST;
fragment_color.w *= 2;

View File

@ -15,8 +15,6 @@ out vec4 fragment_color;
out vec3 tex_coord;
out float fogginess;
const float SCISSOR_ADJUST = HEIGHT_SCALE * 512.0/448.0;
void main() {
@ -61,7 +59,7 @@ void main() {
// hack
transformed.xyz *= transformed.w;
// scissoring area adjust
transformed.y *= SCISSOR_ADJUST;
transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
gl_Position = transformed;
// time of day lookup

View File

@ -9,8 +9,6 @@ uniform float fog_constant;
out vec4 fragment_color;
const float SCISSOR_ADJUST = 512.0/448.0;
// this is just for debugging.
void main() {
vec4 transformed = camera[3];