From 8ddb4138b1eeea3ea6e84719fb4d60c3a3172ca5 Mon Sep 17 00:00:00 2001 From: Tim Anema Date: Sat, 13 Dec 2014 16:47:48 -0500 Subject: [PATCH] updating shaders so I dont have to pass in screen sizes --- lib/body.lua | 45 +++++----- lib/init.lua | 32 ++++--- lib/light.lua | 24 ------ lib/postshader.lua | 10 --- lib/shaders/blurh.glsl | 5 +- lib/shaders/blurv.glsl | 5 +- lib/shaders/postshaders/black_and_white.glsl | 1 - .../postshaders/chromatic_aberration.glsl | 5 +- lib/shaders/postshaders/contrast.glsl | 5 +- lib/shaders/postshaders/curvature.glsl | 83 ++----------------- lib/shaders/postshaders/edges.glsl | 9 +- lib/shaders/postshaders/hdr_tv.glsl | 3 +- lib/shaders/postshaders/phosphor.glsl | 12 ++- lib/shaders/postshaders/pip.glsl | 5 +- lib/shaders/postshaders/pixellate.glsl | 7 +- lib/shaders/postshaders/radialblur.glsl | 1 - lib/shaders/postshaders/scanlines.glsl | 3 +- lib/shaders/postshaders/waterpaint.glsl | 8 +- lib/shaders/reflection.glsl | 6 +- lib/shaders/refraction.glsl | 6 +- lib/shaders/shadow.glsl | 5 +- 21 files changed, 77 insertions(+), 203 deletions(-) diff --git a/lib/body.lua b/lib/body.lua index 4ef344e..1da2f21 100644 --- a/lib/body.lua +++ b/lib/body.lua @@ -695,10 +695,10 @@ end function body:drawCircleShadow(light) local curShadowGeometry = {} 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 y2 = ((self.y - self.oy) - math.cos(angle) * self.radius) - local x3 = ((self.x - self.ox) - math.sin(angle) * self.radius) - local y3 = ((self.y - self.oy) + math.cos(angle) * self.radius) + local x1 = ((self.x - self.ox) + math.sin(angle) * self.radius) + local y1 = ((self.y - self.oy) - math.cos(angle) * self.radius) + local x2 = ((self.x - self.ox) - math.sin(angle) * self.radius) + local y2 = ((self.y - self.oy) + math.cos(angle) * self.radius) local lxh = (light.x * self.zheight) local lyh = (light.y * self.zheight) @@ -707,29 +707,26 @@ function body:drawCircleShadow(light) height_diff = -0.001 end - local x4 = (lxh - (x3 * light.z))/height_diff - local y4 = (lyh - (y3 * light.z))/height_diff - local x5 = (lxh - (x2 * light.z))/height_diff - local y5 = (lyh - (y2 * light.z))/height_diff + local x3 = (lxh - (x2 * light.z))/height_diff + local y3 = (lyh - (y2 * light.z))/height_diff + local x4 = (lxh - (x1 * 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 cx, cy = (x4 + x5)/2, (y4 + y5)/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)) + local radius = math.sqrt(math.pow(x4 - x3, 2) + math.pow(y4-y3, 2)) / 2 + local cx, cy = (x3 + x4)/2, (y3 + y4)/2 - if distance1 >= self.radius then - love.graphics.polygon("fill", x2, y2, x3, y3, x4, y4, x5, y5) - end - - 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.circle("fill", cx, cy, radius) - elseif distance2 < light.range then -- dont draw circle if way off screen - local angle1 = math.atan2(y4 - cy, x4 - cx) - local angle2 = math.atan2(y5 - cy, x5 - cx) - if angle1 > angle2 then - love.graphics.arc("fill", cx, cy, radius, angle1, angle2) - else - love.graphics.arc("fill", cx, cy, radius, angle1 - math.pi, angle2 - math.pi) + else + love.graphics.polygon("fill", x1, y1, x2, y2, x3, y3, x4, y4) + 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 + local angle1 = math.atan2(y3 - cy, x3 - cx) + local angle2 = math.atan2(y4 - cy, x4 - cx) + if angle1 > angle2 then + 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 diff --git a/lib/init.lua b/lib/init.lua index 384072a..771f360 100644 --- a/lib/init.lua +++ b/lib/init.lua @@ -33,6 +33,7 @@ local light_world = class() light_world.blurv = love.graphics.newShader(_PACKAGE.."shaders/blurv.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.reflectionShader = love.graphics.newShader(_PACKAGE.."shaders/reflection.glsl") @@ -50,6 +51,7 @@ function light_world:init(options) self.glowBlur = 1.0 self.glowTimer = 0.0 self.glowDown = false + self.normalInvert = false self.disableGlow = false self.disableMaterial = false @@ -78,15 +80,6 @@ function light_world:refreshScreenSize(w, h) self.reflectionMap = 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) end @@ -136,18 +129,31 @@ function light_world:drawNormalShading(l,t,w,h,s) self.normal2:clear() 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 self.shadowMap:clear() util.drawto(self.shadowMap, l, t, s, function() 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 - self.body[k]:drawShadow(self.lights[i]) + if self.body[k]:isInLightRange(light) and self.body[k]:isInRange(-l,-t,w,h,s) then + self.body[k]:drawShadow(light) end end end) -- 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 diff --git a/lib/light.lua b/lib/light.lua index f6e6f6d..5c70ecb 100644 --- a/lib/light.lua +++ b/lib/light.lua @@ -1,11 +1,8 @@ local _PACKAGE = (...):match("^(.+)[%./][^%./]+") or "" local class = require(_PACKAGE.."/class") -local util = require(_PACKAGE..'/util') local light = class() -light.shadowShader = love.graphics.newShader(_PACKAGE.."/shaders/shadow.glsl") - function light:init(x, y, r, g, b, range) self.direction = 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.glowStrength = 0.0 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 -- 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 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) self.visible = visible end diff --git a/lib/postshader.lua b/lib/postshader.lua index 7db59a4..3ce4fcb 100644 --- a/lib/postshader.lua +++ b/lib/postshader.lua @@ -59,16 +59,6 @@ function post_shader:refreshScreenSize(w, h) self.render_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.h = h end diff --git a/lib/shaders/blurh.glsl b/lib/shaders/blurh.glsl index 747f383..ae58eff 100644 --- a/lib/shaders/blurh.glsl +++ b/lib/shaders/blurh.glsl @@ -1,8 +1,7 @@ -extern vec2 screen = vec2(800.0, 600.0); extern float steps = 2.0; 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); for(int i = 1; i <= steps; i++) { col = col + Texel(texture, vec2(texture_coords.x, texture_coords.y - pSize.y * i)); @@ -10,4 +9,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { } col = col / (steps * 2.0 + 1.0); return vec4(col.r, col.g, col.b, 1.0); -} \ No newline at end of file +} diff --git a/lib/shaders/blurv.glsl b/lib/shaders/blurv.glsl index f92b51a..00b929e 100644 --- a/lib/shaders/blurv.glsl +++ b/lib/shaders/blurv.glsl @@ -1,8 +1,7 @@ -extern vec2 screen = vec2(800.0, 600.0); extern float steps = 2.0; 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); for(int i = 1; i <= steps; i++) { col = col + Texel(texture, vec2(texture_coords.x - pSize.x * i, texture_coords.y)); @@ -10,4 +9,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { } col = col / (steps * 2.0 + 1.0); return vec4(col.r, col.g, col.b, 1.0); -} \ No newline at end of file +} diff --git a/lib/shaders/postshaders/black_and_white.glsl b/lib/shaders/postshaders/black_and_white.glsl index 57093f6..16c9d8a 100644 --- a/lib/shaders/postshaders/black_and_white.glsl +++ b/lib/shaders/postshaders/black_and_white.glsl @@ -2,7 +2,6 @@ extern float exposure = 0.7; extern float brightness = 1.0; extern vec3 lumacomponents = vec3(1.0, 1.0, 1.0); - // luma //const vec3 lumcoeff = vec3(0.299,0.587,0.114); const vec3 lumcoeff = vec3(0.212671, 0.715160, 0.072169); diff --git a/lib/shaders/postshaders/chromatic_aberration.glsl b/lib/shaders/postshaders/chromatic_aberration.glsl index 6d6909c..a86ade2 100644 --- a/lib/shaders/postshaders/chromatic_aberration.glsl +++ b/lib/shaders/postshaders/chromatic_aberration.glsl @@ -1,13 +1,12 @@ -extern vec2 screen = vec2(800.0, 600.0); extern vec2 redStrength = vec2(4.0, 3.0); extern vec2 greenStrength = vec2(-2.0, -1.0); extern vec2 blueStrength = vec2(1.0, -3.0); 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 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; return vec4(colRed, colGreen, colBlue, 1.0); -} \ No newline at end of file +} diff --git a/lib/shaders/postshaders/contrast.glsl b/lib/shaders/postshaders/contrast.glsl index 066a794..dea0d10 100644 --- a/lib/shaders/postshaders/contrast.glsl +++ b/lib/shaders/postshaders/contrast.glsl @@ -1,6 +1,5 @@ -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; col *= col; return vec4(col, 1.0); -} \ No newline at end of file +} diff --git a/lib/shaders/postshaders/curvature.glsl b/lib/shaders/postshaders/curvature.glsl index 8f9a942..6f23acb 100644 --- a/lib/shaders/postshaders/curvature.glsl +++ b/lib/shaders/postshaders/curvature.glsl @@ -1,88 +1,19 @@ -extern vec2 inputSize; -extern vec2 textureSize; - - #define distortion 0.2 - -/* -#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 radialDistortion(vec2 coord) { vec2 cc = coord - 0.5; float dist = dot(cc, cc) * distortion; - vec2 result = coord + cc * (1.0 + dist) * dist; - - result *= ratio; - result.y += offsety; - - return result; + return coord + cc * (1.0 + dist) * dist; } -/* -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); - - 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); +vec4 checkTexelBounds(Image texture, vec2 coords) { + vec2 ss = step(coords, vec2(1.0, 1.0)) * step(vec2(0.0, 0.0), coords); return Texel(texture, coords) * ss.x * ss.y; } -/* -vec4 checkTexelBounds(Image texture, vec2 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)); +vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { + vec2 coords = radialDistortion(texture_coords); + vec4 texcolor = checkTexelBounds(texture, coords); texcolor.a = 1.0; - return texcolor; } diff --git a/lib/shaders/postshaders/edges.glsl b/lib/shaders/postshaders/edges.glsl index 3fcf360..c8add09 100644 --- a/lib/shaders/postshaders/edges.glsl +++ b/lib/shaders/postshaders/edges.glsl @@ -6,9 +6,6 @@ modified by slime73 for use with love2d and mari0 */ - -extern vec2 textureSize; - vec3 grayscale(vec3 color) { 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); - float x = 0.5 / textureSize.x; - float y = 0.5 / textureSize.y; + float x = 0.5 / love_ScreenSize.x; + float y = 0.5 / love_ScreenSize.y; vec2 dg1 = 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 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 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5)); diff --git a/lib/shaders/postshaders/hdr_tv.glsl b/lib/shaders/postshaders/hdr_tv.glsl index 0bfcc90..ba5e30b 100644 --- a/lib/shaders/postshaders/hdr_tv.glsl +++ b/lib/shaders/postshaders/hdr_tv.glsl @@ -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 intens = smoothstep(0.2,0.8,rgb) + normalize(vec4(rgb.xyz, 1.0)); diff --git a/lib/shaders/postshaders/phosphor.glsl b/lib/shaders/postshaders/phosphor.glsl index f505d27..196f09b 100644 --- a/lib/shaders/postshaders/phosphor.glsl +++ b/lib/shaders/postshaders/phosphor.glsl @@ -18,8 +18,6 @@ ) */ -extern vec2 textureSize; - // 0.5 = the spot stays inside the original 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 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) ) return texture2D(_tex0_, coords); else @@ -93,16 +91,16 @@ vec4 grid_color( vec2 coords ) #endif // DEBUG -vec2 onex = vec2( 1.0/textureSize.x, 0.0 ); -vec2 oney = vec2( 0.0, 1.0/textureSize.y ); +vec2 onex = vec2( 1.0/love_ScreenSize.x, 0.0 ); +vec2 oney = vec2( 0.0, 1.0/love_ScreenSize.y ); 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); coords -= pixel_start; 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 pixel; diff --git a/lib/shaders/postshaders/pip.glsl b/lib/shaders/postshaders/pip.glsl index 42ab20b..94e134b 100644 --- a/lib/shaders/postshaders/pip.glsl +++ b/lib/shaders/postshaders/pip.glsl @@ -1,9 +1,6 @@ #define glarebasesize 0.896 #define power 0.50 - -extern vec2 textureSize; extern vec2 outputSize; - extern float time; 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 bum = vec4(0.0); - vec2 glaresize = vec2(glarebasesize) / textureSize; + vec2 glaresize = vec2(glarebasesize) / love_ScreenSize.xy; float y_one = 1.0 / outputSize.y; diff --git a/lib/shaders/postshaders/pixellate.glsl b/lib/shaders/postshaders/pixellate.glsl index 40f78e0..6a7935e 100644 --- a/lib/shaders/postshaders/pixellate.glsl +++ b/lib/shaders/postshaders/pixellate.glsl @@ -1,13 +1,10 @@ - -extern vec2 textureSize; - const float pixel_w = 2.0; const float pixel_h = 2.0; vec4 effect(vec4 vcolor, Image texture, vec2 uv, vec2 pixel_coords) { - float dx = pixel_w*(1.0/textureSize.x); - float dy = pixel_h*(1.0/textureSize.y); + float dx = pixel_w*(1.0/love_ScreenSize.x); + float dy = pixel_h*(1.0/love_ScreenSize.y); vec2 coord = vec2(dx*floor(uv.x/dx), dy*floor(uv.y/dy)); return Texel(texture, coord); } diff --git a/lib/shaders/postshaders/radialblur.glsl b/lib/shaders/postshaders/radialblur.glsl index d47766e..7836d5c 100644 --- a/lib/shaders/postshaders/radialblur.glsl +++ b/lib/shaders/postshaders/radialblur.glsl @@ -3,7 +3,6 @@ extern number blurstart = 1.0; // 0 to 1 extern number blurwidth = -0.02; // -1 to 1 - vec4 effect(vec4 vcolor, Image texture, vec2 texture_coords, vec2 pixel_coords) { vec4 c = vec4(0.0, 0.0, 0.0, 1.0); diff --git a/lib/shaders/postshaders/scanlines.glsl b/lib/shaders/postshaders/scanlines.glsl index 2e4582a..1e460d4 100644 --- a/lib/shaders/postshaders/scanlines.glsl +++ b/lib/shaders/postshaders/scanlines.glsl @@ -1,9 +1,8 @@ -extern vec2 screen = vec2(800.0, 600.0); extern float strength = 2.0; extern float time = 0.0; 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 offsetX = sin(texture_coords.y * 10.0 + time * strength) * pSize.x; float corner = 500.0; diff --git a/lib/shaders/postshaders/waterpaint.glsl b/lib/shaders/postshaders/waterpaint.glsl index 5461eb8..8c44c92 100644 --- a/lib/shaders/postshaders/waterpaint.glsl +++ b/lib/shaders/postshaders/waterpaint.glsl @@ -17,12 +17,10 @@ vec4 compress(vec4 in_color, float threshold, float ratio) return in_color - (diff * (1.0 - 1.0/ratio)); } -extern vec2 textureSize; - vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords) { - float x = 0.5 * (1.0 / textureSize.x); - float y = 0.5 * (1.0 / textureSize.y); + float x = 0.5 * (1.0 / love_ScreenSize.x); + float y = 0.5 * (1.0 / love_ScreenSize.y); vec2 dg1 = 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 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 second = mix(c02, c22, fract(tex.x * texsize.x + 0.5)); diff --git a/lib/shaders/reflection.glsl b/lib/shaders/reflection.glsl index edf662f..c2076b0 100644 --- a/lib/shaders/reflection.glsl +++ b/lib/shaders/reflection.glsl @@ -1,11 +1,9 @@ extern Image backBuffer; - -extern vec2 screen = vec2(800.0, 600.0); extern float reflectionStrength; extern float reflectionVisibility; 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); if(normal.a > 0.0 && normal.r > 0.0) { vec3 pColor = Texel(backBuffer, texture_coords).rgb; @@ -21,4 +19,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { } else { return vec4(0.0); } -} \ No newline at end of file +} diff --git a/lib/shaders/refraction.glsl b/lib/shaders/refraction.glsl index d9b3d23..8a6a27f 100644 --- a/lib/shaders/refraction.glsl +++ b/lib/shaders/refraction.glsl @@ -1,10 +1,8 @@ extern Image backBuffer; - -extern vec2 screen = vec2(800.0, 600.0); extern float refractionStrength = 1.0; 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); 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)); @@ -16,4 +14,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) { } else { return vec4(0.0); } -} \ No newline at end of file +} diff --git a/lib/shaders/shadow.glsl b/lib/shaders/shadow.glsl index 6c1da45..bb623b1 100644 --- a/lib/shaders/shadow.glsl +++ b/lib/shaders/shadow.glsl @@ -4,7 +4,6 @@ */ #define PI 3.1415926535897932384626433832795 -extern vec2 screenResolution; //size of the screen extern Image shadowMap; //a canvas containing shadow data only extern vec3 lightPosition; //the light position on the screen(not global) 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; } else { //on the normal map, draw normal shadows - vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / screenResolution.xy, lightPosition.z); - dir.x *= screenResolution.x / screenResolution.y; + vec3 dir = vec3((lightPosition.xy - pixel_coords.xy) / love_ScreenSize.xy, lightPosition.z); + dir.x *= love_ScreenSize.x / love_ScreenSize.y; vec3 diff = lightColor * max(dot(normalize(normal), normalize(dir)), 0.0); //return the light that is effected by the normal and attenuation return vec4(diff * att, 1.0);