From 95fb7e3be16a95288dec4c66b9511599d034f1af Mon Sep 17 00:00:00 2001 From: ZedB0T <89345505+Zedb0T@users.noreply.github.com> Date: Sat, 18 May 2024 11:57:07 -0400 Subject: [PATCH] Add files (#83) --- hfrag/hfrag.frag | 23 +++++++++++++++++ hfrag/hfrag.vert | 56 ++++++++++++++++++++++++++++++++++++++++ hfrag/hfrag_montage.frag | 8 ++++++ hfrag/hfrag_montage.vert | 11 ++++++++ 4 files changed, 98 insertions(+) create mode 100644 hfrag/hfrag.frag create mode 100644 hfrag/hfrag.vert create mode 100644 hfrag/hfrag_montage.frag create mode 100644 hfrag/hfrag_montage.vert diff --git a/hfrag/hfrag.frag b/hfrag/hfrag.frag new file mode 100644 index 0000000000..fc6bdbce57 --- /dev/null +++ b/hfrag/hfrag.frag @@ -0,0 +1,23 @@ +#version 410 core + +out vec4 color; + +in vec4 fragment_color; +in vec2 tex_coord; +in float fogginess; +uniform sampler2D tex_T0; +uniform vec4 fog_color; + +uniform int gfx_hack_no_tex; + + +void main() { + if (gfx_hack_no_tex == 0) { + vec4 T0 = texture(tex_T0, tex_coord); + color = fragment_color * T0 * 2; + } else { + color = fragment_color; + } + + color.rgb = mix(color.rgb, fog_color.rgb, clamp(fogginess * fog_color.a, 0, 1)); +} diff --git a/hfrag/hfrag.vert b/hfrag/hfrag.vert new file mode 100644 index 0000000000..be46fe4e53 --- /dev/null +++ b/hfrag/hfrag.vert @@ -0,0 +1,56 @@ +#version 410 core + +layout (location = 0) in float position_in; +layout (location = 1) in int time_of_day_index; +layout (location = 2) in ivec2 uv; +layout (location = 3) in int vi; + +uniform vec4 hvdf_offset; +uniform mat4 camera; +uniform float fog_constant; +uniform float fog_min; +uniform float fog_max; +uniform sampler1D tex_T10; // note, sampled in the vertex shader on purpose. +// uniform int decal; +uniform float fog_hack_threshold; + +out vec4 fragment_color; +out vec2 tex_coord; +out float fogginess; + +void main() { + int vx = vi % 512; + int vz = vi / 512; + + tex_coord.x = (uv.x == 1) ? 1.f : 0.f; + tex_coord.y = (uv.y == 1) ? 1.f : 0.f; + + vec4 transformed = -camera[3]; + transformed -= camera[0] * 32768.f * vx; + transformed -= camera[1] * position_in; + transformed -= camera[2] * 32768.f * vz; + + float Q = fog_constant / transformed.w; + + fogginess = 255 - clamp(-transformed.w + hvdf_offset.w, fog_min, fog_max); + + transformed.xyz *= Q; + // offset + 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); + transformed.xyz *= transformed.w; + // scissoring area adjust + transformed.y *= SCISSOR_ADJUST * HEIGHT_SCALE; + gl_Position = transformed; + + // time of day lookup + fragment_color = texelFetch(tex_T10, time_of_day_index, 0); + fragment_color.a = 1.0; +} diff --git a/hfrag/hfrag_montage.frag b/hfrag/hfrag_montage.frag new file mode 100644 index 0000000000..900522a409 --- /dev/null +++ b/hfrag/hfrag_montage.frag @@ -0,0 +1,8 @@ +#version 410 core +out vec4 color; +in vec2 uv; +uniform sampler2D tex_T0; +void main() { + color = texture(tex_T0, uv); + color.a = 1; +} \ No newline at end of file diff --git a/hfrag/hfrag_montage.vert b/hfrag/hfrag_montage.vert new file mode 100644 index 0000000000..a1b4b43166 --- /dev/null +++ b/hfrag/hfrag_montage.vert @@ -0,0 +1,11 @@ +#version 410 core + +layout (location = 0) in vec2 pos; +layout (location = 1) in vec2 tex_coord; + +out vec2 uv; + +void main() { + gl_Position = vec4(pos.x * 2 - 1, pos.y * 2 - 1, 0, 1); + uv = tex_coord; +}