Shaders and setColor

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.
Post Reply
seiya
Prole
Posts: 2
Joined: Fri May 19, 2023 10:56 pm

Shaders and setColor

Post by seiya »

I am learning shaders right now and I have a shader doing what I want for the most part (just diffusing a color). I had a single pixel have its color reset to full red with:

Code: Select all

love.graphics.setColor(1,0,0,1)
love.graphics.circle("fill",rx,ry,1)
Nothing special there, or so I thought. I wanted to see how it interacted with a line of color, so I did this when first making the canvas:

Code: Select all

love.graphics.setColor(0,0,1,1)
love.graphics.rectangle("fill",4,0,1,64)
The blue line was always disappearing though. I did a lot of experimenting to find why it was disappearing and what I found is that setColor was acting to multiply the colors the shader returned by what setColor was set to. Or to be more clear, if the shader returned red at 0.5 and I had used setColor to setColor(0.5,0.5,0.5,1), the red would be 0.25.

Is this interaction intended?
User avatar
UnixRoot
Party member
Posts: 100
Joined: Mon Nov 08, 2021 8:10 am

Re: Shaders and setColor

Post by UnixRoot »

Yes, setColor sets a global color value that's used for every drawing operation afterwards. Everything you draw after setColor is affected. With setColor( 0.5, 0.5, 0.5, 1.0 ) you get halfed color values.
seiya
Prole
Posts: 2
Joined: Fri May 19, 2023 10:56 pm

Re: Shaders and setColor

Post by seiya »

Thank you.

I thought that was the case, but it is better to better to get confirmation than set myself up for problems later.
Post Reply

Who is online

Users browsing this forum: Google [Bot], immortalx and 2 guests