rickomax / psxprev

PSXPREV - Playstation (PSX) Files Previewer/Extractor
BSD 2-Clause "Simplified" License
193 stars 10 forks source link

Add render flags, semi-transparency, and renderer refactoring #77

Closed trigger-segfault closed 12 months ago

trigger-segfault commented 12 months ago

Short explanation

Rendering

This PR aims to support a variety of flags that effect how each mesh is rendered. This includes Unlit, Double-Sided, and Semi-transparent.

Semi-transparency required the most work to implement since it required storing the stp bit (MSB) found in all 16-bit colors. This was done by adding a second Bitmap to Texture that stores false as black, and true as white (This could not be stored in the alpha because textures may be used by both opaque and semi-transparent meshes. Additionally this would mess with texture exporting). To make sure this information is available to the shader, VRAM pages now create 512x256 textures, where x coordinates [256,512) hold the semi-transparent information drawn by textures. Lastly, the fragment shader has been updated to handle reading the stp bits by dividing the uv.x by 2 and adding 0.5 to the second lookup.

Mask color is now ignored when stp bit is SET. This fixes issues where portions of models would be invisible when they should be black.

The MeshBatch now performs drawing in 3 passes.

  1. Opaque meshes
  2. Semi-transparent meshes for pixels with stp bit UNSET (opaque pixels)
  3. Semi-transparent meshes for pixels with stp bit SET (semi-transparent pixels)

The Preview form now has two new checkbox menu items under Models:

Refactoring


Detailed explanation