Fix normal map gradient.

This commit is contained in:
Marcus Ihde 2014-03-08 21:18:40 +01:00
parent 249fff23ae
commit 827394c87b
2 changed files with 6 additions and 6 deletions

View File

@ -827,7 +827,7 @@ function love.light.newImage(p, img, x, y, width, height, ox, oy)
o.normal = love.graphics.newImage(imgNormalData) o.normal = love.graphics.newImage(imgNormalData)
end end
-- generate faded normal map -- generate faded normal map
o.generateNormalMapFade = function(horizontalFade, verticalFade) o.generateNormalMapGradient = function(horizontalGradient, verticalGradient)
local imgData = o.img:getData() local imgData = o.img:getData()
local imgNormalData = love.image.newImageData(o.imgWidth, o.imgHeight) local imgNormalData = love.image.newImageData(o.imgWidth, o.imgHeight)
local dx = 255.0 / o.imgWidth 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 for k = 0, o.imgHeight - 1 do
local r, g, b, a = imgData:getPixel(i, k) local r, g, b, a = imgData:getPixel(i, k)
if a > 0 then if a > 0 then
if horizontalFade == "fade" then if horizontalGradient == "gradient" then
nx = i * dx nx = i * dx
elseif horizontalFade == "inverse" then elseif horizontalGradient == "inverse" then
nx = 255 - i * dx nx = 255 - i * dx
else else
nx = 127 nx = 127
end end
if verticalFade == "fade" then if verticalGradient == "gradient" then
ny = 127 + k * dy * 0.5 ny = 127 + k * dy * 0.5
nz = 255 - k * dy * 0.5 nz = 255 - k * dy * 0.5
elseif verticalFade == "inverse" then elseif verticalGradient == "inverse" then
ny = 127 - k * dy * 0.5 ny = 127 - k * dy * 0.5
nz = 127 - k * dy * 0.25 nz = 127 - k * dy * 0.25
else else

View File

@ -436,7 +436,7 @@ function love.keypressed(k, u)
-- add image -- add image
phyCnt = phyCnt + 1 phyCnt = phyCnt + 1
phyLight[phyCnt] = lightWorld.newImage(blopp, mx, my, 42, 16, 21, 20) 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") phyBody[phyCnt] = love.physics.newBody(physicWorld, mx, my, "dynamic")
phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 42, 29) phyShape[phyCnt] = love.physics.newRectangleShape(0, 0, 42, 29)
phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt]) phyFixture[phyCnt] = love.physics.newFixture(phyBody[phyCnt], phyShape[phyCnt])