diff options
author | the lemons <citrons@mondecitronne.com> | 2023-03-30 04:29:19 -0500 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2023-03-30 04:29:19 -0500 |
commit | d2125d718f19668f47bc51977834d9256e856333 (patch) | |
tree | 753cbefa2d8eb633e3ca5291d87d29fd630387e3 | |
parent | 97b4f497aa38894f9b09be57e95a5359447ac1f7 (diff) |
block textures
-rw-r--r-- | assets.lua | 2 | ||||
-rw-r--r-- | assets/img/block.png | bin | 0 -> 711039 bytes | |||
-rw-r--r-- | assets/shader/hueshift.glsl | 27 | ||||
-rw-r--r-- | game/gfx.lua | 32 |
4 files changed, 45 insertions, 16 deletions
@@ -2,6 +2,8 @@ local M = {} local loaders = { sfx = function(f) return love.audio.newSource(f, "static") end, + img = love.graphics.newImage, + shader = love.graphics.newShader, } local loaded = {} diff --git a/assets/img/block.png b/assets/img/block.png Binary files differnew file mode 100644 index 0000000..aa794ed --- /dev/null +++ b/assets/img/block.png diff --git a/assets/shader/hueshift.glsl b/assets/shader/hueshift.glsl new file mode 100644 index 0000000..fd7d343 --- /dev/null +++ b/assets/shader/hueshift.glsl @@ -0,0 +1,27 @@ +uniform vec3 colorize_to; + +// http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl +vec3 rgb2hsv(vec3 c) +{ + vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0); + vec4 p = c.g < c.b ? vec4(c.bg, K.wz) : vec4(c.gb, K.xy); + vec4 q = c.r < p.x ? vec4(p.xyw, c.r) : vec4(c.r, p.yzx); + + float d = q.x - min(q.w, q.y); + float e = 1.0e-10; + return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); +} + +vec3 hsv2rgb(vec3 c) +{ + vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); + vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); + return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y); +} + +vec4 effect(vec4 color, Image t, vec2 img_pos, vec2 screen_pos) { + vec4 pixel = Texel(t, img_pos); + vec3 hsv = rgb2hsv(pixel.xyz); + vec3 shifted = vec3(mod(hsv.x + colorize_to.x, 1), hsv.yz * colorize_to.yz); + return vec4(hsv2rgb(shifted).xyz, pixel.w) * color; +} diff --git a/game/gfx.lua b/game/gfx.lua index 37a451a..76fd6a2 100644 --- a/game/gfx.lua +++ b/game/gfx.lua @@ -14,13 +14,13 @@ function M.new(assets, game) end local colors = { - ["tetr.Z"] = {1, 0.2, 0.2}, - ["tetr.I"] = {0.2, 1, 1}, - ["tetr.J"] = {0.2, 0.2, 1}, - ["tetr.L"] = {1, 0.5, 0.2}, - ["tetr.O"] = {1, 1, 0.2}, - ["tetr.S"] = {0.2, 1, 0.2}, - ["tetr.T"] = {1, 0.2, 1}, + ["tetr.Z"] = {0, 1, 1}, + ["tetr.I"] = {0.5, 1, 1}, + ["tetr.J"] = {0.67, 1, 1}, + ["tetr.L"] = {0.08, 1, 1}, + ["tetr.O"] = {0.16, 1, 1}, + ["tetr.S"] = {0.33, 1, 1}, + ["tetr.T"] = {0.83, 1, 1}, } function M:field_dimensions() @@ -45,14 +45,14 @@ function M:field_dimensions() end function M:draw_square(block, x, y, block_size, shadow) - if colors[block] then - love.graphics.setColor(unpack(colors[block])) - else - love.graphics.setColor(1, 1, 1) - end - local r, g, b = love.graphics.getColor() - love.graphics.setColor(r, g, b, shadow and 0.2 or 1) - love.graphics.rectangle("fill", x, y, block_size, block_size) + love.graphics.setColor(1, 1, 1, shadow and 0.2 or 1) + local hueshift = self.assets.shader.hueshift + love.graphics.setShader(hueshift) + hueshift:send("colorize_to", colors[block] or {0, 0, 1}) + + local img = self.assets.img.block + local img_w, img_h = img:getDimensions() + love.graphics.draw(img, x, y, 0, block_size / img_w, block_size / img_h) end function M:draw_block(block, line, column, shadow) @@ -72,7 +72,7 @@ function M:draw_tetromino(tetromino, x, y, block_size, trim_margins) xxx = xxx - tetromino.left_side + 1 yyy = yyy - (tetromino.size-tetromino.top) end - M:draw_square(cell, x + (xxx-1)*block_size, y + (yyy-1)*block_size, block_size) + self:draw_square(cell, x + (xxx-1)*block_size, y + (yyy-1)*block_size, block_size) end end end |