1

I want to draw geometric primitives in Blenders Game Engine by using a GLSL Shader.

For example:

glBegin(GL_LINE_STRIP);
    glVertex2f(-0.6,0.3);
    glVertex2f(-0.3,0.2);
    glVertex2f(-.65, 0.2);
    glVertex2f(-0.4, 0.05);
glEnd();

How to wrap this into VertexShader = """ ...code... """ or does it even belong there at all since this shape has nothing to do with a scene-objects vertecies? And do I enable it in the Logic Editor to an object by using an always sensor that links to the script in order for it to work?

All I want to do is to draw a line, along some x and y coordinates (z is 0 in this case). Also it should be scalable enough to draw an entire array of values, but after hours of research i'd be happy to just get three points to work! A simple example would be appreciated a lot.

So its all about how to geht basic stuff like this displayed in BGE by using gpu based GLSL: http://www.informit.com/articles/article.aspx?p=328646&seqNum=6 or here on stackoverflow Is it possible to draw line thickness in a fragment shader?

PS. I could not find anything fitting for my Problem on http://en.wikibooks.org/wiki/GLSL_Programming

And Rasterizer.drawLine() from bge doesn't work for my purposes, since it behaves odd, disappears immediately and the points cant be accessed/edited/moved afterwards.

Community
  • 1
  • 1
atta_bug
  • 11
  • 1
  • The best you could do with this is hardcode the vertex positions into a vertex shader and use the `gl_VertexID` to index into an array of constant positions... you cannot create new vertices with a vertex shader. You can create new vertices with a geometry shader, but even then you'll be dealing with hard-coded vertices and will get worse performance than the vertex shader solution. – Andon M. Coleman Mar 11 '14 at 22:27
  • So for the vertex shader I would need to start with an object that has n vertices, whose positions than can be altered, saved, altered, saved again and so on? How would a geometry shader with my example look in the blender text editor? I'm still trying to get an overview of all actions necessary for GLSL code to work in blender, but now I still don't know how to proceed, even though a snippet of information is appreciated as well. I'm researching geometry shader now.. A short example would be great + information which checkboxes to enable and how to link it in logic etc. – atta_bug Mar 11 '14 at 23:02
  • No, vertex shaders do not alter vertices. What they do are transform the vertices in a vertex buffer into the appropriate coordinate space and then pass a copy of the newly transformed vertex down the graphics pipeline. You can use transform feedback to save these otherwise temporary vertices, but in my mind that is steering everything way off track. I honestly do not know how a Geometry Shader would work with Blender or if it even exposes the necessary API features to use them; I have never used Blender. – Andon M. Coleman Mar 11 '14 at 23:15
  • Thanks. If i get you right the altering and saving (to the temporary storage that is sustained as long as the shader runs) happens by transform feedback. How would I apply the above example with that? Using a loop through list(gl_VertexID), and inside the loop "if gl_VertexID==1 then vertposition = (-0.6,0.3) else if gl_VertexID==2 then vertposition = (-0.3,0.2) else if gl_VertexID==3 then vertposition = (-.65, 0.2) end if? – atta_bug Mar 11 '14 at 23:51
  • Something to that effect, though generally you would use an array of values. This would make it little more than a fancy lookup table. – Andon M. Coleman Mar 12 '14 at 01:17

0 Answers0