From 9c81c71f892b166e9718669eaa3a8461c26b0a73 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Sat, 29 Nov 2014 23:51:44 -0500 Subject: [PATCH] just a few touchups before bed --- examples/complex.lua | 14 +++++++++++ examples/test.lua | 3 ++- lib/body.lua | 1 - lib/shaders/normal.glsl | 56 ----------------------------------------- 4 files changed, 16 insertions(+), 58 deletions(-) delete mode 100644 lib/shaders/normal.glsl diff --git a/examples/complex.lua b/examples/complex.lua index e2ae443..524eff1 100644 --- a/examples/complex.lua +++ b/examples/complex.lua @@ -671,6 +671,20 @@ function love.keypressed(k, u) phyCnt = phyCnt + 1 phyLight[phyCnt] = lightWorld:newRefraction(refraction_normal, mx, my) phyLight[phyCnt]:setReflection(true) + elseif k == "k" then + -- add light + local r = lightWorld:getLightCount() % 3 + local light + + if r == 0 then + light = lightWorld:newLight(mx, my, 31, 127, 63, lightRange) + elseif r == 1 then + light = lightWorld:newLight(mx, my, 127, 63, 31, lightRange) + else + light = lightWorld:newLight(mx, my, 31, 63, 127, lightRange) + end + light:setSmooth(lightSmooth) + light:setGlowStrength(0.3) elseif k == "l" then -- add light local r = lightWorld:getLightCount() % 3 diff --git a/examples/test.lua b/examples/test.lua index 32a7bf6..29043cc 100644 --- a/examples/test.lua +++ b/examples/test.lua @@ -24,8 +24,9 @@ function love.load() end) circle_image = love.graphics.newImage(circle_canvas:getImageData()) - local t = lightWorld:newCircle(150, 150, radius) + local t = lightWorld:newImage(circle_image, 150, 150) t:setNormalMap(normal_map.generateFlat(circle_image, "top")) + t:setShadowType('circle', 50) end function love.mousepressed(x, y, c) diff --git a/lib/body.lua b/lib/body.lua index 2416e5a..1e09c62 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -562,7 +562,6 @@ function body:drawCircleShadow(light) love.graphics.polygon("fill", curShadowGeometry) - print(self.red, self.green, self.blue, self.alpha) if distance1 <= self.radius then love.graphics.arc("fill", cx, cy, radius, 0, (math.pi * 2)) elseif distance2 < light.range then -- dont draw circle if way off screen diff --git a/lib/shaders/normal.glsl b/lib/shaders/normal.glsl deleted file mode 100644 index 550c675..0000000 --- a/lib/shaders/normal.glsl +++ /dev/null @@ -1,56 +0,0 @@ -#define PI 3.1415926535897932384626433832795 - -extern vec2 screenResolution; -extern vec3 lightPosition; -extern vec3 lightColor; -extern float lightRange; -extern float lightSmooth; -extern float lightDirection; -extern float lightAngle; -extern bool invert_normal; - -vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { - vec4 pixelColor = Texel(texture, texture_coords); - - if(pixelColor.a > 0.0) { - if(lightAngle > 0.0) { - float angle2 = atan(lightPosition.x - pixel_coords.x, pixel_coords.y - lightPosition.y) + PI; - if(lightDirection - lightAngle > 0 && lightDirection + lightAngle < PI * 2) { - if(angle2 < mod(lightDirection + lightAngle, PI * 2) && angle2 > mod(lightDirection - lightAngle, PI * 2)) { - return vec4(0.0, 0.0, 0.0, 1.0); - } - } else { - if(angle2 < mod(lightDirection + lightAngle, PI * 2) || angle2 > mod(lightDirection - lightAngle, PI * 2)) { - return vec4(0.0, 0.0, 0.0, 1.0); - } - } - } - - vec3 normal; - if(invert_normal == true) { - normal = vec3(pixelColor.r, 1 - pixelColor.g, pixelColor.b); - } else { - normal = pixelColor.rgb; - } - float dist = distance(lightPosition, vec3(pixel_coords, normal.b)); - - if(dist < lightRange) { - vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / screenResolution.xy, lightPosition.z); - - dir.x *= screenResolution.x / screenResolution.y; - - vec3 N = normalize(normal * 2.0 - 1.0); - vec3 L = normalize(dir); - - vec3 diff = lightColor * max(dot(N, L), 0.0); - - float att = clamp((1.0 - dist / lightRange) / lightSmooth, 0.0, 1.0); - - return vec4(diff * att, 1.0); - } else { - return vec4(0.0, 0.0, 0.0, 1.0); - } - } else { - return vec4(0.0); - } -}