Files
filament/shaders/src/post_process.vs
Pixelflinger 13cfad43b7 Use "inverted-Z" depth buffer
This significantly improve the depth-buffer resolution utilization
through the near-infinity range on Metal and Vulkan.

On OpenGL, this benefit is only seen when glClipControl is available.

The user-facing clip plane is unchanged [-1,1], the conversion
happens in filament's vertex shaders.


The bulk of this change consists in:

- invert the clip space's z in the vertex shader
- clear the depth buffer with 0
- invert all depth function comparisons
- fix all screen-space effects, e.g. ssao, DoF
- fix shadows and shadow biases
- use floating-point depth
- add a driver API to query which clip-space is used
- add glClipControl support to the gl backend
2020-09-01 09:46:46 -07:00

39 lines
1.2 KiB
GLSL

void main() {
// Initialize the vertex shader inputs to sensible default values.
PostProcessVertexInputs inputs;
initPostProcessMaterialVertex(inputs);
inputs.normalizedUV = position.xy * 0.5 + 0.5;
inputs.texelCoords = inputs.normalizedUV * frameUniforms.resolution.xy;
// In Vulkan and Metal, texture coords are Y-down. In OpenGL, texture coords are Y-up.
#if defined(TARGET_METAL_ENVIRONMENT) || defined(TARGET_VULKAN_ENVIRONMENT)
inputs.texelCoords.y = frameUniforms.resolution.y - inputs.texelCoords.y;
inputs.normalizedUV.y = 1.0 - inputs.normalizedUV.y;
#endif
gl_Position = getPosition();
// Adjust clip-space
gl_Position.z = dot(gl_Position.zw, frameUniforms.clipControl.xy);
// Invoke user code
postProcessVertex(inputs);
vertex_uv = inputs.texelCoords;
// Handle user-defined interpolated attributes
#if defined(VARIABLE_CUSTOM0)
VARIABLE_CUSTOM_AT0 = inputs.VARIABLE_CUSTOM0;
#endif
#if defined(VARIABLE_CUSTOM1)
VARIABLE_CUSTOM_AT1 = inputs.VARIABLE_CUSTOM1;
#endif
#if defined(VARIABLE_CUSTOM2)
VARIABLE_CUSTOM_AT2 = inputs.VARIABLE_CUSTOM2;
#endif
#if defined(VARIABLE_CUSTOM3)
VARIABLE_CUSTOM_AT3 = inputs.VARIABLE_CUSTOM3;
#endif
}