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.
Opaque meshes
Semi-transparent meshes for pixels with stp bit UNSET (opaque pixels)
Semi-transparent meshes for pixels with stp bit SET (semi-transparent pixels)
The Preview form now has two new checkbox menu items under Models:
Enable Transparency: Can be used to turn off semi-transparency behavior.
Force Double-Sided: Can be used to use the old behavior of PSXPrev and double-side all polygons. Useful for viewing models from unintended angles.
Refactoring
VRAM page management has now been moved to a new VRAMPages class.
ManifestResourceLoader can now load files from resources, but will default to the file system if the file exists.
Improved cleanup handling of GDI objects. This still doesn't fix all cases though, like with textures that are lost when a parser fails.
Detailed explanation
Implemented RenderFlags, MixtureRate (ABR), and RenderInfo for separating meshes.
RenderInfo is a struct that stores TexturePage, RenderFlags, and MixtureRate.
Most instances where groupedTriangles are looked up via uint (TexturePage) are now looked up via RenderInfo.
Added support for Unlit, DoubleSided, and SemiTransparency RenderFlags, along with support for all 4 MixtureRates.
For readers that don't support RenderFlags, DoubleSided is treated as the default flags (for now). This is because double-sided was already the default behavior for PSXPrev.
MeshBatch now draws meshes in 3 passes. The passes make things a bit more complex, and results in a lot of GL settings (that were originally handled by Scene) needing to be changed on a per-pass or per-mesh basis. This can be optimized in the future by grouping meshes of the same settings together.
Pass 1: Opaque meshes
Pass 2: Semi-transparent meshes for pixels with stp bit UNSET. (opaque pixels)
Pass 3: Semi-transparent meshes for pixels with stp bit SET. (semi-transparent pixels)
Fixed PMDParser bailing on primitiveTypes with bits 0x30, because it treated those as an unknown structure, when in reality, these bits don't affect packet structure (as stated by the docs).
Changed TIMParser allowOutOfBounds handling to check if there's enough room at the start of the function, rather than checking at each pixel. This fixes issues where loading all LRR data at once would produce some partially-invalid texture data. Now null is returned if there's not enough room, so invalid textures never make it to the party.
Textures now store an additional Bitmap that contains semi-transparent data. This is simply a boolean flag (stored as black (false) and white (true)). TIMParser also handles reading in this semi-transparent data.
Texture now implements IDisposable (although this isn't made us of yet).
ManifestResourceLoader now fulfills its intended purpose of loading files from resources. By default, it will attempt to load from a filepath, and fallback to resources if the file isn't found.
Added VRAMPages class to manage VRAM, and move management away from PreviewForm.
This class handles adding Semi-transparency data to pages by storing this data from X coordinates [256,512), so page textures are now 512x256 in size.
Includes static helper functions for clamping TexturePage, TextureX, and TextureY.
Includes functions for supressing updates to the scene textures, allowing for mass-drawing of textures and then updating each page afterwards.
Implements IDisposable (but this isn't made use of yet).
Added uniform semiTransparentMode variable to fragment shader. This variable is used to detect which of the 3 drawing passes the mesh batch is on, and determines when to discard pixels.
Fragment shader now only discards black (mask) pixels when stp bit is UNSET. This fixes a lot of models having gaps in the mesh where black should be.
Added more instances of using and proper cleanup of GDI resources. Bitmaps for 3 PreviewForm color boxes are now stored as fields and updated, rather than creating new Bitmaps each time.
Added 2 new PreviewForm checkbox menu items:
Models > Enable Transparency (checked). Can be used to turn off semi-transparency behavior.
Models > Force Double-Sided (unchecked). Can be used to use the old behavior of PSXPrev and double-side all polygons. Useful for viewing models from unintended angles.
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.
The Preview form now has two new checkbox menu items under Models:
Refactoring
VRAMPages
class.ManifestResourceLoader
can now load files from resources, but will default to the file system if the file exists.Detailed explanation