Files
jak-project/game/graphics/opengl_renderer/shaders/generic.vert
T
Fabian Bergström 40e2f113e6 Make Jak1 playable on macOS (intel) (#2811)
## Problem

OpenGOAL uses OpenGL 4.3.

Apple stopped upgrading OpenGL after 4.1, so the way OpenGOAL currently
works will never be playable on Macs using OpenGL.

## Solution

Luckily, downgrading to OpenGL 4.1 is not a huge change (at least it
doesn't seem like it to my untrained eyes).

## Changes

* set hints for OpenGL 4.1 instead of 4.3 for __APPLE__
* skip the OpenGL debugging callback setup for macOS (requires 4.3)
* bump down the version string for all shaders
* stop using the `binding` layout qualifier in shader code
* move the `flat` qualifier first (not sure if this is a 4.1 thing or
just Macs being more strict)
* don't mix signed and unsigned ints in shaders (not sure if this is a
4.1 thing or just Macs being more strict)
* add some hacky CPP to the Shader constructor for binding texture units
and bones buffers based on variable names in the shader code

## Results


![image](https://github.com/open-goal/jak-project/assets/33322/dd487c2a-61ac-4e36-a595-976204302977)
![Skärmavbild 2023-07-07 kl 13 10
30](https://github.com/open-goal/jak-project/assets/33322/7976d411-0604-4046-9e8a-123106cedf57)
![Skärmavbild 2023-07-07 kl 13 13
48](https://github.com/open-goal/jak-project/assets/33322/78db4f0c-da31-4889-995c-8f54e56deb5c)
2023-07-08 11:53:43 -04:00

94 lines
2.5 KiB
GLSL

#version 410 core
layout (location = 0) in vec3 position_in;
layout (location = 1) in vec4 rgba_in;
layout (location = 2) in vec2 tex_coord_in;
layout (location = 3) in uvec4 byte_info;
uniform float mat_32;
uniform vec3 fog_constants;
uniform vec4 scale;
uniform float mat_23;
uniform float mat_33;
uniform vec4 hvdf_offset;
uniform uint warp_sample_mode;
out vec2 tex_coord;
out vec4 fragment_color;
out float fog;
flat out uvec2 tex_info;
const float warp_off = 1.0f - (SCISSOR_HEIGHT / 512.0f);
void main() {
// lq.xy vf22, 0(vi10) texture load?
// lq_buffer(Mask::xy, vu.vf22, vu.vi10);
// lq.xyz vf16, 2(vi10) vertex load
// lq_buffer(Mask::xyz, gen.vtx_load0, vu.vi10 + 2);
// mtir vi02, vf22.x grab s coordinate of texture
// vu.vi02 = vu.vf22.x_as_u16();
// mulaw.xyzw ACC, vf11, vf00 matrix multiply W
// vu.acc.mula(Mask::xyzw, gen.mat3, vu.vf00.w());
vec4 transformed;
// maddax.xyzw ACC, vf08, vf16 matrix multiply X
// vu.acc.madda(Mask::xyzw, gen.mat0, gen.vtx_load0.x());
transformed.xyz = position_in * scale.xyz;
transformed.z += mat_32;
transformed.w = mat_23 * position_in.z + mat_33;
transformed *= -1; // todo?
// div Q, vf01.x, vf12.w perspective divide
// vu.Q = gen.fog.x() / gen.vtx_p0.w();
float Q = fog_constants.x / transformed.w;
fog = 255 - clamp(-transformed.w + hvdf_offset.w, fog_constants.y, fog_constants.z);
// itof12.xyz vf18, vf22 texture int to float
// vu.vf18.itof12(Mask::xyz, vu.vf22);
tex_coord = tex_coord_in / 4096.f;
if (warp_sample_mode == 1) {
tex_coord = vec2(tex_coord.x, (1.0f - tex_coord.y - warp_off) * SCISSOR_ADJUST);
}
// mul.xyz vf12, vf12, Q persepective divide
// gen.vtx_p0.mul(Mask::xyz, gen.vtx_p0, vu.Q);
transformed.xyz *= Q;
// mul.xyz vf18, vf18, Q texture perspective divide
// vu.vf18.mul(Mask::xyz, vu.vf18, vu.Q);
// add.xyzw vf12, vf12, vf04 apply hvdf
// gen.vtx_p0.add(Mask::xyzw, gen.vtx_p0, gen.hvdf_off);
transformed.xyz += hvdf_offset.xyz;
// correct xy offset
transformed.xy -= (2048.);
// correct z scale
transformed.z /= (8388608);
transformed.z -= 1;
// correct xy scale
transformed.x /= (256);
transformed.y /= -(128);
// hack
transformed.xyz *= transformed.w;
gl_Position = transformed;
// scissoring area adjust
gl_Position.y *= SCISSOR_ADJUST * HEIGHT_SCALE;
fragment_color = vec4(rgba_in.rgb, rgba_in.a * 2);
tex_info = byte_info.xy;
}