[SOLVED] Problem with shaders (especially with texture_coords)

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Nelvin
Party member
Posts: 124
Joined: Mon Sep 12, 2016 7:52 am
Location: Germany

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

Post 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?
LuaIsLife
Prole
Posts: 12
Joined: Fri Nov 02, 2018 4:48 pm

Re: Problem with shaders (especially with texture_coords)

Post 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!
User avatar
pgimeno
Party member
Posts: 3639
Joined: Sun Oct 18, 2015 2:58 pm

Re: Problem with shaders (especially with texture_coords)

Post 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.
User avatar
zorg
Party member
Posts: 3465
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

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

Post 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".
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Google [Bot] and 8 guests