mirror of
https://github.com/tanema/light_world.lua.git
synced 2024-12-24 20:24:19 +00:00
Store shaders as lua strings
This commit is contained in:
parent
22f3ac5f80
commit
0691826e07
@ -7,8 +7,8 @@ local vector = require(_PACKAGE..'/vector')
|
||||
local body = {}
|
||||
body.__index = body
|
||||
|
||||
body.glowShader = love.graphics.newShader(_PACKAGE.."/shaders/glow.glsl")
|
||||
body.materialShader = love.graphics.newShader(_PACKAGE.."/shaders/material.glsl")
|
||||
body.glowShader = love.graphics.newShader(require(_PACKAGE..".shaders.glow"))
|
||||
body.materialShader = love.graphics.newShader(require(_PACKAGE..".shaders.material"))
|
||||
|
||||
local function new(id, type, ...)
|
||||
local args = {...}
|
||||
|
@ -31,10 +31,10 @@ local PostShader = require(_PACKAGE..'postshader')
|
||||
local light_world = {}
|
||||
light_world.__index = light_world
|
||||
|
||||
light_world.image_mask = love.graphics.newShader(_PACKAGE.."/shaders/image_mask.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")
|
||||
light_world.image_mask = love.graphics.newShader(require(_PACKAGE.."shaders.image_mask"))
|
||||
light_world.shadowShader = love.graphics.newShader(require(_PACKAGE.."shaders.shadow"))
|
||||
light_world.refractionShader = love.graphics.newShader(require(_PACKAGE.."shaders.refraction"))
|
||||
light_world.reflectionShader = love.graphics.newShader(require(_PACKAGE.."shaders.reflection"))
|
||||
|
||||
local function new(options)
|
||||
local obj = {}
|
||||
|
@ -31,15 +31,16 @@ local files = love.filesystem.getDirectoryItems(_PACKAGE.."/shaders/postshaders"
|
||||
local shaders = {}
|
||||
|
||||
for i,v in ipairs(files) do
|
||||
local name = _PACKAGE.."/shaders/postshaders".."/"..v
|
||||
local name = _PACKAGE.."/shaders/postshaders/"..v
|
||||
local module = _PACKAGE..".shaders.postshaders."..v:gsub("%.lua","")
|
||||
if love.filesystem.isFile(name) then
|
||||
local str = love.filesystem.read(name)
|
||||
local effect = love.graphics.newShader(name)
|
||||
local effect = love.graphics.newShader(require(module))
|
||||
local defs = {}
|
||||
for vtype, extern in str:gmatch("extern (%w+) (%w+)") do
|
||||
defs[extern] = true
|
||||
end
|
||||
local shaderName = name:match(".-([^\\|/]-[^%.]+)$"):gsub("%.glsl", "")
|
||||
local shaderName = name:match(".-([^\\|/]-[^%.]+)$"):gsub("%.lua", "")
|
||||
shaders[shaderName] = {effect, defs}
|
||||
end
|
||||
end
|
||||
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern Image glowImage;
|
||||
extern float glowTime;
|
||||
|
||||
@ -17,3 +18,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
|
||||
return vec4(Texel(texture, texture_coords).rgb * glowInfo.r, 1.0);
|
||||
}
|
||||
]]
|
@ -1,6 +1,8 @@
|
||||
return [[//
|
||||
//https://love2d.org/wiki/love.graphics.setStencil image mask
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 screen_coords) {
|
||||
if (Texel(texture, texture_coords).rgb == vec3(0.0))
|
||||
discard;
|
||||
return vec4(1.0);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern Image material;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
@ -8,3 +9,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
return vec4(0.0);
|
||||
}
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern float exposure = 0.7;
|
||||
extern float brightness = 1.0;
|
||||
extern vec3 lumacomponents = vec3(1.0, 1.0, 1.0);
|
||||
@ -11,3 +12,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texcoord, vec2 pixel_coords) {
|
||||
vec4 luma = vec4(luminance);
|
||||
return vec4(luma.rgb * brightness, 1.0);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern float steps = 2.0;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
@ -10,3 +11,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);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern float steps = 2.0;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
@ -10,3 +11,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);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern vec2 redStrength = vec2(4.0, 3.0);
|
||||
extern vec2 greenStrength = vec2(-2.0, -1.0);
|
||||
extern vec2 blueStrength = vec2(1.0, -3.0);
|
||||
@ -10,3 +11,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
|
||||
return vec4(colRed, colGreen, colBlue, 1.0);
|
||||
}
|
||||
]]
|
@ -1,5 +1,7 @@
|
||||
return [[//
|
||||
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);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
#define distortion 0.2
|
||||
vec2 radialDistortion(vec2 coord) {
|
||||
vec2 cc = coord - 0.5;
|
||||
@ -16,3 +17,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
texcolor.a = 1.0;
|
||||
return texcolor;
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
/*
|
||||
Edge shader
|
||||
Author: Themaister
|
||||
@ -35,5 +36,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
||||
vec4 final = vec4(5.0 * grayscale(abs(res - c11)), 1.0);
|
||||
return clamp(final, 0.0, 1.0);
|
||||
}
|
||||
|
||||
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern vec3 palette[4];
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
@ -6,3 +7,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
|
||||
return vec4(palette[index], 1.0);
|
||||
}
|
||||
]]
|
@ -1,8 +1,10 @@
|
||||
return [[//
|
||||
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));
|
||||
|
||||
if (fract(pixel_coords.y * 0.5) > 0.5) intens = rgb * 0.8;
|
||||
intens.a = 1.0;
|
||||
return intens;
|
||||
return intens;
|
||||
}
|
||||
]]
|
@ -1,9 +1,10 @@
|
||||
return [[//
|
||||
extern float time = 0.0;
|
||||
extern vec3 tint = vec3(1.0, 1.0, 1.0);
|
||||
extern float fudge = 0.1;
|
||||
|
||||
float rand(vec2 position, float seed) {
|
||||
return fract(sin(dot(position.xy,vec2(12.9898, 78.233))) * seed);
|
||||
return fract(sin(dot(position.xy,vec2(12.9898, 78.233))) * seed);
|
||||
}
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
@ -11,3 +12,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
float intensity = (pixel.r + pixel.g + pixel.b) / 3.0 + (rand(texture_coords, time) - 0.5) * fudge;
|
||||
return vec4(intensity * tint.r, intensity * tint.g, intensity * tint.b, 1.0);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
/*
|
||||
caligari's scanlines
|
||||
|
||||
@ -13,7 +14,7 @@
|
||||
|
||||
http://board.byuu.org/viewtopic.php?p=36219#p36219
|
||||
|
||||
"As I said to Hyllian by PM, I'm fine with the GPL (not really a bi
|
||||
"As I said to Hyllian by PM, I'm fine with the GPL (not really a big
|
||||
deal...)"
|
||||
)
|
||||
*/
|
||||
@ -155,3 +156,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texCoord, vec2 pixel_coords)
|
||||
|
||||
return clamp(GAMMA_OUT(color), 0.0, 1.0);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
/*
|
||||
Plain (and obviously inaccurate) phosphor.
|
||||
Author: Themaister
|
||||
@ -42,4 +43,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
||||
|
||||
return vec4(intensity * result, 1.0);
|
||||
}
|
||||
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
#define glarebasesize 0.896
|
||||
#define power 0.50
|
||||
extern float time;
|
||||
@ -59,4 +60,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texcoord, vec2 pixel_coords)
|
||||
|
||||
return finalcolor;
|
||||
}
|
||||
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
const float pixel_w = 2.0;
|
||||
const float pixel_h = 2.0;
|
||||
|
||||
@ -8,3 +9,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 uv, vec2 pixel_coords)
|
||||
vec2 coord = vec2(dx*floor(uv.x/dx), dy*floor(uv.y/dy));
|
||||
return Texel(texture, coord);
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
#define nsamples 5
|
||||
extern number blurstart = 1.0; // 0 to 1
|
||||
extern number blurwidth = -0.02; // -1 to 1
|
||||
@ -18,3 +19,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 texture_coords, vec2 pixel_coords)
|
||||
|
||||
return c;
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern float strength = 2.0;
|
||||
extern float time = 0.0;
|
||||
|
||||
@ -30,3 +31,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
return vec4(vec3(red * 0.75, green * 0.75, blue * 0.75) * brightness, 1.0);
|
||||
}
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern Image imgBuffer;
|
||||
|
||||
vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
@ -10,3 +11,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords){
|
||||
return vec4(pixel.rgb * (0.5 - texture_coords.y) * 2.0 + pixelBuffer.rgb * texture_coords.y * 2.0, 1.0);
|
||||
}
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
/*
|
||||
Themaister's Waterpaint shader
|
||||
|
||||
@ -53,3 +54,4 @@ vec4 effect(vec4 vcolor, Image texture, vec2 tex, vec2 pixel_coords)
|
||||
|
||||
return final;
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern Image backBuffer;
|
||||
|
||||
extern float reflectionStrength;
|
||||
@ -21,3 +22,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
return vec4(0.0);
|
||||
}
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
extern Image backBuffer;
|
||||
|
||||
extern float refractionStrength = 1.0;
|
||||
@ -16,3 +17,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
return vec4(0.0);
|
||||
}
|
||||
}
|
||||
]]
|
@ -1,3 +1,4 @@
|
||||
return [[//
|
||||
/*
|
||||
Copyright (c) 2014 Tim Anema
|
||||
light shadow, shine and normal shader all in one
|
||||
@ -47,4 +48,4 @@ vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords) {
|
||||
return pixel;
|
||||
}
|
||||
}
|
||||
|
||||
]]
|
Loading…
Reference in New Issue
Block a user