screenCoordinate
In a TSL fragment shader, provides the physical pixel coordinates (vec2) of the current fragment on the screen, used for implementing screen-space effects.
Core Advantages
Enables easy creation of screen-space effects (like post-processing filters) that are independent of the 3D scene, and provides pixel-perfect integer coordinates crucial for effects like grids, dithering, or pixel art.
Common Uses
Creating CRT scanlines or screen grid patterns using the modulo operator.
Implementing vignette effects by calculating the distance to the screen center.
Serving as a lookup coordinate into a dither matrix for color dithering or halftoning algorithms.
How to adjust
This node itself is not adjustable. Its effect is altered by performing math operations on its output `vec2` coordinate. For example: dividing by the screen resolution yields normalized UVs; using the modulo operator creates repeating patterns; calculating the distance from the screen center generates radial gradients.
Code Examples
1// Convert screen pixel coordinates to a tile index
2const tileIndex = floor( screenCoordinate.div( TILE_SIZE ) );
3
4// Calculate a pattern value of 0 or 1 based on the index's parity sum
5const pattern = mod( add( tileIndex.x, tileIndex.y ), 2.0 );
6
7// Mix between black and white using the pattern to create a checkerboard
8const finalColor = mix( whiteColor, blackColor, pattern );