shaders for standard drawing of points lines and planes (with 3d camera transform)
| 61 | public class Standard { |
| 62 | private final Camera camera; |
| 63 | |
| 64 | BaseMesh triangles = BaseMesh.triangleList(0, 0); |
| 65 | MeshBuilder triangles_builder = new MeshBuilder(triangles); |
| 66 | BaseMesh lines = BaseMesh.lineList(0, 0); |
| 67 | |
| 68 | MeshBuilder lines_builder = new MeshBuilder(lines); |
| 69 | BaseMesh points = BaseMesh.pointList(0); |
| 70 | MeshBuilder points_builder = new MeshBuilder(points); |
| 71 | |
| 72 | Shader trianglesAndLinesShader = new Shader(); |
| 73 | |
| 74 | Shader pointShader = new Shader(); |
| 75 | |
| 76 | public Standard(Camera camera) { |
| 77 | this.camera = camera; |
| 78 | trianglesAndLinesShader.addSource(Shader.Type.vertex, "#version 410\n" + |
| 79 | "layout(location=0) in vec3 position;\n" + |
| 80 | "layout(location=1) in vec4 color;\n" + |
| 81 | "out vec4 vcolor;\n" + |
| 82 | "uniform mat4 _p;\n" + |
| 83 | "uniform mat4 _mv;\n" + |
| 84 | "void main()\n" + |
| 85 | "{\n" + |
| 86 | "gl_Position = _p * _mv * vec4(position, 1.0); \n" + |
| 87 | "vcolor = color;\n" + |
| 88 | "}"); |
| 89 | |
| 90 | trianglesAndLinesShader.addSource(Shader.Type.fragment, "#version 410\n" + |
| 91 | "layout(location=0) out vec4 _output;\n" + |
| 92 | "in vec4 vcolor;\n" + |
| 93 | "uniform float opacity; \n" + |
| 94 | "uniform float zoffset; \n" + |
| 95 | "void main()\n" + |
| 96 | "{\n" + |
| 97 | " float f = mod(gl_FragCoord.x-gl_FragCoord.y,20)/20.0;\n" + |
| 98 | " f = (sin(f*3.14*2)+1)/2;" + |
| 99 | " f = (smoothstep(0.45, 0.55, f)+1)/2;" + |
| 100 | " _output = vec4(abs(vcolor.xyzw));\n" + |
| 101 | " if (vcolor.w<0) _output.w *= f;" + |
| 102 | " _output.w *= opacity;\n" + |
| 103 | " gl_FragDepth = gl_FragCoord.z+zoffset;\n" + |
| 104 | // " _output = vec4(1,0,1,1);" + |
| 105 | "}"); |
| 106 | |
| 107 | // camera |
| 108 | trianglesAndLinesShader.attach(new Uniform<Mat4>("_p", () -> camera.projectionMatrix(drawing==null ? 0 : drawing.displayZ))); |
| 109 | trianglesAndLinesShader.attach(new Uniform<Mat4>("_mv", () -> camera.view(drawing==null ? 0 : drawing.displayZ))); |
| 110 | trianglesAndLinesShader.attach(new Uniform<Float>("opacity", () -> 1f)); |
| 111 | |
| 112 | |
| 113 | pointShader.addSource(Shader.Type.vertex, "#version 410\n" + |
| 114 | "layout(location=0) in vec3 position;\n" + |
| 115 | "layout(location=1) in vec4 color;\n" + |
| 116 | "layout(location=2) in vec2 pointControl;\n" + |
| 117 | "out vec4 vcolor_q;\n" + |
| 118 | "uniform mat4 _p;\n" + |
| 119 | "uniform mat4 _mv;\n" + |
| 120 | "out vec2 pc_q;\n" + |
nothing calls this directly
no test coverage detected