[jak2] fix palace rotation and sprite glow depth test (#2269)

- Disable depth test for sprite glow (VU1 programs only `sq.xy` and
leaves `z` alone, which has Z_MAX from the template)
- Fix tfrag/tie/shrub issues when `use-camera-other` is set.
This commit is contained in:
water111
2023-02-26 09:52:04 -05:00
committed by GitHub
parent 90d5e83d9e
commit e48ae247c4
4 changed files with 57 additions and 20 deletions
@@ -7,10 +7,11 @@ in float discard_flag;
in vec2 uv_texture;
layout (binding = 0) uniform sampler2D tex;
uniform float glow_boost;
void main() {
vec4 texture_color = texture(tex, uv_texture);
color.xyz = texture_color.xyz * fragment_color.xyz * 2.f * discard_flag / 128.f;
color.xyz = texture_color.xyz * fragment_color.xyz * 2.f * discard_flag / 128.f * glow_boost;
color.w = fragment_color.w * texture_color.w;
}
@@ -492,6 +492,7 @@ void GlowRenderer::blit_depth(SharedRenderState* render_state) {
void GlowRenderer::draw_debug_window() {
ImGui::Checkbox("Show Probes", &m_debug.show_probes);
ImGui::Checkbox("Show Copy", &m_debug.show_probe_copies);
ImGui::SliderFloat("Boost Glow", &m_debug.glow_boost, 0, 10);
ImGui::Text("Count: %d", m_debug.num_sprites);
}
@@ -681,7 +682,12 @@ void GlowRenderer::draw_sprites(SharedRenderState* render_state, ScopedProfilerN
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
render_state->shaders[ShaderId::GLOW_DRAW].activate();
glEnable(GL_DEPTH_TEST);
glUniform1f(glGetUniformLocation(render_state->shaders[ShaderId::GLOW_DRAW].id(), "glow_boost"),
m_debug.glow_boost);
// on PS2's, it's enabled but all sprite z's are UINT24_MAX, so it always passes.
// this z-override is done in VU1 code and we don't replicate it here.
glDisable(GL_DEPTH_TEST);
glDepthFunc(GL_GEQUAL);
glEnable(GL_BLEND);
// Cv = (Cs - 0) * Ad + D
@@ -723,6 +729,7 @@ void GlowRenderer::draw_sprites(SharedRenderState* render_state, ScopedProfilerN
prof.add_tri(2);
glDrawElements(GL_TRIANGLE_STRIP, 5, GL_UNSIGNED_INT, (void*)(record.idx * sizeof(u32)));
}
glEnable(GL_DEPTH_TEST);
}
GlowRenderer::Vertex* GlowRenderer::alloc_vtx(int num) {
@@ -26,6 +26,7 @@ class GlowRenderer {
bool show_probes = false;
bool show_probe_copies = false;
int num_sprites = 0;
float glow_boost = 1.f;
} m_debug;
void add_sprite_pass_1(const SpriteGlowOutput& data);
void add_sprite_pass_2(const SpriteGlowOutput& data, int sprite_idx);
@@ -615,25 +615,53 @@
;; first 4 quadwords are planes, then itimes
(let ((data-ptr (the-as (pointer uint128) (-> dma-buf base))))
(set! (-> data-ptr 0) (-> *math-camera* plane 0 quad))
(set! (-> data-ptr 1) (-> *math-camera* plane 1 quad))
(set! (-> data-ptr 2) (-> *math-camera* plane 2 quad))
(set! (-> data-ptr 3) (-> *math-camera* plane 3 quad))
(set! (-> data-ptr 4) (-> lev mood-context itimes 0 quad))
(set! (-> data-ptr 5) (-> lev mood-context itimes 1 quad))
(set! (-> data-ptr 6) (-> lev mood-context itimes 2 quad))
(set! (-> data-ptr 7) (-> lev mood-context itimes 3 quad))
(set! (-> data-ptr 8) (-> *math-camera* camera-temp vector 0 quad))
(set! (-> data-ptr 9) (-> *math-camera* camera-temp vector 1 quad))
(set! (-> data-ptr 10) (-> *math-camera* camera-temp vector 2 quad))
(set! (-> data-ptr 11) (-> *math-camera* camera-temp vector 3 quad))
(set! (-> data-ptr 12) (-> *math-camera* hvdf-off quad))
(let ((vec (-> (the (inline-array vector) data-ptr) 13)))
(set! (-> vec x) (-> *math-camera* pfog0))
(set! (-> vec y) (-> *math-camera* fog-min))
(set! (-> vec z) (-> *math-camera* fog-max))
;; the "use-camera-other" flag is set to "move" entire levels,
;; like the rotating city below in the throne room.
(cond
((-> lev info use-camera-other)
(set! (-> data-ptr 0) (-> *math-camera* plane-other 0 quad))
(set! (-> data-ptr 1) (-> *math-camera* plane-other 1 quad))
(set! (-> data-ptr 2) (-> *math-camera* plane-other 2 quad))
(set! (-> data-ptr 3) (-> *math-camera* plane-other 3 quad))
(set! (-> data-ptr 4) (-> lev mood-context itimes 0 quad))
(set! (-> data-ptr 5) (-> lev mood-context itimes 1 quad))
(set! (-> data-ptr 6) (-> lev mood-context itimes 2 quad))
(set! (-> data-ptr 7) (-> lev mood-context itimes 3 quad))
(set! (-> data-ptr 8) (-> *math-camera* camera-temp-other vector 0 quad))
(set! (-> data-ptr 9) (-> *math-camera* camera-temp-other vector 1 quad))
(set! (-> data-ptr 10) (-> *math-camera* camera-temp-other vector 2 quad))
(set! (-> data-ptr 11) (-> *math-camera* camera-temp-other vector 3 quad))
(set! (-> data-ptr 12) (-> *math-camera* hvdf-off quad))
(let ((vec (-> (the (inline-array vector) data-ptr) 13)))
(set! (-> vec x) (-> *math-camera* pfog0))
(set! (-> vec y) (-> *math-camera* fog-min))
(set! (-> vec z) (-> *math-camera* fog-max))
)
(set! (-> data-ptr 14) (-> *math-camera* trans-other quad))
)
(else
(set! (-> data-ptr 0) (-> *math-camera* plane 0 quad))
(set! (-> data-ptr 1) (-> *math-camera* plane 1 quad))
(set! (-> data-ptr 2) (-> *math-camera* plane 2 quad))
(set! (-> data-ptr 3) (-> *math-camera* plane 3 quad))
(set! (-> data-ptr 4) (-> lev mood-context itimes 0 quad))
(set! (-> data-ptr 5) (-> lev mood-context itimes 1 quad))
(set! (-> data-ptr 6) (-> lev mood-context itimes 2 quad))
(set! (-> data-ptr 7) (-> lev mood-context itimes 3 quad))
(set! (-> data-ptr 8) (-> *math-camera* camera-temp vector 0 quad))
(set! (-> data-ptr 9) (-> *math-camera* camera-temp vector 1 quad))
(set! (-> data-ptr 10) (-> *math-camera* camera-temp vector 2 quad))
(set! (-> data-ptr 11) (-> *math-camera* camera-temp vector 3 quad))
(set! (-> data-ptr 12) (-> *math-camera* hvdf-off quad))
(let ((vec (-> (the (inline-array vector) data-ptr) 13)))
(set! (-> vec x) (-> *math-camera* pfog0))
(set! (-> vec y) (-> *math-camera* fog-min))
(set! (-> vec z) (-> *math-camera* fog-max))
)
(set! (-> data-ptr 14) (-> *math-camera* trans quad))
)
)
(set! (-> data-ptr 14) (-> (math-camera-pos) quad))
(charp<-string (the (pointer uint8) (&-> data-ptr 15)) (symbol->string (-> lev nickname)))
)
(&+! (-> dma-buf base) (* 16 16))