Commit graph

371 commits

Author SHA1 Message Date
Ian Curtis cdf5e4b2b2 Fix transparency depth testing
The two transparency layers, might not be separate layers at all. We believe the hardware is writing each layer to every other pixel (stipple alpha), then using an anti-aliasing filter to effectively blend the pixels. Because the pixels don't overlap they don't depth test against each other. We are using separate layers to emulate this, so the depth buffer must be saved and restored between the layers.
2023-11-17 16:07:20 +00:00
dukeeeey de61835f14
Merge pull request #107 from gm-matthew/lod-blending
Implement LOD blending
2023-11-17 15:53:14 +00:00
Ian Curtis 8778f98c4a Add missing edge on transluency function 2023-11-17 15:50:04 +00:00
gm-matthew ac53101214 Implement LOD blending
If two translucent polygons with opposing patterns overlap the result is always opaque
Also the LOD scale calculation depends on Euclidean distance of x, y and z, not just z
2023-11-17 15:13:27 +00:00
Ian Curtis d726356006 Remove debug code 2023-11-13 23:19:18 +00:00
Ian Curtis efe3077f53 Fix some stencil issues
The stencil mask must be set to all 1s otherwise we can't clear all the bits in the stencil buffer. Also we no longer need to save/restore the depth buffer into between priority layers.
2023-11-13 21:17:06 +00:00
Ian Curtis c40d6ac17b Rewrite the stencil buffer usage slightly, so both the LOS and layered polys work. LOS uses the top bit of the stencil buffer. Fixes some minor issues with draw order in sega rally. 2023-11-10 19:13:37 +00:00
Ian Curtis f9a0901e8c Fix regression
Scroll attenuation seems to disable ambient fog. If scroll attenuation is enabled it's telling the h/w to draw the real3d spot light on fog for the scroll fog layer. This should fix a regression where the background disappears on sega rally.
2023-11-09 18:41:57 +00:00
Ian Curtis a8976b51a2 typo 2023-11-06 10:56:39 +00:00
Ian Curtis a065df24b8 Correct scroll fog attenuation logic (gm_matthew)
The attenuation value effects the spot light on fog for the scroll fog layer. The old implemention was nearly correct but the paramaters for the mix function were swapped.
2023-11-05 23:44:27 +00:00
Ian Curtis aecf61762e Various fixes
- Scroll fog needed a break statement otherwise it could draw potentially multiples times.
- The fog atttenuation paramater doesn't appear to effect scroll fog, other than to potentially enable it. This fixes some issues with emergency call ambulance.
- Added support for the node discard attributes which sega rally2 uses to throw away specific geometry. This fixes junk that starts to show up in the levels after multiple runs.
2023-11-05 17:39:23 +00:00
dukeeeey 628eeebbc3
Merge pull request #101 from gm-matthew/lod-and-blending
Add LOD switching and blending out culling nodes
2023-11-03 19:56:17 +00:00
Ian Curtis 8dda8e9105 Fix the line of sight function.
Polygons have a line of sight value that's either a 0 or 1. We write this value into the stencil buffer, then read the app can read it back to determine the polygon attribute is visible or not. The returned value is 1/depth value in world coordinates. The first bit of the float is actually a control bit, 1 indicates no geometry hit, 0 indicates geometry hit.
2023-11-03 13:24:59 +00:00
gm-matthew 483dbdda2e Add LOD switching and blending out culling nodes
We're not blending between LODs yet as we're not sure of the best way to implement it
Also implementing control bits for disable culling and enable model scale (needed for ECA and Harley)
2023-11-02 14:16:07 +00:00
Ian Curtis 3a85bd9e25 remove debug code 2023-11-01 16:03:11 +00:00
Ian Curtis d16ba90856 Update comments for the culling node function. gm_matthew worked out that the last 2 bits of the model scale float appear to be control bits for disable culling and valid model scale. Strange logic but the line of sight (LOS) function does something similar by re-using float bits for control words. 2023-11-01 16:01:13 +00:00
Ian Curtis 8fea5bd3bf gm_mathew - the line scroll values, the top 16bits are the even lines, the bottom 16bits are the odd lines. We had it swapped. This fixes the number below the word results in daytona, when you finish a game. 2023-10-31 23:50:19 +00:00
Ian Curtis f89da17f17 Fix white gfx on linux / intel gpus. These optimisations originally came from toxieainc 2023-10-27 10:45:16 +01:00
Ian Curtis c5f9a3ad26 Amend the ambient fog logic to be disabled if fog density/start is set to zero. This fixes a regression where the sky stops drawing in lost world.
Rewrite the scroll fog shader slightly. Scroll fog is a 2d layer, it has no depth, or can be considered to be drawn at infinity, therefore is not effected by the viewport light. The scroll attenatuion value also I think attenatutes the scroll fog alpha value. This fixes various effects in emergency call ambulance.
2023-10-24 10:17:15 +01:00
Ian Curtis a214c6dae8 Prior scroll fog logic was nearly correct. For scroll fogging to draw it needs either a start value or a fog density value, but these can come from a different viewport if they have the same colour fog set. This fixes the credits in vf3 which sets scroll fog, but it never draws on the original hardware.
For a long time we've had bug reports that in vf3 the background in the Dural levels was the wrong colour, it should have been much darker. We thought it was again missing scroll fog, but gm_mathew worked out it was actually coming from the fogAmbient paramater. Not only does it darken the fog, but it also has an effect on the 2d background from the tilegen, similar to scroll fog. This also fixes the sky in lemans24.
2023-10-22 21:07:35 +01:00
Ian Curtis 2af0787279 Remove debug code 2023-10-17 17:33:26 +01:00
Ian Curtis 79ddc8c739 Rewrite the logic for the scoll fog (render buffer clear colour). Each viewport can potentially have a scroll fog value so the logic of which value to pick wasn't immediately clear. TLDR I think it picks the highest value starting from the lowest priority layers. This fixes the sky in daytona battle on the edge. 2023-10-17 17:30:14 +01:00
Ian Curtis 86d477263f Scroll fog is like a clear colour for the render target, but can be semi transparent as the tilegen layer can be shown underneath. I assumed that transprent polys would be drawn to the render target for transparent polys but unfortunately the logic does not work. So where else could it be drawn? Well with limited memory it must be draw to the buffer for opaque polys, which means this render target is also blended. 2023-10-15 17:16:52 +01:00
Ian Curtis 6595b9320e Rewrite the renderer a bit to spit out the finished graphics from the 3d chip on separate buffers. One buffer is for opaque pixels, and 2 more for translucent pixels. Before the frame was composited on the back buffer, which meant the tilegen had to have been drawn first. This way the images are now totally independant of the tilegen chip so can be drawn as soon as the register write 0xC is written to the tilegen.
Some games update the tilegen after the ping_ping bit has flipped at 66% of the frame, so we need to split the tilegen drawing up into two stages to get some effects to work. So having the tilegen draw independantly of the 3d chip can make this happen.
2023-10-14 20:05:00 +01:00
Ian Curtis d656643087 gm_mathew worked out that the camera flashes in sega rally 2 have the 'reset-matrix' attribute set inside the culling nodes, which was unsupported until now because we never found any games to have used this bit. The reset matrix is a bit strange, I would assume it would just reset the matrix back to identity, instead it seems to just reset the rotation back to identity whilst preserving the scale/position. 2023-09-27 16:33:53 +01:00
Ian Curtis c6ea81d996 Emulate the entire tilegen chip in a GLSL shader. (This is now possible with opengl 3+). The tilegen drawing was emulated on the CPU, but was one of the most expensive functions in the emulator according to a profiler. On a modern GPU it's pretty much free, because a GPU is a massive SIMD monster.
Tilegen shaders are mapped to uniforms, and the vram and palette are mapped to two textures.

