SFML community forums

General => Feature requests => Topic started by: tgm on August 30, 2010, 06:56:49 pm

Title: Vertex Shader
Post by: tgm on August 30, 2010, 06:56:49 pm
Hi Laurent
Why don't you allow to set the VertexShaderSrc? This is quite useful even for normal sprites in a deferred rendering approach. And as far as i can see the changes are minimal (adding a second parameter to LoadFromFile).
Am i missing something?
I did add a member char* vertexShaderSrc to the sf::Shader that is used instead of vertexSrc if it is non-null...
greetz TGM
Title: Vertex Shader
Post by: Laurent on August 30, 2010, 07:04:54 pm
Hi

I already answered to this feature request, you'll find my answer(s) on this forum ;)
Title: Vertex Shader
Post by: tgm on August 30, 2010, 09:29:36 pm
shit sry  :oops:
*edit*
I think my point is still valid:
Vertexshader can (and are) used to transform texture coordinates.

(http://i14.photobucket.com/albums/a322/TheGameMaker/lights.png)
(http://i14.photobucket.com/albums/a322/TheGameMaker/lights2.png)
(http://i14.photobucket.com/albums/a322/TheGameMaker/lights3.png)

over 500 lights fluidly with full normal mapping -> only possible with vertex shader. (screenshot didn't vsync.. but hey i think you get the idea)
*edit2*
sry for that oversize images
Title: Vertex Shader
Post by: Laurent on August 30, 2010, 10:53:04 pm
Last time I implemented lighting with a vertex shader was a long time ago, can you explain how exactly you implement with SFML and a vertex shader?
Title: Vertex Shader
Post by: tgm on August 30, 2010, 11:08:38 pm
Actually the lighting is done in a pixelshader...
The vertexshader is only needed to calculate texcoords.
I render 1 pass colors only into a target,
I render 1 pass normals only (world coords) into a target.
Then I use small sprites for every light, using 3 textures:
the 2 rendertargets and a mask.
And this is where the Vertexshader is needed: this sprite has a second set of texcoords containing its world coordinates. This coordinates are used to make a lookup in the color&normal buffer. Then we I can calculate the light influence. Of this light in the world as texture of my sprite. The sprite is finally blended additively. and dadada.. very little overhead for pixel not being reached by the light. Its called "Deferred Lighting"
(sry its late..)
greetz
Title: Vertex Shader
Post by: Laurent on August 30, 2010, 11:27:40 pm
Ok I see. So it would be useful to people who want to implement deferred lighting with SFML... which seems too specific to me.

From the point of view of a regular user, this class would be useless, nobody would be able to get something interesting from it.

SFML doesn't aim at providing a complete OpenGL wrapper, but rather a simple and consistent API for 2D graphics. For this kind of advanced/fancy stuff, you'd better use OpenGL directly.

I hope that you understand my point of view ;)
Title: Vertex Shader
Post by: mooflu on February 21, 2011, 02:45:17 am
Sorry to resurrect an old thread. I've also found setting a custom vertex shader useful.

I realize you want to keep your 2D api simple, but as a compromise, maybe you could add a member variable for the default vertex shader (which you have to setup anyway) and make the shader strings and CompileProgram protected. That way, those of us needing it can derive from sf::Shader.
Title: Vertex Shader
Post by: Laurent on February 21, 2011, 07:37:45 am
I'll think about it, yes.