GLSL built-in function
texture2DProj()
Samples a 2D texture after dividing by the final coordinate.
Demo version: GLSL ES 1.00 / WebGL 1Demo stage: Fragment
Syntax
vec4 texture2DProj(sampler2D sampler, vec3 coord)Parameters
- sampler
- Bound fixture texture
- coord
- Lookup coordinate
Return value
A filtered vec4 sampled after dividing the first two coordinate components by the last component.
Live example
Edit the code and the preview updates as you type.
What texture2DProj does
Samples a 2D texture after dividing by the final coordinate.
Read the preview
vec3(uv*(0.3+uv.x),0.7) makes the effective lookup uv*(0.3+uv.x)/0.7. Change the final 0.7 to 1.0 to reduce the coordinate expansion and reveal a different portion of the grid.
Core call
texture2DProj(u_texture,vec3(uv*(0.3+uv.x),0.7)).rgb;
The divisor must not be zero; the vec4 overload divides by q.
Experiment
Replace the projected argument with vec3(uv,1.0). Division by 1 leaves uv unchanged, so the grid and letters return to their undistorted layout.