mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
really simplified directional lights
This commit is contained in:
parent
6ae929fbeb
commit
81bcb0e347
@ -138,6 +138,9 @@ function light_world:drawNormalShading(l,t,w,h,s)
|
|||||||
self.bodies[k]:drawShadow(light)
|
self.bodies[k]:drawShadow(light)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
local angle = math.pi - light.angle / 2.0
|
||||||
|
love.graphics.setColor(0, 0, 0)
|
||||||
|
love.graphics.arc("fill", light.x, light.y, light.range, light.direction - angle, light.direction + angle)
|
||||||
end)
|
end)
|
||||||
-- draw scene for this light using normals and shadowmap
|
-- draw scene for this light using normals and shadowmap
|
||||||
self.shadowShader:send('shadowMap', self.shadowMap)
|
self.shadowShader:send('shadowMap', self.shadowMap)
|
||||||
@ -146,8 +149,6 @@ function light_world:drawNormalShading(l,t,w,h,s)
|
|||||||
self.shadowShader:send('lightRange',{light.range * s})
|
self.shadowShader:send('lightRange',{light.range * s})
|
||||||
self.shadowShader:send("lightSmooth", light.smooth)
|
self.shadowShader:send("lightSmooth", light.smooth)
|
||||||
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
self.shadowShader:send("lightGlow", {1.0 - light.glowSize, light.glowStrength})
|
||||||
self.shadowShader:send("lightAngle", math.pi - light.angle / 2.0)
|
|
||||||
self.shadowShader:send("lightDirection", light.direction)
|
|
||||||
self.shadowShader:send("invert_normal", self.normalInvert == true)
|
self.shadowShader:send("invert_normal", self.normalInvert == true)
|
||||||
util.drawCanvasToCanvas(self.normalMap, self.normal2, {
|
util.drawCanvasToCanvas(self.normalMap, self.normal2, {
|
||||||
blendmode = 'additive',
|
blendmode = 'additive',
|
||||||
|
@ -14,15 +14,6 @@ extern float lightAngle; //if set, the light becomes directional to a slice
|
|||||||
extern float lightDirection; //which direction to shine the light in if directional in degrees
|
extern float lightDirection; //which direction to shine the light in if directional in degrees
|
||||||
extern bool invert_normal; //if the light should invert normals
|
extern bool invert_normal; //if the light should invert normals
|
||||||
|
|
||||||
//calculate if a pixel is within the light slice
|
|
||||||
bool not_in_slice(vec2 pixel_coords){
|
|
||||||
float angle = atan(lightPosition.x - pixel_coords.x, pixel_coords.y - lightPosition.y) + PI;
|
|
||||||
bool pastRightSide = angle < mod(lightDirection + lightAngle, PI * 2);
|
|
||||||
bool pastLeftSide = angle > mod(lightDirection - lightAngle, PI * 2);
|
|
||||||
bool lightUp = lightDirection - lightAngle > 0 && lightDirection + lightAngle < PI * 2;
|
|
||||||
return (lightUp && (pastRightSide && pastLeftSide)) || (!lightUp && (pastRightSide || pastLeftSide));
|
|
||||||
}
|
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec4 pixelColor = Texel(texture, texture_coords);
|
vec4 pixelColor = Texel(texture, texture_coords);
|
||||||
vec4 shadowColor = Texel(shadowMap, texture_coords);
|
vec4 shadowColor = Texel(shadowMap, texture_coords);
|
||||||
@ -33,11 +24,6 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
|||||||
//not in range draw in shadows
|
//not in range draw in shadows
|
||||||
return vec4(0.0, 0.0, 0.0, 1.0);
|
return vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
}else{
|
}else{
|
||||||
//if the light is a slice and the pixel is not inside
|
|
||||||
if(lightAngle > 0.0 && not_in_slice(pixel_coords)) {
|
|
||||||
return vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
}
|
|
||||||
|
|
||||||
vec3 normal;
|
vec3 normal;
|
||||||
if(pixelColor.a > 0.0) {
|
if(pixelColor.a > 0.0) {
|
||||||
//if on the normal map ie there is normal map data
|
//if on the normal map ie there is normal map data
|
||||||
|
Loading…
Reference in New Issue
Block a user