Fix body shadow

This commit is contained in:
jiangzhi.xie 2019-09-08 12:53:47 +08:00
parent 9d48adb46b
commit 600d02ca63
2 changed files with 8 additions and 11 deletions

View File

@ -382,10 +382,6 @@ end
-- set glass color
function body:setColor(r, g, b)
if r > 1 then r = r / 255 end
if g > 1 then g = r / 255 end
if b > 1 then b = r / 255 end
self.red = r
self.green = g
self.blue = b
@ -689,7 +685,7 @@ function body:drawShadow(light)
return
end
love.graphics.setColor(self.red, self.green, self.blue, self.alpha)
love.graphics.setColor(self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255)
if self.shadowType == "polygon" then
self:drawPolyShadow(light)
elseif self.shadowType == "circle" then
@ -779,10 +775,10 @@ function body:drawImageShadow(light)
local shadowY = (length * math.cos(shadowRotation) + 1.0) * shadowStartY
self.shadowMesh:setVertices({
{shadowX, shadowY, 0, 0, self.red, self.green, self.blue, self.alpha},
{shadowX + self.imgWidth, shadowY, 1, 0, self.red, self.green, self.blue, self.alpha},
{self.imgWidth, shadowStartY, 1, 1, self.red, self.green, self.blue, self.alpha},
{0, shadowStartY, 0, 1, self.red, self.green, self.blue, self.alpha}
{shadowX, shadowY, 0, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{shadowX + self.imgWidth, shadowY, 1, 0, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{self.imgWidth, shadowStartY, 1, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255},
{0, shadowStartY, 0, 1, self.red / 255, self.green / 255, self.blue / 255, self.alpha / 255}
})
love.graphics.draw(self.shadowMesh, self.x, self.y, self.rotation, self.scalex, self.scaley, self.ox, self.oy)

View File

@ -104,7 +104,6 @@ function light_world:draw(cb)
_ = self.disableReflection or self:drawReflection( self.l,self.t,self.w,self.h,self.s)
end)
self.post_shader:drawWith(self.render_buffer, self.l, self.t, self.s)
-- love.graphics.draw(self.shadow_buffer)
end
-- draw normal shading
@ -169,7 +168,9 @@ function light_world:drawShadows(l,t,w,h,s)
shader = self.shadowShader,
stencil = function()
local angle = light.direction - (light.angle / 2.0)
love.graphics.arc("fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle)
love.graphics.arc(
"fill", (light.x + l/s) * s, (light.y + t/s) * s, light.range, angle, angle + light.angle
)
end
})
end