6
« on: January 11, 2013, 06:17:14 am »
Alright so I've spent the past few days reading up on shaders. I know I'm probably going to get scolded and/or flamed for some/all of these but I figured I'd ask here. I'm trying to grasp a few things about shaders before I go about doing anything serious with them.
Here is a list of questions that have been on my mind for a while now and that pertain almost specifically to SFML (for the most part). I realize there are a lot, but hopefully a few of them can be answered at the least.
- To clip drawing textures, would I use a fragment shader as opposed to a vertex shader (and update the bounds using parameters?) then setting the alpha to 0 if the pixel lies outside of the bounds? My current understanding of shaders says yes but more or less I'd like some confirmation that I'm not too entirely crazy.
- Are shaders faster/more ideal than using sf::Sprite and an sf::Texture to draw images each frame?
- What's the difference (internally) between drawing an sf::Sprite with a texture and just a set of polygons with a shader that draws a texture specified? Is there any advantage? If SFML isn't using a built-in shader to do this, how is SFML drawing a texture to the screen?
- If shaders -are- faster, to draw an image with a shader (assuming the shader has been passed the appropriate texture as a parameter) would I just draw four points do the draw() method and then pass the shader as part of the render state?
- Are `uniform` constants (variables) in shaders just the parameters set by SFML's setParameter() method, verbatim?
- If so, what happens when I want to use a uniform constant that hasn't been set by the application? Is it undefined behavior?
- Are parameters sticky - meaning, if I set a parameter one frame, and not the next, does the value from the first time I set the parameter "stick" (persist) throughout the rest of the frames until it is explicitely set again?
- Can/will shaders lock up the computer if something unexpected happens (like drivers do)?
- For maximum compatibility (the application in question is not a game) should I target the lowest possible shader version?
Keep in mind I've been reading tons of articles on the structure of a shader, the pipeline flow, etc. However, I'm still trying to map out how exactly to incorporate shaders into my program. I've already decided to use them because I know there will be a direct advantage over my previous methods.