TODO rip out the redundant code in the tilegen class. We don't need to pre-calculate palettes anymore. etc

The tilegen code supports has a start/end line so we can emulate as many lines as we want in a chunk, which will come in later as some games update the tilegen immediately after the ping_pong bit has flipped ~ 66% of the frame.

The scud rolling start tilegen bug is probably actually a bug in the original h/w implementation, that ends up looking correct on original h/w but not for us. Need hardware testing to confirm what it's actually doing.
2023-09-23 15:27:04 +01:00
Ian Curtis 57ead6037d Better opengl resource allocation. Fixes going fullscreen and back. 2022-12-17 23:46:02 +00:00
Ian Curtis 153c510009 Fix uniform location. 2022-11-26 12:58:07 +00:00
Ian Curtis 5f30614c4c FIx shaders failing to build on apple h/w 2022-11-09 18:56:15 +00:00
Ian Curtis 40c8259130 Rewrite the whole project for GL4+. I figured if we removed the limitation of a legacy rendering API we could improve things a bit. With GL4+ we can do unsigned integer math in the shaders. This allows us to upload a direct copy of the real3d texture sheet, and texture directly from this memory given the x/y pos and type. This massively simplifies the binding and invalidation code. Also the crazy corner cases will work because it essentially works the same way as the original hardware.
The standard triangle render requires gl 4.1 core, so should work on mac. The quad renderer runs on 4.5 core. The legacy renderer should still work, and when enabled a regular opengl context will be created, which allows functions marked depreciated in the core profiles to still work. This will only work in windows/linux I think. Apple doesn't support this.

