just a few touchups before bed

This commit is contained in:
Tim Anema 2014-11-29 23:51:44 -05:00
parent bbcd20a27e
commit 9c81c71f89
4 changed files with 16 additions and 58 deletions

View File

@ -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

View File

@ -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)

View File

@ -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

View File

@ -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);
}
}