engine icon indicating copy to clipboard operation
engine copied to clipboard

[Impeller] Map to Metal's NDC in the perspective projection utility

Open bdero opened this issue 3 years ago • 0 comments

Currently the perspective transform assumes OpenGL's NDC depth range of -1 to 1. This patch switches to Metal/Vulkan's range of 0 to 1.

For GLES, the compiler is already emitting the appropriate clip space conversion. For example, when given the following vertex shader as input...

void main() {
  gl_Position = vert_info.mvp * vec4(position, 1.0);
}

...the compiler emits the following when targeting GLES:

void main()
{
    gl_Position = vert_info.mvp * vec4(position, 1.0);
    gl_Position.z = 2.0 * gl_Position.z - gl_Position.w;
}

Noticed this problem in impeller-cmake-example.

image

bdero avatar Aug 13 '22 11:08 bdero