Commit graph

281 commits

Author SHA1 Message Date
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 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 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
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 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 4961951a89 fix a real error (m68kdasm) and some harmless performance warnings and use modern headers 2022-07-11 18:10:41 +02: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
Matthew Daniels 9ffce8b92a Getting rid of most of the includes from Supermodel.h; each file now explicitly includes the header files it needs.
Making changes to a header file should no longer force the entire project to recompile.
2021-11-22 17:15:06 +00:00
Ian Curtis e3374256ff Just a few compile warnings 2021-02-20 22:19:16 +00:00
Ian Curtis 75f8ee61a3 fix missing polys with quad renderer 2020-09-14 20:01:52 +00:00
Ian Curtis 38c3ff61f9 Clip scroll fog to viewport, instead of filling entire screen. Fixes fog bug in Daytona credits. 2020-09-08 09:10:24 +00:00
Ian Curtis aaa26f678c Update scroll fog logic. Should fix the credits in virtua fighter and daytona that have fogging applied to the background layer and shouldn't. 2020-09-07 16:25:18 +00:00
Ian Curtis ba917aca6d Update glew version 2020-07-31 19:18:51 +00:00
Ian Curtis 6f6c98c671 The translator map seems to work with paletted colour values too, and the result is not clamped. Colours are passed to the GPU as unsigned bytes to multiplying by 16 will overflow, so we do the logic in the shader. If we passed floats we could skip the shader logic. 2020-05-11 09:05:46 +00:00
Ian Curtis e2ad593e88 When the translator map is enabled the colour values seem to use 4 bits, 0-16. Why not 0-31 I don't know. Anyway virtua on is overflowing these values for some of the smoke effects. For us the numbers were wrapping around. Clamping is enough to fix this. (Thanks model123) 2020-05-07 19:34:22 +00:00
Ian Curtis 5ace960f14 tweak value so the map indicator still works at the start of spikeout 2020-01-04 18:15:30 +00:00
Ian Curtis 6b8a29105a Sutherland-Hodgeman clipping only works for planar primitives. Scud is rendering non planar quads and this breaks our algorithm a little when using the quad renderer. Stretching the near plane a few % is enough to fix it. 2020-01-04 13:48:14 +00:00
Ian Curtis d711afade1 Only need to clip against 4 planes for poly culling 2020-01-04 13:45:55 +00:00
Ian Curtis 605dad2c02 Fix the sky in harley in first person mode where pixels in the sky are culled when they shouldn't be with the quad renderer. Basically we were running out of precision in a rare corner case. Doing the maths with double precision and casting back to float was enough to fix the issue. 2019-12-27 21:36:46 +00:00
Ian Curtis a5858e635d To calculate the mipmap value the opengl needs to calculate the difference in the texture coordinates between adjacent pixels. If there are no adjacent pixels the hw may need to spawn invisible fragments outside of the visible polygon. Our algorithm was culling these out so the mipamp calculation failed for edge pixels. Anyway this fixes quad rendering looking broken with the latest nvidia drivers. 2019-12-10 11:40:39 +00:00
Ian Curtis 06688de5fc Really should cull against 5 frustum planes. 2019-11-15 20:00:25 +00:00