mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
updating shaders so I dont have to pass in screen sizes
This commit is contained in:
parent
6c87407a6f
commit
8ddb4138b1
45
lib/body.lua
45
lib/body.lua
@ -695,10 +695,10 @@ end
|
|||||||
function body:drawCircleShadow(light)
|
function body:drawCircleShadow(light)
|
||||||
local curShadowGeometry = {}
|
local curShadowGeometry = {}
|
||||||
local angle = math.atan2(light.x - (self.x - self.ox), (self.y - self.oy) - light.y) + math.pi / 2
|
local angle = math.atan2(light.x - (self.x - self.ox), (self.y - self.oy) - light.y) + math.pi / 2
|
||||||
local x2 = ((self.x - self.ox) + math.sin(angle) * self.radius)
|
local x1 = ((self.x - self.ox) + math.sin(angle) * self.radius)
|
||||||
local y2 = ((self.y - self.oy) - math.cos(angle) * self.radius)
|
local y1 = ((self.y - self.oy) - math.cos(angle) * self.radius)
|
||||||
local x3 = ((self.x - self.ox) - math.sin(angle) * self.radius)
|
local x2 = ((self.x - self.ox) - math.sin(angle) * self.radius)
|
||||||
local y3 = ((self.y - self.oy) + math.cos(angle) * self.radius)
|
local y2 = ((self.y - self.oy) + math.cos(angle) * self.radius)
|
||||||
|
|
||||||
local lxh = (light.x * self.zheight)
|
local lxh = (light.x * self.zheight)
|
||||||
local lyh = (light.y * self.zheight)
|
local lyh = (light.y * self.zheight)
|
||||||
@ -707,29 +707,26 @@ function body:drawCircleShadow(light)
|
|||||||
height_diff = -0.001
|
height_diff = -0.001
|
||||||
end
|
end
|
||||||
|
|
||||||
local x4 = (lxh - (x3 * light.z))/height_diff
|
local x3 = (lxh - (x2 * light.z))/height_diff
|
||||||
local y4 = (lyh - (y3 * light.z))/height_diff
|
local y3 = (lyh - (y2 * light.z))/height_diff
|
||||||
local x5 = (lxh - (x2 * light.z))/height_diff
|
local x4 = (lxh - (x1 * light.z))/height_diff
|
||||||
local y5 = (lyh - (y2 * light.z))/height_diff
|
local y4 = (lyh - (y1 * light.z))/height_diff
|
||||||
|
|
||||||
local radius = math.sqrt(math.pow(x5 - x4, 2) + math.pow(y5-y4, 2)) / 2
|
local radius = math.sqrt(math.pow(x4 - x3, 2) + math.pow(y4-y3, 2)) / 2
|
||||||
local cx, cy = (x4 + x5)/2, (y4 + y5)/2
|
local cx, cy = (x3 + x4)/2, (y3 + y4)/2
|
||||||
local distance1 = math.sqrt(math.pow(light.x - self.x, 2) + math.pow(light.y - self.y, 2))
|
|
||||||
local distance2 = math.sqrt(math.pow(light.x - cx, 2) + math.pow(light.y - cy, 2))
|
|
||||||
|
|
||||||
if distance1 >= self.radius then
|
if math.sqrt(math.pow(light.x - self.x, 2) + math.pow(light.y - self.y, 2)) <= self.radius then
|
||||||
love.graphics.polygon("fill", x2, y2, x3, y3, x4, y4, x5, y5)
|
|
||||||
end
|
|
||||||
|
|
||||||
if distance1 <= self.radius then
|
|
||||||
love.graphics.circle("fill", cx, cy, radius)
|
love.graphics.circle("fill", cx, cy, radius)
|
||||||
elseif distance2 < light.range then -- dont draw circle if way off screen
|
else
|
||||||
local angle1 = math.atan2(y4 - cy, x4 - cx)
|
love.graphics.polygon("fill", x1, y1, x2, y2, x3, y3, x4, y4)
|
||||||
local angle2 = math.atan2(y5 - cy, x5 - cx)
|
if math.sqrt(math.pow(light.x - cx, 2) + math.pow(light.y - cy, 2)) < light.range then -- dont draw circle if way off screen
|
||||||
if angle1 > angle2 then
|
local angle1 = math.atan2(y3 - cy, x3 - cx)
|
||||||
love.graphics.arc("fill", cx, cy, radius, angle1, angle2)
|
local angle2 = math.atan2(y4 - cy, x4 - cx)
|
||||||
else
|
if angle1 > angle2 then
|
||||||
love.graphics.arc("fill", cx, cy, radius, angle1 - math.pi, angle2 - math.pi)
|
love.graphics.arc("fill", cx, cy, radius, angle1, angle2)
|
||||||
|
else
|
||||||
|
love.graphics.arc("fill", cx, cy, radius, angle1 - math.pi, angle2 - math.pi)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
32
lib/init.lua
32
lib/init.lua
@ -33,6 +33,7 @@ local light_world = class()
|
|||||||
|
|
||||||
light_world.blurv = love.graphics.newShader(_PACKAGE.."shaders/blurv.glsl")
|
light_world.blurv = love.graphics.newShader(_PACKAGE.."shaders/blurv.glsl")
|
||||||
light_world.blurh = love.graphics.newShader(_PACKAGE.."shaders/blurh.glsl")
|
light_world.blurh = love.graphics.newShader(_PACKAGE.."shaders/blurh.glsl")
|
||||||
|
light_world.shadowShader = love.graphics.newShader(_PACKAGE.."/shaders/shadow.glsl")
|
||||||
light_world.refractionShader = love.graphics.newShader(_PACKAGE.."shaders/refraction.glsl")
|
light_world.refractionShader = love.graphics.newShader(_PACKAGE.."shaders/refraction.glsl")
|
||||||
light_world.reflectionShader = love.graphics.newShader(_PACKAGE.."shaders/reflection.glsl")
|
light_world.reflectionShader = love.graphics.newShader(_PACKAGE.."shaders/reflection.glsl")
|
||||||
|
|
||||||
@ -50,6 +51,7 @@ function light_world:init(options)
|
|||||||
self.glowBlur = 1.0
|
self.glowBlur = 1.0
|
||||||
self.glowTimer = 0.0
|
self.glowTimer = 0.0
|
||||||
self.glowDown = false
|
self.glowDown = false
|
||||||
|
self.normalInvert = false
|
||||||
|
|
||||||
self.disableGlow = false
|
self.disableGlow = false
|
||||||
self.disableMaterial = false
|
self.disableMaterial = false
|
||||||
@ -78,15 +80,6 @@ function light_world:refreshScreenSize(w, h)
|
|||||||
self.reflectionMap = love.graphics.newCanvas(w, h)
|
self.reflectionMap = love.graphics.newCanvas(w, h)
|
||||||
self.reflectionMap2 = love.graphics.newCanvas(w, h)
|
self.reflectionMap2 = love.graphics.newCanvas(w, h)
|
||||||
|
|
||||||
self.blurv:send("screen", {w, h})
|
|
||||||
self.blurh:send("screen", {w, h})
|
|
||||||
self.refractionShader:send("screen", {w, h})
|
|
||||||
self.reflectionShader:send("screen", {w, h})
|
|
||||||
|
|
||||||
for i = 1, #self.lights do
|
|
||||||
self.lights[i]:refresh(w, h)
|
|
||||||
end
|
|
||||||
|
|
||||||
self.post_shader:refreshScreenSize(w, h)
|
self.post_shader:refreshScreenSize(w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -136,18 +129,31 @@ function light_world:drawNormalShading(l,t,w,h,s)
|
|||||||
|
|
||||||
self.normal2:clear()
|
self.normal2:clear()
|
||||||
for i = 1, #self.lights do
|
for i = 1, #self.lights do
|
||||||
if self.lights[i]:inRange(l,t,w,h,s) then
|
local light = self.lights[i]
|
||||||
|
if light:inRange(l,t,w,h,s) then
|
||||||
-- create shadow map for this light
|
-- create shadow map for this light
|
||||||
self.shadowMap:clear()
|
self.shadowMap:clear()
|
||||||
util.drawto(self.shadowMap, l, t, s, function()
|
util.drawto(self.shadowMap, l, t, s, function()
|
||||||
for k = 1, #self.body do
|
for k = 1, #self.body do
|
||||||
if self.body[k]:isInLightRange(self.lights[i]) and self.body[k]:isInRange(-l,-t,w,h,s) then
|
if self.body[k]:isInLightRange(light) and self.body[k]:isInRange(-l,-t,w,h,s) then
|
||||||
self.body[k]:drawShadow(self.lights[i])
|
self.body[k]:drawShadow(light)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
-- draw scene for this light using normals and shadowmap
|
-- draw scene for this light using normals and shadowmap
|
||||||
self.lights[i]:drawNormalShading(l,t,w,h,s, self.normalMap, self.shadowMap, self.normal2)
|
self.shadowShader:send('shadowMap', self.shadowMap)
|
||||||
|
self.shadowShader:send('lightColor', {light.red / 255.0, light.green / 255.0, light.blue / 255.0})
|
||||||
|
self.shadowShader:send("lightPosition", {(light.x + l/s) * s, (h/s - (light.y + t/s)) * s, (light.z * 10) / 255.0})
|
||||||
|
self.shadowShader:send('lightRange',{light.range * s})
|
||||||
|
self.shadowShader:send("lightSmooth", light.smooth)
|
||||||
|
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)
|
||||||
|
util.drawCanvasToCanvas(self.normalMap, self.normal2, {
|
||||||
|
blendmode = 'additive',
|
||||||
|
shader = self.shadowShader
|
||||||
|
})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,11 +1,8 @@
|
|||||||
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
|
local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or ""
|
||||||
local class = require(_PACKAGE.."/class")
|
local class = require(_PACKAGE.."/class")
|
||||||
local util = require(_PACKAGE..'/util')
|
|
||||||
|
|
||||||
local light = class()
|
local light = class()
|
||||||
|
|
||||||
light.shadowShader = love.graphics.newShader(_PACKAGE.."/shaders/shadow.glsl")
|
|
||||||
|
|
||||||
function light:init(x, y, r, g, b, range)
|
function light:init(x, y, r, g, b, range)
|
||||||
self.direction = 0
|
self.direction = 0
|
||||||
self.angle = math.pi * 2.0
|
self.angle = math.pi * 2.0
|
||||||
@ -20,11 +17,6 @@ function light:init(x, y, r, g, b, range)
|
|||||||
self.glowSize = 0.1
|
self.glowSize = 0.1
|
||||||
self.glowStrength = 0.0
|
self.glowStrength = 0.0
|
||||||
self.visible = true
|
self.visible = true
|
||||||
self:refresh()
|
|
||||||
end
|
|
||||||
|
|
||||||
function light:refresh(w, h)
|
|
||||||
self.shadowShader:send('screenResolution', {w or love.window.getWidth(), h or love.window.getHeight()})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- set position
|
-- set position
|
||||||
@ -116,22 +108,6 @@ function light:inRange(l,t,w,h,s)
|
|||||||
return self.visible and (lx + rs) > 0 and (lx - rs) < w/s and (ly + rs) > 0 and (ly - rs) < h/s
|
return self.visible and (lx + rs) > 0 and (lx - rs) < w/s and (ly + rs) > 0 and (ly - rs) < h/s
|
||||||
end
|
end
|
||||||
|
|
||||||
function light:drawNormalShading(l,t,w,h,s, normalMap, shadowMap, canvas)
|
|
||||||
self.shadowShader:send('shadowMap', shadowMap)
|
|
||||||
self.shadowShader:send('lightColor', {self.red / 255.0, self.green / 255.0, self.blue / 255.0})
|
|
||||||
self.shadowShader:send("lightPosition", {(self.x + l/s) * s, (h/s - (self.y + t/s)) * s, (self.z * 10) / 255.0})
|
|
||||||
self.shadowShader:send('lightRange',{self.range * s})
|
|
||||||
self.shadowShader:send("lightSmooth", self.smooth)
|
|
||||||
self.shadowShader:send("lightGlow", {1.0 - self.glowSize, self.glowStrength})
|
|
||||||
self.shadowShader:send("lightAngle", math.pi - self.angle / 2.0)
|
|
||||||
self.shadowShader:send("lightDirection", self.direction)
|
|
||||||
self.shadowShader:send("invert_normal", self.normalInvert == true)
|
|
||||||
util.drawCanvasToCanvas(normalMap, canvas, {
|
|
||||||
blendmode = 'additive',
|
|
||||||
shader = self.shadowShader
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function light:setVisible(visible)
|
function light:setVisible(visible)
|
||||||
self.visible = visible
|
self.visible = visible
|
||||||
end
|
end
|
||||||
|
@ -59,16 +59,6 @@ function post_shader:refreshScreenSize(w, h)
|
|||||||
self.render_buffer = love.graphics.newCanvas(w, h)
|
self.render_buffer = love.graphics.newCanvas(w, h)
|
||||||
self.back_buffer = love.graphics.newCanvas(w, h)
|
self.back_buffer = love.graphics.newCanvas(w, h)
|
||||||
|
|
||||||
post_shader.blurv:send("screen", {w, h})
|
|
||||||
post_shader.blurh:send("screen", {w, h})
|
|
||||||
for shaderName, v in pairs(shaders) do
|
|
||||||
for def in pairs(v[2]) do
|
|
||||||
if def == "screen" or def == "textureSize" or def == "inputSize" or def == "outputSize" then
|
|
||||||
v[1]:send(def, {w, h})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
self.w = w
|
self.w = w
|
||||||
self.h = h
|
self.h = h
|
||||||
end
|
end
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern float steps = 2.0;
|
extern float steps = 2.0;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
vec2 pSize = vec2(1.0 / love_ScreenSize.x, 1.0 / love_ScreenSize.y);
|
||||||
vec4 col = Texel(texture, texture_coords);
|
vec4 col = Texel(texture, texture_coords);
|
||||||
for(int i = 1; i <= steps; i++) {
|
for(int i = 1; i <= steps; i++) {
|
||||||
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * i));
|
col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * i));
|
||||||
|
@ -1,8 +1,7 @@
|
|||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern float steps = 2.0;
|
extern float steps = 2.0;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
vec2 pSize = vec2(1.0 / love_ScreenSize.x, 1.0 / love_ScreenSize.y);
|
||||||
vec4 col = Texel(texture, texture_coords);
|
vec4 col = Texel(texture, texture_coords);
|
||||||
for(int i = 1; i <= steps; i++) {
|
for(int i = 1; i <= steps; i++) {
|
||||||
col = col + Texel(texture, vec2(texture_coords.x - pSize.x * i, texture_coords.y));
|
col = col + Texel(texture, vec2(texture_coords.x - pSize.x * i, texture_coords.y));
|
||||||
|
@ -2,7 +2,6 @@ extern float exposure = 0.7;
|
|||||||
extern float brightness = 1.0;
|
extern float brightness = 1.0;
|
||||||
extern vec3 lumacomponents = vec3(1.0, 1.0, 1.0);
|
extern vec3 lumacomponents = vec3(1.0, 1.0, 1.0);
|
||||||
|
|
||||||
|
|
||||||
// luma
|
// luma
|
||||||
//const vec3 lumcoeff = vec3(0.299,0.587,0.114);
|
//const vec3 lumcoeff = vec3(0.299,0.587,0.114);
|
||||||
const vec3 lumcoeff = vec3(0.212671, 0.715160, 0.072169);
|
const vec3 lumcoeff = vec3(0.212671, 0.715160, 0.072169);
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern vec2 redStrength = vec2(4.0, 3.0);
|
extern vec2 redStrength = vec2(4.0, 3.0);
|
||||||
extern vec2 greenStrength = vec2(-2.0, -1.0);
|
extern vec2 greenStrength = vec2(-2.0, -1.0);
|
||||||
extern vec2 blueStrength = vec2(1.0, -3.0);
|
extern vec2 blueStrength = vec2(1.0, -3.0);
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
vec2 pSize = vec2(1.0 / love_ScreenSize.x, 1.0 / love_ScreenSize.y);
|
||||||
float colRed = Texel(texture, vec2(texture_coords.x + pSize.x * redStrength.x, texture_coords.y - pSize.y * redStrength.y)).r;
|
float colRed = Texel(texture, vec2(texture_coords.x + pSize.x * redStrength.x, texture_coords.y - pSize.y * redStrength.y)).r;
|
||||||
float colGreen = Texel(texture, vec2(texture_coords.x + pSize.x * greenStrength.x, texture_coords.y - pSize.y * greenStrength.y)).g;
|
float colGreen = Texel(texture, vec2(texture_coords.x + pSize.x * greenStrength.x, texture_coords.y - pSize.y * greenStrength.y)).g;
|
||||||
float colBlue = Texel(texture, vec2(texture_coords.x + pSize.x * blueStrength.x, texture_coords.y - pSize.y * blueStrength.y)).b;
|
float colBlue = Texel(texture, vec2(texture_coords.x + pSize.x * blueStrength.x, texture_coords.y - pSize.y * blueStrength.y)).b;
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
{
|
|
||||||
vec3 col = Texel(texture, texture_coords).rgb * 2.0;
|
vec3 col = Texel(texture, texture_coords).rgb * 2.0;
|
||||||
col *= col;
|
col *= col;
|
||||||
return vec4(col, 1.0);
|
return vec4(col, 1.0);
|
||||||
|
@ -1,88 +1,19 @@
|
|||||||
extern vec2 inputSize;
|
|
||||||
extern vec2 textureSize;
|
|
||||||
|
|
||||||
|
|
||||||
#define distortion 0.2
|
#define distortion 0.2
|
||||||
|
vec2 radialDistortion(vec2 coord) {
|
||||||
/*
|
|
||||||
#define f 0.6
|
|
||||||
#define ox 0.5
|
|
||||||
#define oy 0.5
|
|
||||||
#define scale 0.8
|
|
||||||
#define k1 0.7
|
|
||||||
#define k2 -0.5
|
|
||||||
|
|
||||||
vec2 barrelDistort(vec2 coord)
|
|
||||||
{
|
|
||||||
vec2 xy = (coord - vec2(ox, oy))/vec2(f) * scale;
|
|
||||||
|
|
||||||
vec2 r = vec2(sqrt(dot(xy, xy)));
|
|
||||||
|
|
||||||
float r2 = float(r*r);
|
|
||||||
|
|
||||||
float r4 = r2*r2;
|
|
||||||
|
|
||||||
float coeff = (k1*r2 + k2*r4);
|
|
||||||
|
|
||||||
return ((xy+xy*coeff) * f) + vec2(ox, oy);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
vec2 radialDistortion(vec2 coord, const vec2 ratio)
|
|
||||||
{
|
|
||||||
float offsety = 1.0 - ratio.y;
|
|
||||||
coord.y -= offsety;
|
|
||||||
coord /= ratio;
|
|
||||||
|
|
||||||
vec2 cc = coord - 0.5;
|
vec2 cc = coord - 0.5;
|
||||||
float dist = dot(cc, cc) * distortion;
|
float dist = dot(cc, cc) * distortion;
|
||||||
vec2 result = coord + cc * (1.0 + dist) * dist;
|
return coord + cc * (1.0 + dist) * dist;
|
||||||
|
|
||||||
result *= ratio;
|
|
||||||
result.y += offsety;
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
vec4 checkTexelBounds(Image texture, vec2 coords, vec2 bounds)
|
|
||||||
{
|
|
||||||
vec4 color = Texel(texture, coords) *
|
|
||||||
|
|
||||||
vec2 ss = step(coords, vec2(bounds.x, 1.0)) * step(vec2(0.0, bounds.y), coords);
|
vec4 checkTexelBounds(Image texture, vec2 coords) {
|
||||||
|
vec2 ss = step(coords, vec2(1.0, 1.0)) * step(vec2(0.0, 0.0), coords);
|
||||||
color.rgb *= ss.x * ss.y;
|
|
||||||
color.a = step(color.a, ss.x * ss.y);
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
vec4 checkTexelBounds(Image texture, vec2 coords, vec2 bounds)
|
|
||||||
{
|
|
||||||
vec2 ss = step(coords, vec2(bounds.x, 1.0)) * step(vec2(0.0, bounds.y), coords);
|
|
||||||
return Texel(texture, coords) * ss.x * ss.y;
|
return Texel(texture, coords) * ss.x * ss.y;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec4 checkTexelBounds(Image texture, vec2 coords)
|
vec2 coords = radialDistortion(texture_coords);
|
||||||
{
|
vec4 texcolor = checkTexelBounds(texture, coords);
|
||||||
vec2 bounds = vec2(inputSize.x / textureSize.x, 1.0 - inputSize.y / textureSize.y);
|
|
||||||
|
|
||||||
vec4 color;
|
|
||||||
if (coords.x > bounds.x || coords.x < 0.0 || coords.y > 1.0 || coords.y < bounds.y)
|
|
||||||
color = vec4(0.0, 0.0, 0.0, 1.0);
|
|
||||||
else
|
|
||||||
color = Texel(texture, coords);
|
|
||||||
|
|
||||||
return color;
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
|
||||||
{
|
|
||||||
vec2 coords = radialDistortion(texture_coords, inputSize / textureSize);
|
|
||||||
|
|
||||||
vec4 texcolor = checkTexelBounds(texture, coords, vec2(inputSize.x / textureSize.x, 1.0 - inputSize.y / textureSize.y));
|
|
||||||
texcolor.a = 1.0;
|
texcolor.a = 1.0;
|
||||||
|
|
||||||
return texcolor;
|
return texcolor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,9 +6,6 @@
|
|||||||
modified by slime73 for use with love2d and mari0
|
modified by slime73 for use with love2d and mari0
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
extern vec2 textureSize;
|
|
||||||
|
|
||||||
vec3 grayscale(vec3 color)
|
vec3 grayscale(vec3 color)
|
||||||
{
|
{
|
||||||
return vec3(dot(color, vec3(0.3, 0.59, 0.11)));
|
return vec3(dot(color, vec3(0.3, 0.59, 0.11)));
|
||||||
@ -18,8 +15,8 @@ vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
|||||||
{
|
{
|
||||||
vec4 texcolor = Texel(texture, tex);
|
vec4 texcolor = Texel(texture, tex);
|
||||||
|
|
||||||
float x = 0.5 / textureSize.x;
|
float x = 0.5 / love_ScreenSize.x;
|
||||||
float y = 0.5 / textureSize.y;
|
float y = 0.5 / love_ScreenSize.y;
|
||||||
vec2 dg1 = vec2( x, y);
|
vec2 dg1 = vec2( x, y);
|
||||||
vec2 dg2 = vec2(-x, y);
|
vec2 dg2 = vec2(-x, y);
|
||||||
|
|
||||||
@ -29,7 +26,7 @@ vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
|||||||
vec3 c20 = Texel(texture, tex - dg2).xyz;
|
vec3 c20 = Texel(texture, tex - dg2).xyz;
|
||||||
vec3 c22 = Texel(texture, tex + dg1).xyz;
|
vec3 c22 = Texel(texture, tex + dg1).xyz;
|
||||||
|
|
||||||
vec2 texsize = textureSize;
|
vec2 texsize = love_ScreenSize.xy;
|
||||||
|
|
||||||
vec3 first = mix(c00, c20, fract(tex.x * texsize.x + 0.5));
|
vec3 first = mix(c00, c20, fract(tex.x * texsize.x + 0.5));
|
||||||
vec3 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5));
|
vec3 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5));
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
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 rgb = Texel(texture, texture_coords);
|
vec4 rgb = Texel(texture, texture_coords);
|
||||||
vec4 intens = smoothstep(0.2,0.8,rgb) + normalize(vec4(rgb.xyz, 1.0));
|
vec4 intens = smoothstep(0.2,0.8,rgb) + normalize(vec4(rgb.xyz, 1.0));
|
||||||
|
|
||||||
|
@ -18,8 +18,6 @@
|
|||||||
)
|
)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern vec2 textureSize;
|
|
||||||
|
|
||||||
|
|
||||||
// 0.5 = the spot stays inside the original pixel
|
// 0.5 = the spot stays inside the original pixel
|
||||||
// 1.0 = the spot bleeds up to the center of next pixel
|
// 1.0 = the spot bleeds up to the center of next pixel
|
||||||
@ -80,7 +78,7 @@ vec4 B_IN = vec4(1.0) - A_IN;
|
|||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
vec4 grid_color( vec2 coords )
|
vec4 grid_color( vec2 coords )
|
||||||
{
|
{
|
||||||
vec2 snes = floor( coords * textureSize );
|
vec2 snes = floor( coords * love_ScreenSize.xy );
|
||||||
if ( (mod(snes.x, 3.0) == 0.0) && (mod(snes.y, 3.0) == 0.0) )
|
if ( (mod(snes.x, 3.0) == 0.0) && (mod(snes.y, 3.0) == 0.0) )
|
||||||
return texture2D(_tex0_, coords);
|
return texture2D(_tex0_, coords);
|
||||||
else
|
else
|
||||||
@ -93,16 +91,16 @@ vec4 grid_color( vec2 coords )
|
|||||||
|
|
||||||
#endif // DEBUG
|
#endif // DEBUG
|
||||||
|
|
||||||
vec2 onex = vec2( 1.0/textureSize.x, 0.0 );
|
vec2 onex = vec2( 1.0/love_ScreenSize.x, 0.0 );
|
||||||
vec2 oney = vec2( 0.0, 1.0/textureSize.y );
|
vec2 oney = vec2( 0.0, 1.0/love_ScreenSize.y );
|
||||||
|
|
||||||
vec4 effect(vec4 vcolor, Image texture, vec2 texCoord, vec2 pixel_coords)
|
vec4 effect(vec4 vcolor, Image texture, vec2 texCoord, vec2 pixel_coords)
|
||||||
{
|
{
|
||||||
vec2 coords = (texCoord * textureSize);
|
vec2 coords = (texCoord * love_ScreenSize.xy);
|
||||||
vec2 pixel_start = floor(coords);
|
vec2 pixel_start = floor(coords);
|
||||||
coords -= pixel_start;
|
coords -= pixel_start;
|
||||||
vec2 pixel_center = pixel_start + vec2(0.5);
|
vec2 pixel_center = pixel_start + vec2(0.5);
|
||||||
vec2 texture_coords = pixel_center / textureSize;
|
vec2 texture_coords = pixel_center / love_ScreenSize.xy;
|
||||||
|
|
||||||
vec4 color = vec4(0.0);
|
vec4 color = vec4(0.0);
|
||||||
vec4 pixel;
|
vec4 pixel;
|
||||||
|
@ -1,9 +1,6 @@
|
|||||||
#define glarebasesize 0.896
|
#define glarebasesize 0.896
|
||||||
#define power 0.50
|
#define power 0.50
|
||||||
|
|
||||||
extern vec2 textureSize;
|
|
||||||
extern vec2 outputSize;
|
extern vec2 outputSize;
|
||||||
|
|
||||||
extern float time;
|
extern float time;
|
||||||
|
|
||||||
const vec3 green = vec3(0.17, 0.62, 0.25);
|
const vec3 green = vec3(0.17, 0.62, 0.25);
|
||||||
@ -27,7 +24,7 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texcoord, vec2 pixel_coords)
|
|||||||
vec4 sum = vec4(0.0);
|
vec4 sum = vec4(0.0);
|
||||||
vec4 bum = vec4(0.0);
|
vec4 bum = vec4(0.0);
|
||||||
|
|
||||||
vec2 glaresize = vec2(glarebasesize) / textureSize;
|
vec2 glaresize = vec2(glarebasesize) / love_ScreenSize.xy;
|
||||||
|
|
||||||
float y_one = 1.0 / outputSize.y;
|
float y_one = 1.0 / outputSize.y;
|
||||||
|
|
||||||
|
@ -1,13 +1,10 @@
|
|||||||
|
|
||||||
extern vec2 textureSize;
|
|
||||||
|
|
||||||
const float pixel_w = 2.0;
|
const float pixel_w = 2.0;
|
||||||
const float pixel_h = 2.0;
|
const float pixel_h = 2.0;
|
||||||
|
|
||||||
vec4 effect(vec4 vcolor, Image texture, vec2 uv, vec2 pixel_coords)
|
vec4 effect(vec4 vcolor, Image texture, vec2 uv, vec2 pixel_coords)
|
||||||
{
|
{
|
||||||
float dx = pixel_w*(1.0/textureSize.x);
|
float dx = pixel_w*(1.0/love_ScreenSize.x);
|
||||||
float dy = pixel_h*(1.0/textureSize.y);
|
float dy = pixel_h*(1.0/love_ScreenSize.y);
|
||||||
vec2 coord = vec2(dx*floor(uv.x/dx), dy*floor(uv.y/dy));
|
vec2 coord = vec2(dx*floor(uv.x/dx), dy*floor(uv.y/dy));
|
||||||
return Texel(texture, coord);
|
return Texel(texture, coord);
|
||||||
}
|
}
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
extern number blurstart = 1.0; // 0 to 1
|
extern number blurstart = 1.0; // 0 to 1
|
||||||
extern number blurwidth = -0.02; // -1 to 1
|
extern number blurwidth = -0.02; // -1 to 1
|
||||||
|
|
||||||
|
|
||||||
vec4 effect(vec4 vcolor, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
vec4 effect(vec4 vcolor, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
||||||
{
|
{
|
||||||
vec4 c = vec4(0.0, 0.0, 0.0, 1.0);
|
vec4 c = vec4(0.0, 0.0, 0.0, 1.0);
|
||||||
|
@ -1,9 +1,8 @@
|
|||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern float strength = 2.0;
|
extern float strength = 2.0;
|
||||||
extern float time = 0.0;
|
extern float time = 0.0;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||||
vec2 pSize = 1.0 / screen;
|
vec2 pSize = 1.0 / love_ScreenSize.xy;
|
||||||
float brightness = 1.0;
|
float brightness = 1.0;
|
||||||
float offsetX = sin(texture_coords.y * 10.0 + time * strength) * pSize.x;
|
float offsetX = sin(texture_coords.y * 10.0 + time * strength) * pSize.x;
|
||||||
float corner = 500.0;
|
float corner = 500.0;
|
||||||
|
@ -17,12 +17,10 @@ vec4 compress(vec4 in_color, float threshold, float ratio)
|
|||||||
return in_color - (diff * (1.0 - 1.0/ratio));
|
return in_color - (diff * (1.0 - 1.0/ratio));
|
||||||
}
|
}
|
||||||
|
|
||||||
extern vec2 textureSize;
|
|
||||||
|
|
||||||
vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
||||||
{
|
{
|
||||||
float x = 0.5 * (1.0 / textureSize.x);
|
float x = 0.5 * (1.0 / love_ScreenSize.x);
|
||||||
float y = 0.5 * (1.0 / textureSize.y);
|
float y = 0.5 * (1.0 / love_ScreenSize.y);
|
||||||
|
|
||||||
vec2 dg1 = vec2( x, y);
|
vec2 dg1 = vec2( x, y);
|
||||||
vec2 dg2 = vec2(-x, y);
|
vec2 dg2 = vec2(-x, y);
|
||||||
@ -39,7 +37,7 @@ vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
|||||||
vec3 c21 = Texel(texture, tex + dx).xyz;
|
vec3 c21 = Texel(texture, tex + dx).xyz;
|
||||||
vec3 c22 = Texel(texture, tex + dg1).xyz;
|
vec3 c22 = Texel(texture, tex + dg1).xyz;
|
||||||
|
|
||||||
vec2 texsize = textureSize;
|
vec2 texsize = love_ScreenSize.xy;
|
||||||
|
|
||||||
vec3 first = mix(c00, c20, fract(tex.x * texsize.x + 0.5));
|
vec3 first = mix(c00, c20, fract(tex.x * texsize.x + 0.5));
|
||||||
vec3 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5));
|
vec3 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5));
|
||||||
|
@ -1,11 +1,9 @@
|
|||||||
extern Image backBuffer;
|
extern Image backBuffer;
|
||||||
|
|
||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern float reflectionStrength;
|
extern float reflectionStrength;
|
||||||
extern float reflectionVisibility;
|
extern float reflectionVisibility;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
vec2 pSize = vec2(1.0 / love_ScreenSize.x, 1.0 / love_ScreenSize.y);
|
||||||
vec4 normal = Texel(texture, texture_coords);
|
vec4 normal = Texel(texture, texture_coords);
|
||||||
if(normal.a > 0.0 && normal.r > 0.0) {
|
if(normal.a > 0.0 && normal.r > 0.0) {
|
||||||
vec3 pColor = Texel(backBuffer, texture_coords).rgb;
|
vec3 pColor = Texel(backBuffer, texture_coords).rgb;
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
extern Image backBuffer;
|
extern Image backBuffer;
|
||||||
|
|
||||||
extern vec2 screen = vec2(800.0, 600.0);
|
|
||||||
extern float refractionStrength = 1.0;
|
extern float refractionStrength = 1.0;
|
||||||
|
|
||||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||||
vec2 pSize = vec2(1.0 / screen.x, 1.0 / screen.y);
|
vec2 pSize = vec2(1.0 / love_ScreenSize.x, 1.0 / love_ScreenSize.y);
|
||||||
vec4 normal = Texel(texture, texture_coords);
|
vec4 normal = Texel(texture, texture_coords);
|
||||||
if(normal.b > 0.0) {
|
if(normal.b > 0.0) {
|
||||||
vec4 normalOffset = Texel(texture, vec2(texture_coords.x + (normal.x - 0.5) * pSize.x * refractionStrength, texture_coords.y + (normal.y - 0.5) * pSize.y * refractionStrength));
|
vec4 normalOffset = Texel(texture, vec2(texture_coords.x + (normal.x - 0.5) * pSize.x * refractionStrength, texture_coords.y + (normal.y - 0.5) * pSize.y * refractionStrength));
|
||||||
|
@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
#define PI 3.1415926535897932384626433832795
|
#define PI 3.1415926535897932384626433832795
|
||||||
|
|
||||||
extern vec2 screenResolution; //size of the screen
|
|
||||||
extern Image shadowMap; //a canvas containing shadow data only
|
extern Image shadowMap; //a canvas containing shadow data only
|
||||||
extern vec3 lightPosition; //the light position on the screen(not global)
|
extern vec3 lightPosition; //the light position on the screen(not global)
|
||||||
extern vec3 lightColor; //the rgb color of the light
|
extern vec3 lightColor; //the rgb color of the light
|
||||||
@ -70,8 +69,8 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
|||||||
return pixel;
|
return pixel;
|
||||||
} else {
|
} else {
|
||||||
//on the normal map, draw normal shadows
|
//on the normal map, draw normal shadows
|
||||||
vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / screenResolution.xy, lightPosition.z);
|
vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / love_ScreenSize.xy, lightPosition.z);
|
||||||
dir.x *= screenResolution.x / screenResolution.y;
|
dir.x *= love_ScreenSize.x / love_ScreenSize.y;
|
||||||
vec3 diff = lightColor * max(dot(normalize(normal), normalize(dir)), 0.0);
|
vec3 diff = lightColor * max(dot(normalize(normal), normalize(dir)), 0.0);
|
||||||
//return the light that is effected by the normal and attenuation
|
//return the light that is effected by the normal and attenuation
|
||||||
return vec4(diff * att, 1.0);
|
return vec4(diff * att, 1.0);
|
||||||
|
Loading…
Reference in New Issue
Block a user