mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
Fix normal map gradient.
This commit is contained in:
parent
249fff23ae
commit
827394c87b
10
light.lua
10
light.lua
@ -827,7 +827,7 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
|
||||
o.normal = love.graphics.newImage(imgNormalData)
|
||||
end
|
||||
-- generate faded normal map
|
||||
o.generateNormalMapFade = function(horizontalFade, verticalFade)
|
||||
o.generateNormalMapGradient = function(horizontalGradient, verticalGradient)
|
||||
local imgData = o.img:getData()
|
||||
local imgNormalData = love.image.newImageData(o.imgWidth, o.imgHeight)
|
||||
local dx = 255.0 / o.imgWidth
|
||||
@ -840,18 +840,18 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
|
||||
for k = 0, o.imgHeight - 1 do
|
||||
local r, g, b, a = imgData:getPixel(i, k)
|
||||
if a > 0 then
|
||||
if horizontalFade == "fade" then
|
||||
if horizontalGradient == "gradient" then
|
||||
nx = i * dx
|
||||
elseif horizontalFade == "inverse" then
|
||||
elseif horizontalGradient == "inverse" then
|
||||
nx = 255 - i * dx
|
||||
else
|
||||
nx = 127
|
||||
end
|
||||
|
||||
if verticalFade == "fade" then
|
||||
if verticalGradient == "gradient" then
|
||||
ny = 127 + k * dy * 0.5
|
||||
nz = 255 - k * dy * 0.5
|
||||
elseif verticalFade == "inverse" then
|
||||
elseif verticalGradient == "inverse" then
|
||||
ny = 127 - k * dy * 0.5
|
||||
nz = 127 - k * dy * 0.25
|
||||
else
|
||||
|
2
main.lua
2
main.lua
@ -436,7 +436,7 @@ function love.keypressed(k, u)
|
||||
-- add image
|
||||
phyCnt = phyCnt + 1
|
||||
phyLight[phyCnt] = lightWorld.newImage(blopp, mx, my, 42, 16, 21, 20)
|
||||
phyLight[phyCnt].generateNormalMapFade("fade", "fade")
|
||||
phyLight[phyCnt].generateNormalMapGradient("gradient", "gradient")
|
||||
phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
|
||||
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 42, 29)
|
||||
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])
|
||||
|
Loading…
Reference in New Issue
Block a user