How does the point shader work with custom attributes?

edited October 2016 in GLSL / Shaders

Hi, I'm trying to make a particles system where particles positions and velocities are calculated with a shader. I'm stuck because I cannot understand how some parameters of the point shader work.

In particular I cannot get a point shader to take custom attributes. Is that possible?

1) I tried the attrib() function which works fine with triangles and QUADS but when i set the shape to be POINTS type then it stops working.

2) I tried to pass some data using the default vertex attributes such us 'uv' or 'normal' but it does not work either.

3) So I tried to have a solution based on QUADS instead of using a point shader, but then, when I do like in the Static Particles Retained example and use createShape(PShape.GROUP) again custom attributes stop working and I get a null Pointer Exception :

`

particles = createShape(PShape.GROUP) ;

sprite = loadImage("sprite.png");

for (int n = 0; n < npartTotal;  n++) {

float cx = random(-500, +500);
float cy = random(-500, +500); 
float cz = random(-500, +500);

PShape part = createShape();
part.beginShape(QUAD);
part.noStroke();
part.tint(255);
part.texture(sprite);
part.normal(0, 0, 1);

part.attrib("custom",1.0); //this does not work

part.vertex(cx - partSize/2, cy - partSize/2, cz, 0, 0);
part.vertex(cx + partSize/2, cy - partSize/2, cz, sprite.width, 0);
part.vertex(cx + partSize/2, cy + partSize/2, cz, sprite.width, sprite.height);
part.vertex(cx - partSize/2, cy + partSize/2, cz, 0, sprite.height);    
part.endShape();    
particles.addChild(part);`

4) So I decided to use normal QUADS, without groups or anything, and seems to work, but at that point I'm stuck because I can't get each quad to act like a billboard and always face the screen. Is there a way to have quads always facing the Camera?

It would be very practical if point shaders support custom attributes.

5) I can't get point shader to use strokeWeight attribute per vertex, like line shader does. So what is the correct way to render each point with a different radius?

Last question! Taking inspiration from the advanced openGL example I was able to render a buffer of vertices with the pointSprite feature of openGL where each vertex corresponds to a point. I was able to pass textures and custom attributes such as uv, size, etc, but at that point I was just using low level calls and processing was not very useful.

So, Is there a way to render each vertex as a point sprite using just the processing API?

Sign In or Register to comment.