SFML community forums
Help => Graphics => Topic started by: Avonclese on October 23, 2017, 02:19:30 pm
-
Hello! Quick question regarding shaders and vertex arrays
Scenario...
Basic 2D game where I render 500 objects in a single draw call by having all their vertices combined in a single vertex array. Works perfectly.
I want to use a shader to apply some fancy shading to just ONE of those objects.
I supply my shader as an argument in the draw call, so it will therefore affects everything drawn.
So my question is: is it possible to have a shader only affect one object (set of vertices) through a single draw call or will I have to draw the object separately on its own?
Thank you!
-
Afaik you need to draw it separately as a shader always applies to all vertices or fragments that were passed along.
-
You could use an unused attribute (color alpha, texture coordinate, ...) as a flag to identify which vertices need to be processed by the shader. Then the shader can interpret this value and react accordingly.