Make shader clip space consistent across APIs and projection matrices.

- All shaders are expected to output clip space values that are effectively y-up, with [-1, 1] z, in NDC.
- The transform to a backend's expected clip space values from the above range now happens after user vertex shader code is run, instead of inside a projection matrix.
- Projection matrices no longer need to be flipped when rendering to a canvas versus the main screen.

This means custom projection matrices might need to be altered to account for the more consistent range.
This commit is contained in:
Sasha Szpakowski
2024-03-23 22:00:02 -03:00
parent 698d305212
commit 7bfbd647ba
11 changed files with 93 additions and 68 deletions
+3 -6
View File
@@ -465,12 +465,6 @@ love::graphics::GraphicsReadback *Graphics::newReadbackInternal(ReadbackMethod m
return new GraphicsReadback(this, method, texture, slice, mipmap, rect, dest, destx, desty);
}
Matrix4 Graphics::computeDeviceProjection(const Matrix4 &projection, bool /*rendertotexture*/) const
{
uint32 flags = DEVICE_PROJECTION_FLIP_Y;
return calculateDeviceProjection(projection, flags);
}
void Graphics::backbufferChanged(int width, int height, int pixelwidth, int pixelheight, bool backbufferstencil, bool backbufferdepth, int msaa)
{
bool sizechanged = width != this->width || height != this->height
@@ -1133,6 +1127,9 @@ void Graphics::applyShaderUniforms(id<MTLRenderCommandEncoder> renderEncoder, lo
// Same with point size.
builtins->normalMatrix[1].w = getPointSize();
uint32 flags = Shader::CLIP_TRANSFORM_Z_NEG1_1_TO_0_1;
builtins->clipSpaceParams = Shader::computeClipSpaceParams(flags);
builtins->screenSizeParams = Vector4(getPixelWidth(), getPixelHeight(), 1.0f, 0.0f);
auto rt = states.back().renderTargets.getFirstTarget();
if (rt.texture.get())