I’ve been trying to optimize various parts of an application for a couple of weeks now. One of the things I’ve been focusing on was picking. The way this was done was by rendering all geometry in a second pass, only drawing an ID for each primitive. Both this pass and the color pass was using the fixed function pipeline.
I was hoping that by using shaders, I could draw both color and ID in one pass. Said and done, things got slower. Right now, I only have one shader which I only bind once, and this shader has one uniform (a vec3 for the ID) which I only look up the location for once. I set this uniform to a different value for every primitive (sphere, cone, cylinder etc). To me, it seems like this is where the overhead would come from. Is it possible that the pipeline is being flushed in order to not overwrite the uniform while being used by the previous render call?
The shaders doesn’t do anything particularly fancy, so it shouldn’t be that either. Since everything was set up to use the fixed function pipeline, I’m using those attributes (such as gl_Color) as much as possible in the shaders as well. Which btw seems to cause an entirely different problem, namely that several primitives seem to get rendered without gl_Color etc being changed in between them… Less concerning for now, but perhaps you can explain this behaviour as well?
I get about 90 fps on one computer when using the old picking, 80 when I’m using the shader picking. I’m not sure about what hardware it has, but I’ve been told that it has a “good graphics card.”
As you can see, I haven’t even tried making it pretty or fast or anything, I just wanted to get a rough estimate of how it would work for now. And as I said, it doesn’t do anything fancy, so it would be weird if this is what’s slowing me down.
I agree that only rendering “one pixel” would probably be a better solution, quite embarrasing that I didn’t think of that… Either way though, I still feel like this picking would be faster than the old one.
I don’t see anything wrong with the code, except the need to get rid of ‘if’. There is no reason why pick_alpha is not passed directly as ‘pick_id.w’. Paste the updated FPS after you finish with this, please.
Although unlikely that a single if-statement would give such an overhead, I did what you said, and it didn’t give any noticable difference. Please keep in mind that I’ve gotten rid of an entire rendering pass through all the geometry, yet it got slower. That’s quite a significant overhead which I can’t seem to track down.
I appreciate any ideas you might have that might explain this!