Skip to content

Instantly share code, notes, and snippets.

@gregtatum
Last active August 29, 2015 14:21
Show Gist options
  • Select an option

  • Save gregtatum/a069a0caddc73f09c5e2 to your computer and use it in GitHub Desktop.

Select an option

Save gregtatum/a069a0caddc73f09c5e2 to your computer and use it in GitHub Desktop.
//Use gl.POINTS to draw a dot
uniform vec3 color;
void main() {
// Map ( [0,0] , [1,1] ) => ( [-1,-1], [1,1] )
vec2 coord = ( gl_PointCoord - vec2(0.5, 0.5) ) * 2.0;
// Step it so that it's a hard transition
float alpha = step( 0.0, 1.0 - length( coord ) );
// Set the color to white with an alpha
gl_FragColor = vec4( color, alpha );
}
//Another method, with smoother borders
precision mediump float;
void main() {
// Map coord range ( [0,0] , [1,1] ) => ( [-1,-1], [1,1] )
vec2 coord = ( gl_PointCoord - vec2(0.5, 0.5) ) * 2.0;
float alpha = 1.0 - smoothstep(
0.9,
1.0,
length(coord)
);
vec3 color = vec3( 0.0, 0.5, 0.5 );
// Set the color to white with an alpha
gl_FragColor = vec4( color, alpha );
}
@MarkWissler
Copy link

So I'm just now getting around to these. They're not working right off the bat for my ThreeJS point cloud that's using these as its fragmentshader. I assume there's some config I'll have to do to my shaderMaterial? i.e. Whatever triggers the gl.enable(gl.BLEND)?

Edit: The shaderMaterial just needed the following properties added:

blending: THREE.NormalBlending,
depthTest: false,
transparent: true

Thanks, Greg! 👍

@MarkWissler
Copy link

Follow up question: Do you know of a way to draw circles and still depth test?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment