0.9.2 to 11.2 drawing quads with alpha

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
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

0.9.2 to 11.2 drawing quads with alpha

Post by vortizee »

In 0.9.2 in-stencil cloud quads drawn over terrain quads rendered intuitively, as one would expect in a graphics program via layers. Occasionally clouds overlapped so the effect was more opaque (heavy clouds), which effect was exploited to simulate a storm cloud by intermittently drawing another quad over it consisting of the same cloud with a ray of lightning.
clouds.jpg
clouds.jpg (18.94 KiB) Viewed 3987 times
In 11.2 the cloud renders totally different, some unknown blending changes its colors or the pixel colors under the transparent pixels. I’ve never used [read: understood] canvas, layer or blend commands in Löve though I’ve tried various of the latter with no success. I get either a white or magenta effect. How do I get the intuitive effect back in 11.2?

Code: Select all

  love.graphics.stencil( scope_stencil, “replace", 1, false )
  love.graphics.setStencilTest( "greater", 0 )
  
  LGD( maskScreen, 24*s, 20*s, 0, s, s ) -- love.graphics.draw full tile set unpopulated 
  do
      if #cits.grid > 0 then
        for i=1, #cits.grid do
          x, y = cits.grid[i][1], cits.grid[i][2]
          h = ter.hgt[x][y]
          LGD( thimage, img_terr[6], pX[x], pY[y], 0, s, s )
          LGD( dalerts, digitsTerr[h], pX[x]+1, pY[y]+1, 0, s, s )
        end
      end
   
     -- DRAW CLOUDS
     love.graphics.setBlendMode(“add”, “alphamultiply”) -- one of many clumsy attempts

  if #clouds.grid > 0 then
    
    setCol[“clouds”]()		-- love.graphics.setColor rgba where alpha=89/255
    for i=1, #clouds.grid do
      local x, y = clouds.grid[i][1], clouds.grid[i][2]
        LGD(  thimage, img_clds[1], pX[x], pY[y], 0, s, s )
    end
      
    if #storm.grid > 0 then
      for i=1, #storm.grid do
        local x, y = storm.grid[i][1], storm.grid[i][2]
          if lightning == 0 then
            LGD(  thimage, img_clds[1], pX[x], pY[y], 0, s, s )
          else
            LGD(  thimage, img_clds[2], pX[x], pY[y], 0, s, s )
          end
      end
    end
  end
  
  love.graphics.setBlendMode("alpha")   
  setCol["draw"]()
  love.graphics.setStencilTest()
  
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: 0.9.2 to 11.2 drawing quads with alpha

Post by pgimeno »

I'm lost, and I can't follow your code without enough context as to letting us know what each variable is.

Do you think you could post a minimal reproducing love file with an example, that renders fine in 0.9.2 but wrong in 11.0?

I suspect the problem may be in alphamultiply vs premultiplied, but I can't say for sure from that code.
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: 0.9.2 to 11.2 drawing quads with alpha

Post by vortizee »

Hardly anything changed from 0.9.2 to 11.2: the code posted earlier was 11.2; 0.9.2 is below, and the only issue is how the cloud renders. The example just draws a city tile over the full tile set, plus a digit-image over it — there being no transparency in any of those, they render fine. The cloud though, is an opaque shape inside a transparent rectangle, and that is a tile drawn after love.graphics.setColor is given an alpha in its rgba table — no canvas function or blending command used (all other images are drawn in rgba: 1,1,1,1).

Code: Select all

-- 0.9.2
local LGD		= love.graphics.draw

local scope_stencil = function()		-- for setStencil()
  setCol[“stencil”]()				-- 0,0,0,1
  love.graphics.circle( 'fill', 403*s, 400*s, 379.5*s)
end

function love.draw()
    s = scale
    setCol["draw"]()
    LGD( mainScreen, 0, 0, 0, s, s )	-- the main window
    LGD( maskScreen, 24*s, 20*s, 0, s, s ) -- whole terrain unpopulated
    -- draw stuff, print stuff
  
  love.graphics.setStencil( scope_stencil )
  do
     if #cits.grid > 0 then
      for i=1, #cits.grid do
        x, y = cits.grid[i][1], cits.grid[i][2]
        h = ter.hgt[x][y]
        LGD( thimage, img_terr[6], pX[x], pY[y], 0, s, s )
        LGD( dalerts, digitsTerr[h], pX[x]+1, pY[y]+1, 0, s, s )
      end
    end
   
    -- DRAW CLOUDS
  if #clouds.grid > 0 then
    setCol["clouds"]()
    for i=1, #clouds.grid do
      local x, y = clouds.grid[i][1], clouds.grid[i][2]
      LGD(  thimage, img_clds[1], pX[x], pY[y], 0, s, s )
    end
      
    if #storm.grid > 0 then
      for i=1, #storm.grid do
        local x, y = storm.grid[i][1], storm.grid[i][2]
        if lightning == 0 then
          LGD(  thimage, img_clds[1], pX[x], pY[y], 0, s, s )
        else
          LGD(  thimage, img_clds[2], pX[x], pY[y], 0, s, s )
        end
      end
    end
  end
    
  setCol["draw"]()

  love.graphics.setStencil()		-- out of the stencil

    -- draw stuff, print stuff

On the left is what 0.9.2 renders (as intended). What I get on 11.2 without any setBlendMode command are purple clouds. With love.graphics.setBlendMode(“add”, “alphamultiply”) — which at least doesn’t change the transparent areas of the cloud image below or in the tile drawn before it, I get the white clouds. It gets weirder at other blend settings.
comparo.jpg
comparo.jpg (10.24 KiB) Viewed 3949 times
Oh, I just realized I’m still using the love.graphics.draw statement of 0.9.2 in 11.2, and something has probably changed there.
User avatar
pgimeno
Party member
Posts: 3544
Joined: Sun Oct 18, 2015 2:58 pm

Re: 0.9.2 to 11.2 drawing quads with alpha

Post by pgimeno »

Without a complete self-contained example that reproduces the problem, I don't think anyone will be able to help.
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: 0.9.2 to 11.2 drawing quads with alpha

Post by vortizee »

Okay, that’ll be my 2nd project.
User avatar
vortizee
Prole
Posts: 34
Joined: Sat Feb 14, 2015 6:23 am

Re: 0.9.2 to 11.2 drawing quads with alpha

Post by vortizee »

Problem solved — a silly typo!

In the conversion from 0.9.2 to 11.2, the quick and dirty color redefinitions were just given a “/255” but somewhere along the line what should have been 255/255, 255/255, 255/255, 89/255 (1, 1, 1, 0.35) swallowed a ‘2’ in ‘g’ of ‘rgba (55/255), messing up the cloud tile.

The default love.graphics.setBlendMode(“alpha”, “alphamultiply”) works as expected, and in fact can be omitted for my purposes. Sayonara 0.9.2.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot], Semrush [Bot] and 49 guests