mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
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:
@@ -108,6 +108,14 @@ public:
|
||||
ACCESS_WRITE = (1 << 1),
|
||||
};
|
||||
|
||||
enum ClipSpaceTransformFlags
|
||||
{
|
||||
CLIP_TRANSFORM_NONE = 0,
|
||||
CLIP_TRANSFORM_FLIP_Y = 1 << 0,
|
||||
CLIP_TRANSFORM_Z_NEG1_1_TO_0_1 = 1 << 1,
|
||||
CLIP_TRANSFORM_Z_0_1_TO_NEG1_1 = 1 << 2,
|
||||
};
|
||||
|
||||
struct CompileOptions
|
||||
{
|
||||
std::map<std::string, std::string> defines;
|
||||
@@ -177,6 +185,7 @@ public:
|
||||
Matrix4 transformMatrix;
|
||||
Matrix4 projectionMatrix;
|
||||
Vector4 normalMatrix[3]; // 3x3 matrix padded to an array of 3 vector4s.
|
||||
Vector4 clipSpaceParams;
|
||||
Colorf constantColor;
|
||||
|
||||
// Pixel shader-centric variables past this point.
|
||||
@@ -212,6 +221,18 @@ public:
|
||||
**/
|
||||
static bool isDefaultActive();
|
||||
|
||||
/**
|
||||
* Used for transforming standardized post-projection clip space positions
|
||||
* into the backend's current clip space.
|
||||
* Right now, the standard is:
|
||||
* NDC y is [-1, 1] starting at the bottom (y-up).
|
||||
* NDC z is [-1, 1].
|
||||
* Pixel coordinates are y-down.
|
||||
* Pixel (0, 0) in a texture is the top-left.
|
||||
* Aside from NDC z, this matches Metal and D3D12.
|
||||
*/
|
||||
static Vector4 computeClipSpaceParams(uint32 clipSpaceTransformFlags);
|
||||
|
||||
/**
|
||||
* Returns any warnings this Shader may have generated.
|
||||
**/
|
||||
|
||||
Reference in New Issue
Block a user