three
Version:
JavaScript 3D library
106 lines (71 loc) • 2.41 kB
JavaScript
export const vertex = /* glsl */`
// This is used for computing an equivalent of gl_FragCoord.z that is as high precision as possible.
// Some platforms compute gl_FragCoord at a lower precision which makes the manually computed value better for
// depth-based postprocessing effects. Reproduced on iPad with A10 processor / iPadOS 13.3.1.
varying vec2 vHighPrecisionZW;
void main() {
vHighPrecisionZW = gl_Position.zw;
}
`;
export const fragment = /* glsl */`
uniform float opacity;
varying vec2 vHighPrecisionZW;
void main() {
vec4 diffuseColor = vec4( 1.0 );
diffuseColor.a = opacity;
// Higher precision equivalent of gl_FragCoord.z. This assumes depthRange has been left to its default values.
float fragCoordZ = 0.5 * vHighPrecisionZW[0] / vHighPrecisionZW[1] + 0.5;
gl_FragColor = vec4( vec3( 1.0 - fragCoordZ ), opacity );
gl_FragColor = packDepthToRGBA( fragCoordZ );
gl_FragColor = vec4( packDepthToRGB( fragCoordZ ), 1.0 );
gl_FragColor = vec4( packDepthToRG( fragCoordZ ), 0.0, 1.0 );
}
`;