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

Author Topic: The Ability to Pass Floats To/From Shaders  (Read 3821 times)

0 Members and 1 Guest are viewing this topic.

k6l2

  • Newbie
  • *
  • Posts: 8
    • View Profile
The Ability to Pass Floats To/From Shaders
« on: October 23, 2015, 01:57:30 am »
Lol like... why is this not a feature?  I can't even pass an array of floats to my fragment shader...  What am I supposed to do?  Convert each float to a 32-bit integer via static_cast, and pass 4 pieces of that integer to the shader via the r-g-b-a components of each pixel of a texture, then convert it back somehow in the shader via the sampler2D?  Ridiculous.  :o

And if I want to use a shader to output something to a render texture, the reverse problem applies because SFML doesn't use floats for components of sf::Color, which is insane.  I mean, I know it's supposed to make it look cleaner or easier or whatever, but Uint8 components just don't make sense and form an unnecessary limitation on the developer.  Why not just store color components as floats in sf::Color, and give the user a better class interface to use either Uint8/float depending on their code?

Or maybe there is just some secret way of doing this in the API that I just haven't found yet.  Maybe someone can enlighten me?

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: The Ability to Pass Floats To/From Shaders
« Reply #1 on: October 23, 2015, 02:13:56 am »
The shader class in SFML right now is really just a wrapper for loading and compiling shaders from source. It provides some functions to set uniforms and thats about it. You can get the native handle which you need in order to use attribute pointers (Which is what I assume you are talking about). There is a branch in development in GitHub right now for API changes regarding the shader class and uniforms but nothing for attributes.

k6l2

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: The Ability to Pass Floats To/From Shaders
« Reply #2 on: October 23, 2015, 02:24:02 am »
Word, thanks for the info, Gambit.   Yea that was what I was planning on doing.  Hopefully someone fixes sf::Color while they're at it.

Gambit

  • Sr. Member
  • ****
  • Posts: 283
    • View Profile
Re: The Ability to Pass Floats To/From Shaders
« Reply #3 on: October 23, 2015, 03:46:35 am »
Is there a problem with sf::Color? Also you are more than welcome to contribute directly to SFML via pull request if you read (And abide by) the contributing guide.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: The Ability to Pass Floats To/From Shaders
« Reply #4 on: October 23, 2015, 08:35:24 am »
Please calm down and explain your problem. I have no idea what you're talking about, because you're just complaining. The title says float components (which is already supported), and you're talking about colors, I have I no idea why.

Anyway, whatever you're trying to say, have a look at this first:
https://github.com/SFML/SFML/pull/983
Laurent Gomila - SFML developer

k6l2

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: The Ability to Pass Floats To/From Shaders
« Reply #5 on: October 24, 2015, 02:17:32 am »
Please calm down and explain your problem.
I am calm, and I did explain the problem.  Gambit then told be about how the Shader interface was changing, and I was satisfied by his answer.

The float components of sf::Color was just another thing that was annoying to me because there was no interface to pass float Vectors in the API right now, and the pull request you just linked satisfies that feature request as well.

Also, I didn't know that GL_RGBA uses 8-bit components before I asked lol..  ;D

Edit: also yea my title was wrong/misleading, because I was specifically talking about array uniforms, not just float uniforms, sorry about that
« Last Edit: October 24, 2015, 02:20:14 am by k6l2 »