I've tried looking everywhere, but I just don't get it. How is multiple shaders assigned to a mesh if you can only bind a single shader in OpenGL?

Assume I have a mesh with a texture shader and now I do a ray-cast from the mouse position to select the object from the editor. In this case I would like to apply a selection shader that highlights that the mesh is selected, but still preserves the texture shader of the mesh.

I want to apply the selection shader on top of the texture shader of the mesh. How is this generally done in game engines?

One way of doing this would be to make a completely third shader that is combination of both shaders and just apply the third shader. But that doesn't seem efficient and would become tedious when trying to add new shaders; now you have to specify a selection shader for every shader in the game, in case it's selected in the editor.

Any help is appreciated and if you can guide to some reading material that would be amazing.

  • $\begingroup$ "mesh with a texture shader" What is a "texture shader"? $\endgroup$ – Nicol Bolas Oct 5 '19 at 20:10
  • $\begingroup$ "mesh with a texture shader" what I meant with that was a shader that takes in a sampler2D texture and samples the coordinates and outputs the frag color. $\endgroup$ – FableProtector Oct 5 '19 at 20:35
  • $\begingroup$ You can use the stencil buffer to create a mask. Then use that mask to apply your selection shader only on the part of the screen that the mask covers. $\endgroup$ – lightxbulb Oct 5 '19 at 21:38
  • $\begingroup$ Just because you think X is one thing does not mean a lower level system considees this to be true. Nothing stops the game engine from drawing the thing you call a mesh as 2 separate meshes, or lump what you call 2 shaders into one. $\endgroup$ – joojaa Oct 10 '19 at 14:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.