// fragment shader to demo position to texture and texture to position mapping uniform sampler2D grid; void main() { // base color, with alpha channel for grid masking gl_FragColor = vec4(gl_Color.xyz,-1); // overlay red grid for texture coordinates gl_FragColor = mix(gl_FragColor, vec4(1,0,0,1), texture2D(grid, 2.*gl_TexCoord[0].xy).r); // overlay green grid for position gl_FragColor = mix(gl_FragColor, vec4(0,1,0,1), texture2D(grid, gl_TexCoord[1].xy/gl_TexCoord[1].w).r); // toss fragments not on grid if (gl_FragColor.a < 0.) discard; }