I'm am currently trying to draw shapes or at least the equivalent of geometry in ThreeJS r128 with exclusively with shaders.
The common way to draw stuff on the screen with this library consist of creating a mesh with a geometry (here is the boilerplate code for project creation) associated to it. After the creation of that object, we can apply a shader to this new component via the ShaderMaterial class.
However, I can't find how to render the shader on the scene rather than on an object. With OpenGL Shading Language (GLSL), we can actually draw shapes on the screen without having vertices. That's what I am aiming for, but it seems that I am tangled up in this rendering system.
Is it even possible to render only with the shaders in ThreeJS ?
For testing, here is a function to create a filled circle with shader:
Fragment Shader:
uniform vec2 u_resolution;
float circleShape(vec2 position, float radius){
return step(radius, length(position));
}
void main(){
vec2 position = gl_FragCoord.xy / u_resolution;
float circle = circleShape(position, 0.3);
vec3 color = vec3(circle);
gl_FragColor = vec4(color, 1.0);
}
Here is my Vertex Shader too just in case:
void main(){
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}