Page 25 of 33

Bloom for 0.9.1?

Posted: Mon Jun 02, 2014 5:03 am
by Ratchet
Somebody got a working bloom shader for 0.9.1? I can't get the stuff to work that's around here :o:

Especially this does just nothing :?

Re: Share a Shader!

Posted: Tue Jun 03, 2014 6:16 pm
by CaptainMaelstrom
This should work. Credit to BlackBulletIV.

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;
   }
]]

Re: Share a Shader!

Posted: Wed Jun 04, 2014 1:08 pm
by Ratchet
My whole computer freezes when I use it :huh:
Yes, my graphic card does support shaders.

Re: Share a Shader!

Posted: Sat Jun 07, 2014 9:16 am
by Zilarrezko
I'm having trouble finding good rich in-depth tutorials for shaders. You could say they're... a Shady Business.

Re: Share a Shader!

Posted: Sat Jun 07, 2014 1:50 pm
by Germanunkol
It is difficult, getting started. But download some of the examples in this thread and learn from them (I think there was a few simpler image-manipulation demos towars the beginning).
I assume you've read the introduction to shaders?

Apart from that, go read some glsl (fragment) shader tutorials. Apart from the main function call's name and the "uniform" keyword, they're pretty much exactly what Löve shaders do.

Re: Share a Shader!

Posted: Tue Jun 10, 2014 4:45 am
by substitute541
Created a simple terrain generator along with lighting.
terrain.love
(1.97 KiB) Downloaded 568 times
FPS 990.png
FPS 990.png (587.83 KiB) Viewed 7504 times
And here's the code for the normal map generator and shader.

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;
}

Re: Share a Shader!

Posted: Thu Jun 19, 2014 10:10 am
by Zilarrezko
Alright... So I'm having problems with transferring openGL's GLSL globals like gl_NormalMatrix and gl_Normal.

It's really confusing having things renamed to... "Be made easier for coding" when it's making it more of a pain to learn the stuff. Although if I ever get GLSL Love enchanced version down, I'm sure I would appreciate having the globals not me huge names with a bunch of underscores and the like.

It would be a lot nicer if Love had on it's wiki page with global variables the variables' equivalent to GLSL variables. Or if someone would make a video tutorial on Love's version of GLSL. I'd be willing to do it, although of course I'm have variable problems. Which is one of the last things I want.

Sorry if I'm being blunt. Just frustrated when I can't figure things out. :?

Re: Share a Shader!

Posted: Fri Jun 20, 2014 7:34 am
by Positive07
[wiki]Shader Variables[/wiki] and Shader Language... this?

Re: Share a Shader!

Posted: Fri Jun 20, 2014 9:36 am
by Zilarrezko
Positive07 wrote:[wiki]Shader Variables[/wiki] and Shader Language... this?
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.

Re: Share a Shader!

Posted: Fri Jun 20, 2014 2:19 pm
by Tanner
Love's default shaders are actually open-source! You can just look at the whole shader program yourself here: https://bitbucket.org/rude/love/src/585 ... ua#cl-1294 :)