Skip to content

Fix VDP2 background rendering pipeline#6

Open
spacestate1 wants to merge 1 commit intoyaz0r:masterfrom
spacestate1:pr/vdp2-rendering-fixes
Open

Fix VDP2 background rendering pipeline#6
spacestate1 wants to merge 1 commit intoyaz0r:masterfrom
spacestate1:pr/vdp2-rendering-fixes

Conversation

@spacestate1
Copy link
Copy Markdown

Fixes VDP2 background layer rendering so layers display correctly at all resolutions.

Files changed

VDP2 shader

  • AzelLib/shaders/VDP2_ps.sc (L6): Use regular sampler for plane config texture (was unsigned int sampler that broke on some drivers)
  • AzelLib/shaders/VDP2_ps.sc (L42-48): Read config values as RGBA8 bytes and reconstruct ints (matches new texture format)
  • AzelLib/shaders/VDP2_ps.sc (L120-127): Wrap scroll coordinates with modulo so negative scroll values work instead of showing red
  • AzelLib/shaders/VDP2_ps.sc (L131): Fix Y-axis tile lookup - was using width instead of height
  • AzelLib/shaders/VDP2_ps.sc (L163-185): Pick correct palette based on color depth (16-color vs 256-color modes)
  • AzelLib/shaders/VDP2_ps.sc (L295-299): Apply zoom/scale to pixel coordinates

Layer data and GPU rendering

  • AzelLib/renderer.cpp (L540-564): Add zoom and output height fields to layer config struct
  • AzelLib/renderer.cpp (L582-590): Recreate GPU framebuffer when switching between GPU and software mode
  • AzelLib/renderer.cpp (L617): Change config texture format from R32U to RGBA8 (works on all backends)
  • AzelLib/renderer.cpp (L632-697): Pass all layer settings as GPU uniforms so the shader can read them reliably

Software rendering path

  • AzelLib/renderer.cpp (new, ~L743-775): New renderLayerSoftware() function - renders on CPU and uploads to GPU texture. Replaces assert(0) that crashed when software mode was selected.
  • AzelLib/renderer.cpp (L813-816): Apply zoom in software renderer too

Per-layer fixes (BG0, BG1, BG3, RBG0)

  • AzelLib/renderer.cpp renderBG0 (L988-1004): Remove duplicate resolution doubling, add zoom registers, use new software path
  • AzelLib/renderer.cpp renderBG1 (L1104-1163): Add zoom registers, use new software path
  • AzelLib/renderer.cpp renderBG3 (L1226-1240): Add output height, use new software path
  • AzelLib/renderer.cpp renderRBG0 (L1307-1323): Add output height, use new software path

Compositing (final image assembly)

  • AzelLib/renderer.cpp (L1808-1812): Enable alpha blending when drawing layers, stop clearing between each layer
  • AzelLib/renderer.cpp (L1854-1870): Handle all 8 HRESO resolution modes. Split VDP1 (3D) resolution from VDP2 (background) resolution - title screen needs 352px for 3D but 704px for backgrounds
  • AzelLib/renderer.cpp (L1998-2040): Use the back screen color register for clear color. Draw sprites at their priority level, then backgrounds in order

Supporting fixes

  • AzelLib/renderer.h (L15-17): Reorder views so VDP1 renders before the composite pass
  • AzelLib/VDP2.cpp (L418-419): Init zoom Y registers to 1.0 (was uninitialized)
  • AzelLib/VDP2.cpp (L1759): Fix missing return in computeStringLength()

Merge note

Safe to merge on its own. This is the biggest PR but all changes are self-consistent - the shader, texture format, and renderer code all match each other. Recommend merging this before PR 4 (title screen text), since the text layer needs these rendering fixes to actually show up.

- Shader: fix planeConfig sampler type (R32U -> RGBA8 with manual unpack),
  fix palette number extraction for 16-color and 256-color modes,
  wrap scroll coordinates properly (fixes negative scroll artifacts),
  fix dotInPlaneY using planeDotHeight instead of planeDotWidth,
  add zoom/coordinate increment support
- Software renderer: implement renderLayerSoftware() so CPU render path
  works for all layers (was assert(0)), add zoom support
- Resolution: handle all HRESO modes (0-7), separate VDP1 output resolution
  from VDP2 native resolution (e.g. title screen: VDP1=352, VDP2=704)
- Compositing: set back screen clear color, render SPRITE_POLY at its
  priority before background layers, add alpha blending, clear composite
  view once instead of per-layer
- View ordering: VDP1 renders before composite view
- VDP2 registers: initialize zoom Y registers, fix computeStringLength
  missing return value
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant