Commit Graph

35 Commits

Author SHA1 Message Date
Matt Borgerson 8cc83dfc43 nv2a/glsl: Remove some more redundant comments 2025-06-28 00:18:28 -07:00
Matt Borgerson 1489253c68 nv2a/glsl: Add glsl_ prefix to public functions 2025-06-28 00:18:28 -07:00
Matt Borgerson 7804fc0656 nv2a/glsl: Move clipRange value calc to helper func 2025-06-28 00:18:28 -07:00
Matt Borgerson b72119da41 nv2a/glsl: Remove some redundant comments 2025-06-28 00:18:28 -07:00
Matt Borgerson fc28b9c817 nv2a: Move PSH definitions to psh_regs.h 2025-06-28 00:18:28 -07:00
Matt Borgerson 55705002c5 nv2a/glsl: Be consistent in name of state parameter 2025-06-28 00:18:28 -07:00
Matt Borgerson 22b242b2d6 nv2a/glsl: Let pgraph_gen_vsh_glsl take a pointer to PshState 2025-06-28 00:18:28 -07:00
Matt Borgerson 1930934908 nv2a/glsl: Clean up some includes 2025-06-28 00:18:28 -07:00
Matt Borgerson 34e8c62a42 nv2a: Move {Vsh,Psh}State generation into glsl subdir 2025-06-28 00:18:28 -07:00
Matt Borgerson 45724b34e6 nv2a: Drop some unnecessary comments 2025-06-28 00:18:28 -07:00
Matt Borgerson c88bac1706 nv2a: Simplify shader uniform declaration and update
This patch moves uniform declaration into {vsh, psh}.h headers, using
macros to generate accessory definitions. Mapping of PGRAPH state to
uniform values is factored out of parallel paths in GL/Vk renderers into
common renderer-agnostic helper functions, with renderer-specific
uniform value update paths being automated.
2025-06-28 00:18:28 -07:00
Matt Borgerson 18872f2eb9 nv2a: Update various copyright headers 2025-06-28 00:18:28 -07:00
Matt Borgerson 4977e65bd5 nv2a/vk: Clean up layout binding ids 2025-06-28 00:18:28 -07:00
Matt Borgerson 9020913e29 nv2a: Extract GLSL generation options from {Vsh,Psh}State 2025-06-28 00:18:28 -07:00
Erik Abair 348b03d6ce
nv2a: Handle PGRAPH color keying 2025-06-21 13:25:24 -07:00
Matt Borgerson 6e513ed948 nv2a/psh: Fix 2D texture addressing in DOT_STR_3D mode 2025-04-29 23:41:05 -07:00
Erik Abair 89185e6937 nv2a/psh: Fix default alpha for unbound texture samplers 2025-04-22 20:16:15 -07:00
coldhex 02659dd3cc nv2a: Fix cubemap fourth texture coordinate component handling
Xbox hardware ignores fourth texture coordinate component for cubemaps.
2025-03-17 11:37:41 -07:00
Matt Borgerson a143f66ce4 nv2a/psh: Handle 3D textures in PROJECT2D mode 2025-03-10 16:13:09 -07:00
coldhex 798ad30819 nv2a: Perspective-correct interpolation for w-buffering
z_perspective is true implies w-buffering and then the w-coordinate stored
in the depth buffer should also be interpolated in a perspective-correct
way. We do this by calculating w and setting gl_FragDepth in the fragment
shader.

Since enabling polygon offset and setting values using glPolygonOffset
won't have any effect when manually setting gl_FragDepth for w-buffering,
we introduce the depthOffset variable to obtain similar behaviour (but the
glPolygonOffset factor-argument is currently not emulated.) (Note that
glPolygonOffset is OpenGL implementation-dependent and it might be good to
use depthOffset for z-buffering as well, but this is not done here and we
still use OpenGL/Vulkan zbias functionality.)

This also implements depth clipping and clamping in the fragment shader.
If triangles are clipped, the shadows of the small rocks in Halo 2 Beaver
Creek map can have flickering horizontal lines. The shadows are drawn on
the ground in another pass with the same models as for the ground, but for
some reason with depth clamping enabled. The flickering happens if Xemu
clips the ground triangles, but the exact same shadow triangles are depth
clamped, so there are small differences in the coordinates. The shadows
are drawn with depth function GL_EQUAL so there is no tolerance for any
differences. Clipping in the fragment shader solves the problem because
the ground and shadow triangles remain exactly the same regardless of
depth clipping/clamping. For some performance gain, it might be a good
idea to cull triangles by depth in the geometry shader, but this is not
implemented here.

In the programmable vertex shader we always multiply position output by w
because this improves numerical stability in subsequent floating point
computations by modern GPUs. This usually means that the perspective
divide done by the vertex program gets undone.

The magic bounding constants 5.42101e-020 and 1.884467e+019 are replaced
by 5.421011e-20 and 1.8446744e19, i.e. more decimals added. This makes the
32-bit floating point numbers represent exactly 2^(-64) and 2^64 (raw bits
0x1f800000 and 0x5f800000) which seem more likely the correct values
although testing with hardware was not done to this precision.

Testing indicates that the same RCC instruction magic constants are also
applied to both fixed function and programmable vertex shader w-coordinate
output. This bounding replaces the special test for w==0.0 and abs(w)==inf
which used to set vtx_inv_w=1.0 (which did not match Xbox hardware
behaviour.)
2025-03-08 14:54:18 -07:00
Erik Abair f701573d44 nv2a: Use rounded values for alpha testing 2025-03-05 17:12:14 -07:00
Matt Borgerson 6c389194b6 nv2a/psh: Remove unused arguments in string format 2025-01-07 00:52:51 -07:00
Matt Borgerson d76898f63b nv2a: Fix variable shadowing complaints 2025-01-07 00:52:51 -07:00
Matt Borgerson 6ac52147a4 nv2a/psh: Remove function scope variable i, which was being shadowed 2025-01-07 00:52:51 -07:00
Matt Borgerson 8f478e017a nv2a/psh: Handle 3D textures in BUMPENVMAP[_LUM] modes 2024-12-31 03:17:52 -07:00
Matt Borgerson 76e2b779e3 nv2a/psh: Handle rect tex on project3d 2024-12-31 01:37:05 -07:00
Matt Borgerson 62acb2db7e nv2a/psh: Drop rect_tex assertion 2024-12-31 01:37:05 -07:00
Matt Borgerson 1c38a0a42b nv2a/psh: Normalize coords at sample time 2024-12-31 01:37:05 -07:00
Matt Borgerson ec59148333 nv2a: Normalize unnormalized texture coordinates in shader 2024-12-31 01:37:05 -07:00
Matt Borgerson 567bc33a70 nv2a/glsl: Fix project2d usampler lookup 2024-12-31 01:37:05 -07:00
Matt Borgerson 017444b8a0 nv2a/glsl: Ensure sampler type matches texture dimensionality 2024-12-31 01:37:05 -07:00
Matt Borgerson 36e7cca1e9 nv2a/glsl: Initialize vars 2024-12-31 01:37:05 -07:00
Matt Borgerson b9e68a760b nv2a/vk: Fix shadowmap readback in frag shader 2024-12-31 01:37:05 -07:00
Matt Borgerson 2bb2084ece nv2a/vk: Use textureLod in psh_append_shadowmap 2024-12-31 01:37:05 -07:00
Matt Borgerson a5385803db nv2a: Add Vulkan renderer 2024-12-31 01:37:05 -07:00