Bloom for 0.9.1?
Posted: Mon Jun 02, 2014 5:03 am
Somebody got a working bloom shader for 0.9.1? I can't get the stuff to work that's around here
Especially this does just nothing
Especially this does just nothing
Code: Select all
shaders.bloom = lg.newShader[[
//BlackBulletIV
extern vec2 size = vec2(20,20);
extern int samples = 2; // pixels per axis; higher = bigger glow, worse performance
extern float quality = .5; // lower = smaller glow, better quality
vec4 effect(vec4 color, Image tex, vec2 tc, vec2 sc)
{
vec4 src = Texel(tex, tc);
vec4 sum = vec4(0);
int diff = (samples - 1) / 2;
vec2 sizeFactor = vec2(1) / size * quality;
for (int x = -diff; x <= diff; x++)
{
for (int y = -diff; y <= diff; y++)
{
vec2 offset = vec2(x, y) * sizeFactor;
sum += Texel(tex, tc + offset);
}
}
return ((sum / (samples * samples)) + src) * color;
}
]]
Code: Select all
function drawNormals(data)
local normals = love.image.newImageData(800, 600)
local sqrt = math.sqrt
local floor = math.floor
local a = 50
for y=1, 600-2 do
for x=1, 800-2 do
local s1, s2 = data:getPixel(x-1, y)
local s3, s4 = data:getPixel(x+1, y)
local v1 = s1*s2/65025 -- these multiplications are basically calculating
local v2 = s3*s4/65025 -- the final height value of my heightmap.
s1, s2 = data:getPixel(x, y-1)
s3, s4 = data:getPixel(x, y+1)
local v3 = s1*s2/65025 -- the height values are stored in two channels
local v4 = s3*s4/65025 -- first is the (red) details of the terrain,
local s5, s6 = data:getPixel(x, y) -- next is the (green) overall shape, including mountains.
local xgrad = a*(v1-v2) -- calculate the gradients by finding the difference between
local ygrad = a*(v3-v4) -- the two height valaues
local d = sqrt(xgrad*xgrad+ygrad*ygrad+1) -- normalize it
xgrad = xgrad/d
ygrad = ygrad/d
local z = 1/d
normals:setPixel(x, y, floor(xgrad*128+128), floor(ygrad*128+128), z*255, 255) -- store the normals
end
end
return normals
end
Code: Select all
extern vec2 screen = vec2(800.0f, 600.0f);
extern vec2 sundir = vec2(0.0f, 0.0f);
extern Image colormap;
const float sunheight = 1.0f;
const vec3 terrain = vec3(0.0f, 0.7f, 0.0f);
const vec3 ambient = vec3(0.01f, 0.0f, 0.015f);
// assume color is green for now
vec4 effect(vec4 color, Image texture, vec2 texcoords, vec2 pixcoords) {
// source color
vec4 source = Texel(texture, texcoords);
vec3 sunvector = normalize(vec3(sundir, -sunheight));
vec3 normal = normalize(source.rgb-vec3(0.5f, 0.5f, 0.5f));
vec4 data = Texel(colormap, texcoords);
float height = (data.r*data.g);
float l = dot(normal, -sunvector)*0.5f +0.5f;
l *= 1/((sunheight-height)*0.7f+1);
vec4 texcolor = vec4(terrain*l+ambient, 1.0f);
return texcolor * color;
}
Nah I've already looked through those. I mean something that shows something like what Shader Language does with all the "sampler2D is image", except for all of love's shader variables. I would make a better example but unfortunatly if I knew which GLSL variables corresponded to love's variables then I wouldn't be asking this question.Positive07 wrote:[wiki]Shader Variables[/wiki] and Shader Language... this?