A GL 4.1 GPU is now the min required spec. Sorry if you have an OLDER gpu. GL 4.1 is over 12 years old now.

This is a big update so I apologise in advance if I accidently broke something :]
2022-11-07 21:33:01 +00:00
Ian Curtis b2e5a200da Fix build for linux (just missing header) 2022-10-17 09:34:11 +01:00
Ian Curtis f0872cc998 Upgrade the glsl shader class a bit. Add a const char* comparitor so we can use a map with a simple "string" key. Fine to use when performance is not critical. 2022-10-16 21:03:41 +01:00
Ian Curtis 6fbf938335 Add a proper git ignore file .. And fix the legacy renderer to build with new visual studio (2019) 2022-10-16 20:45:40 +01:00
toxieainc e644751f01 after clarifications, minor cleanup 2022-10-10 16:35:02 -07:00
toxieainc 75771b3d14 remove 2 dupe function calls, where ProcessLos should actually be rather costly 2022-10-10 16:35:02 -07:00
Fernando Casas Schössow 412e9232d7 Fix new 3D engine texture2DLod function missing error on Linux/MESA. MESA requires needed extensions to be explicitly declared in code otherwise it will not enable them. 2022-10-10 16:30:09 -07:00
toxieainc aae58edd62 change one more place with potential aliasing issue 2022-10-03 17:59:59 -07:00
toxieainc 5f97e5af6c address review 2022-10-03 17:59:59 -07:00
toxieainc 519d695f57 address review and move bit casts to new header 2022-10-03 17:59:59 -07:00
toxieainc 1b0e3be8dc use correct slash 2022-10-03 17:59:59 -07:00
toxieainc 22ffb5cc19 Harmless math warning fixes. map->unordered_map in CNew3D::CacheModel. Avoid general aliasing problems (using bit_cast or the recommended/optimized-away memcpy). 2022-10-03 17:59:59 -07:00
toxieainc d7041a83c9 fix missing version GLSL compiler warnings on startup
happens (at least) on Intel drivers
2022-08-19 08:41:22 -07:00
toxieainc 6c24bf7c8f Optimize quad rendering by replacing the double computations for the area computation with the equivalent shoelace algorithm along with kahans algorithm to compute the cross products. In addition pull out the /w to the end, which increases precision even more.
Thus making the result similar to the fp64 version, tested e.g. with harleys first person mode (all artifacts still gone as before).

Improves perf on low end boards (e.g. Intel) dramatically (10fps with harley before, now 70 on my laptop), and even on higher end (e.g. NVIDIA laptop, quads are now faster than tri pipeline on my laptop).
2022-08-16 21:34:31 -07:00
toxieainc 27e071dafb add comment 2022-07-18 21:43:13 +02:00
toxieainc abb1273aa0 slightly optimize DrawTileLine (less branches/logic) 2022-07-11 18:49:02 +02:00
toxieainc b2b8396947 missed 2 changed files with last commit 2022-07-11 18:27:44 +02:00
toxieainc 4961951a89 fix a real error (m68kdasm) and some harmless performance warnings and use modern headers 2022-07-11 18:10:41 +02:00
toxieainc e0053b3a46 fix some real errors (Model3,InputSystem), minor errors (SCSP,SDL/Main) and some performance warnings 2022-07-11 17:43:59 +02:00
Ian Curtis 83e7b5f45d njz3: Proper quadrophonic audio support. Need 4+ speakers to take advantage otherwise down mixed to stereo. 2022-06-09 21:10:39 +00:00
Ian Curtis 0ef90899e1 Double buffer the line of sight values. Should allow the correct values to be returned if GPU threading is enabled. 2022-01-02 12:48:09 +00:00