Respect color.alpha by rendering.draw_something

Things that already exist in the current mod API
Post Reply
User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Respect color.alpha by rendering.draw_something

Post by darkfrei »

You can try the code (note that a=0.5):

Code: Select all

/c  local p = game.player 
rendering.draw_rectangle{
  color={r=0, g=1, b=1, a=0.5}, 
  filled=true, 
  left_top={x=p.position.x-1.5, y=p.position.y-1.5}, 
  right_bottom={x=p.position.x+1.5, y=p.position.y+1.5}, 
  surface=p.surface}
Expected:
2019-06-04T19_53_05-Window.png
2019-06-04T19_53_05-Window.png (87.01 KiB) Viewed 1762 times

Got:
2019-06-04T19_51_07-Window.png
2019-06-04T19_51_07-Window.png (39.13 KiB) Viewed 1762 times
https://lua-api.factorio.com/latest/Lua ... _rectangle
Last edited by darkfrei on Tue Jun 04, 2019 6:34 pm, edited 3 times in total.

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Respect color.alpha by rendering.draw_something

Post by eradicator »

Code: Select all

/c  local p = game.player
 rendering.draw_rectangle{
 color = {r=1,g=0,b=0,a=0},
 filled=true, 
 left_top={x=p.position.x-1.5, y=p.position.y-1.5},
 right_bottom={x=p.position.x+1.5, y=p.position.y+1.5},
 surface=p.surface}
It's not completely ignored. It's just not applied correctly. Looks like (r+a)/2 instead of (r*a) to me.
Last edited by eradicator on Tue Jun 04, 2019 6:32 pm, edited 1 time in total.
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

posila
Factorio Staff
Factorio Staff
Posts: 5201
Joined: Thu Jun 11, 2015 1:35 pm
Contact:

Re: Respect color.alpha by rendering.draw_something

Post by posila »

Factorio uses (and expects) colors in alpha-premultiplied format. https://factorio.com/blog/post/fff-172

if you want tint with {r=0, g=1, b=1} and alpha blend with alpha = 0.5, tint/color you need to pass in is {r=0, g=0.5, b=0.5, a=0.5}

User avatar
eradicator
Smart Inserter
Smart Inserter
Posts: 5206
Joined: Tue Jul 12, 2016 9:03 am
Contact:

Re: Respect color.alpha by rendering.draw_something

Post by eradicator »

posila wrote:
Tue Jun 04, 2019 6:32 pm
Factorio uses (and expects) colors in alpha-premultiplied format. https://factorio.com/blog/post/fff-172

if you want tint with {r=0, g=1, b=1} and alpha blend with alpha = 0.5, tint/color you need to pass in is {r=0, g=0.5, b=0.5, a=0.5}
/me goes to fix my color function... :oops:
Author of: Belt Planner, Hand Crank Generator, Screenshot Maker, /sudo and more.
Mod support languages: 日本語, Deutsch, English
My code in the post above is dedicated to the public domain under CC0.

User avatar
darkfrei
Smart Inserter
Smart Inserter
Posts: 2903
Joined: Thu Nov 20, 2014 11:11 pm
Contact:

Re: Respect color.alpha by rendering.draw_something

Post by darkfrei »

eradicator wrote:
Tue Jun 04, 2019 6:31 pm
It's not completely ignored. It's just not applied correctly. Looks like (r+a)/2 instead of (r*a) to me.
You are right, it works correct for gray black images only:

Code: Select all

/c  local p = game.player 
rendering.draw_rectangle{
color={r=0, g=0, b=0, a=0.5}, 
filled=true, 
left_top={x=p.position.x-1.5, y=p.position.y-1.5}, 
right_bottom={x=p.position.x+1.5, y=p.position.y+1.5}, 
surface=p.surface}
2019-06-04T20_41_18-Window.png
2019-06-04T20_41_18-Window.png (178.59 KiB) Viewed 1747 times
upd: rendering rectangles with all grayscales and alphas:

Code: Select all

/c 
local p = game.player
for x = 0, 10 do
  for y = 0, 10 do
    local color = x/10
    local alpha = y/10
    rendering.draw_rectangle{
      color={r=color, g=color, b=color, a=alpha}, 
      filled=true, 
      left_top =   {x=p.position.x   + x, y=p.position.y   + y}, 
      right_bottom={x=p.position.x+1 + x, y=p.position.y+1 + y}, 
      surface=p.surface}
  end
end
day and night results:
2019-06-04T21_20_20-Window.png
2019-06-04T21_20_20-Window.png (238.78 KiB) Viewed 1737 times
2019-06-04T21_21_34-Window.png
2019-06-04T21_21_34-Window.png (131.76 KiB) Viewed 1737 times
fog

Post Reply

Return to “Already exists”