Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tile_shader = love.graphics.newShader[[
- vec4 darkenPixel();
- vec4 darkenPixel( vec4 pixel, number darkness , number initial_lightness) {
- number r = pixel.r * darkness * initial_lightness;
- number g = pixel.g * darkness * initial_lightness;
- number b = pixel.b * darkness * initial_lightness;
- return vec4(r, g, b, pixel.a);
- }
- extern number initial_lightness;
- extern bool top;
- extern bool bottom;
- extern bool left;
- extern bool right;
- extern bool top_left;
- extern bool top_right;
- extern bool bottom_left;
- extern bool bottom_right;
- vec4 effect( vec4 colour, Image texture, vec2 texture_coords, vec2 screen_coords ) {
- number lightness_multiplier = 1.75;
- number spread = 2.3;
- number x = texture_coords.x;
- number y = texture_coords.y;
- number diffX = x - 0.5;
- number diffY = y - 0.5;
- vec4 pixel = Texel(texture, texture_coords);
- number magnitude = sqrt(pow(diffX, 2) + pow(diffY, 2));
- if (top && diffY <= 0 || bottom && diffY >= 0)
- magnitude = min(abs(0.5 - x), magnitude);
- if (left && diffX <= 0 || right && diffX >= 0)
- magnitude = min(abs(0.5 - y), magnitude);
- if (top && left && top_left && y < 1 - x || bottom && right && bottom_right && y > 1 - x) {
- magnitude = min(abs(x - y) / sqrt(2), magnitude);
- bool top_left_top = top && diffX <= 0 && y < x;
- bool top_left_left = left && diffY <= 0 && y > x;
- bool bot_right_bot = bottom && diffX >= 0 && y > x;
- bool bot_right_right = right && diffY >= 0 && y < x;
- if (top_left_top || top_left_left || bot_right_bot || bot_right_right)
- magnitude = 0;
- }
- if (top && right && top_right && y < x || bottom && left && bottom_left && y > x){
- magnitude = min(abs(x + y - 1) / sqrt(2), magnitude);
- bool top_right_top = top && diffX >= 0 && y < 1 - x;
- bool top_right_right = right && diffY <= 0 && y > 1 - x;
- bool bot_left_bot = bottom && diffX <= 0 && y > 1 - x;
- bool bot_left_left = left && diffY >= 0 && y < 1 - x;
- if (top_right_top || top_right_right || bot_left_bot || bot_left_left)
- magnitude = 0;
- }
- magnitude = pow(magnitude, 2) * spread;
- number darkness = 1 - ((1 - magnitude) / lightness_multiplier);
- vec4 newPixel = darkenPixel(pixel, darkness, initial_lightness);
- return newPixel;
- }
- ]]
Advertisement
Add Comment
Please, Sign In to add comment