Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Shaders and drawing vertex array  (Read 1591 times)

0 Members and 1 Guest are viewing this topic.

Avonclese

  • Newbie
  • *
  • Posts: 7
    • View Profile
Shaders and drawing vertex array
« 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!


eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: Shaders and drawing vertex array
« Reply #1 on: October 23, 2017, 05:27:48 pm »
Afaik you need to draw it separately as a shader always applies to all vertices or fragments that were passed along.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Shaders and drawing vertex array
« Reply #2 on: October 23, 2017, 06:30:33 pm »
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.
Laurent Gomila - SFML developer