Page 9 of 10

Re: LÖVE 11.0 released!

Posted: Mon Apr 09, 2018 8:48 pm
by SiENcE
zorg wrote: Mon Apr 09, 2018 3:58 pmPaused at the very beginning == Stopped then, basically
Sure, but how do i know if a source was stopped or paused? Or do I have to remember that now? Before i had only to ask the source.

Re: LÖVE 11.0 released!

Posted: Mon Apr 09, 2018 9:07 pm
by zorg
SiENcE wrote: Mon Apr 09, 2018 8:48 pm
zorg wrote: Mon Apr 09, 2018 3:58 pmPaused at the very beginning == Stopped then, basically
Sure, but how do i know if a source was stopped or paused? Or do I have to remember that now? Before i had only to ask the source.
The point is that when playback is suspended at the very beginning, the paused and stopped "states" are basically equivalent. pause is always halt playback, stop is always halt playback and rewind, and rewind is always seek(0).

Re: LÖVE 11.0 released!

Posted: Mon Apr 09, 2018 9:58 pm
by Iori Branford
So I found an answer on color clamping.
https://bitbucket.org/rude/love/issues/ ... error-if-a

Indeed the behavior my project relies on was against spec, and in 11.0 requires a pixel shader (or one of the floating point pixel formats but no idea how widely supported they are).

Re: LÖVE 11.0 released!

Posted: Tue Apr 10, 2018 7:18 am
by shru
Iori Branford wrote: Mon Apr 09, 2018 9:58 pm Indeed the behavior my project relies on was against spec, and in 11.0 requires a pixel shader (or one of the floating point pixel formats but no idea how widely supported they are).
I was also able to recreate the effect by drawing a given sprite additional time(s) after calling `love.graphics.setBlendMode('add')`. I don't know a lot about shaders or alternate pixel formats, so I don't have any conception of whether this is more or less computationally expensive than either of those approaches.

Re: LÖVE 11.0 released!

Posted: Tue Apr 10, 2018 2:33 pm
by pgimeno
shru wrote: Tue Apr 10, 2018 7:18 am I was also able to recreate the effect by drawing a given sprite additional time(s) after calling `love.graphics.setBlendMode('add')`. I don't know a lot about shaders or alternate pixel formats, so I don't have any conception of whether this is more or less computationally expensive than either of those approaches.
Shaders are running all the time, therefore using a shader should be computationally cheaper than drawing the sprite multiple times.

This is an approach you can try:

Code: Select all

local shader = love.graphics.newShader[[
  // Based on the default shader code at https://love2d.org/wiki/love.graphics.newShader
  extern number colour[4];
  vec4 effect(vec4 ignored, Image texture, vec2 texture_coords, vec2 screen_coords)
  {
    vec4 texturecolor = Texel(texture, texture_coords);
    return texturecolor * (vec4(colour[0], colour[1], colour[2], colour[3])*(1.0/255.0));
  }
]]
love.graphics.setShader(shader)

function mySetColour(r, g, b, a) -- in this example it's global; you may want to put it inside a module or object.
  if g == nil then assert(type(r) == "table"); g = r[2]; b = r[3]; a = r[4]; r = r[1] end
  if a == nil then a = 255 end
  assert(type(r) == "number" and type(g) == "number" and type(b) == "number" and type(a) == "number")
  shader:send('colour', r, g, b, a)
end

-- example usage:

local img = love.graphics.newImage('image1.jpg')

function love.draw()
  mySetColour(511, 255, 255) -- draw redder than normal
  love.graphics.draw(img)
end
If you want 0-1 range, remove the *(1.0/255.0) part from the shader and change a = 255 to a = 1 in mySetColour.

Re: LÖVE 11.0 released!

Posted: Wed Apr 11, 2018 5:02 pm
by pixelicidio
For the new COLOR FROMAT change the fun thing about lua is that you can replece the setColor function for the whole project only once like this:

Code: Select all

--love version >11 fix colors
if api.getVersion() >=  11 then
  local oldSetColor = love.graphics.setColor
  love.graphics.setColor = function (r, g, b, a)     
    if type(r)=="table" then
        g = r[2] / 255
        b = r[3] / 255
        a = (r[4] or 255) / 255
        r = r[1] / 255
    else
      r = r / 255
      g = g / 255
      b = b / 255
      a = (a or 255) / 255
    end
    oldSetColor(r,g,b,a)
  end
end
Then do the same for other functions involving colors.

Re: LÖVE 11.0 released!

Posted: Wed Apr 11, 2018 10:46 pm
by shru
pgimeno wrote: Tue Apr 10, 2018 2:33 pm Shaders are running all the time, therefore using a shader should be computationally cheaper than drawing the sprite multiple times.

This is an approach you can try:

-- snip --
Just wanted to take the time to thank you for the example code.

Re: LÖVE 11.0 released!

Posted: Thu Apr 12, 2018 6:10 am
by D0NM
Thank you, pixelicidio!

You just have to think about something like that... and it is ready ))

Re: LÖVE 11.0 released!

Posted: Thu Apr 12, 2018 8:51 am
by raidho36
Note that this function is just a compatibility layer to spare you the work. You probably want to properly convert your setColor functions some time in the future.

Re: LÖVE 11.0 released!

Posted: Thu Apr 12, 2018 10:59 am
by pgimeno
Also don't forget getColor.