Page 2 of 2

Re: [SOLVED] Problem with shaders (especially with texture_coords)

Posted: Sun Nov 04, 2018 11:38 am
by Nelvin
Not sure if I missed something, but can't you just create a mesh for the circle, rect etc. including the texture uvs/vertex colors or whatever you need?

Re: Problem with shaders (especially with texture_coords)

Posted: Sun Nov 04, 2018 1:43 pm
by LuaIsLife
pgimeno wrote: Sun Nov 04, 2018 11:21 am
LuaIsLife wrote: Sun Nov 04, 2018 5:33 am

Code: Select all

  vec4 pixel = Texel(image, uvs);
This will return always white. Maybe you meant

Code: Select all

  vec4 pixel = Texel(image, uvs) * color;
?
.. holy... Yes, that did it.... Care to explain why the old code did work for all my "sprites" (images) but not for the stuff like circles/rectangles but the one with the "* color" part does?

Thanks!

Re: Problem with shaders (especially with texture_coords)

Posted: Sun Nov 04, 2018 2:39 pm
by pgimeno
LuaIsLife wrote: Sun Nov 04, 2018 1:43 pm .. holy... Yes, that did it.... Care to explain why the old code did work for all my "sprites" (images) but not for the stuff like circles/rectangles but the one with the "* color" part does?
Sure. Don't confuse the texture texel colour with the tinting colour set by calling love.graphics.setColor.

love.graphics.setColor is used to tint whatever you draw. This tinting is done through component-wise multiplication of the texel colour and the setColor colour, and is performed in the shader. That colour is received in the 'color' parameter of the effect() function. According to the wiki, there is always a shader active, even if you don't define one. Take a look at the default LÖVE shader in love.graphics.newShader#Notes_2. Note how it multiplies by 'color' so that it can tint what you draw!

The texture in the default primitives (circle, rectangle, line...) is a 1x1 white pixel (I'm not 100% sure if that's the case, but you can certainly think of it this way). That means that its colour is R=1, G=1, B=1, A=1. Those values, multiplied by the setColor value, give you the setColor value unchanged, therefore all those primitives are drawn with that colour. So, when you draw a coloured primitive, what you're actually doing is tinting its white texture. And for that to work, the shader must support tinting.

The texture in your images is the image itself. If you don't multiply the texture colour by the 'color' parameter, you can't tint your images using love.graphics.setColor. I doubt you're using setColor for tinting your images (other than to set it to 1,1,1,1), that's why when drawing your images, you don't see a difference between the version that multiplies by 'color' and the version that doesn't.

Apologies if the explanation isn't too clear. I find it somewhat hard to explain.

Re: [SOLVED] Problem with shaders (especially with texture_coords)

Posted: Sun Nov 04, 2018 7:01 pm
by zorg
Nelvin wrote: Sun Nov 04, 2018 11:38 am Not sure if I missed something, but can't you just create a mesh for the circle, rect etc. including the texture uvs/vertex colors or whatever you need?
Just wanted to respond to this post as well; yes, afaik you can use custom meshes and even a 1*1px texture on it, with the correct uvs so that it'd work as "geometric primitives".