Page 15 of 33

Re: Share a Shader!

Posted: Mon Dec 03, 2012 4:41 pm
by Nixola
That's quite bad, you've got 2 FPS with a black screen ^^' I guess I messed up something since I don't know the language, my bad

Re: Share a Shader!

Posted: Mon Dec 03, 2012 4:55 pm
by Ref
Thanks anyway!
Maybe the Gods of pixeleffects will show mercy and provide a display of their brilliance.

Re: Share a Shader!

Posted: Tue Dec 04, 2012 5:56 am
by ioxu
This should work.
This is the apple glsl shader by Iñigo Quilez http://www.iquilezles.org.
Direct link: http://www.iquilezles.org/apps/shadertoy/?p=apple
apple_iq.love
apple shader by Iñigo Quilez
(2.89 KiB) Downloaded 601 times
edit: here's a youtube of Iñigo livecoding the shader http://www.youtube.com/watch?v=CHmneY8ry84
amazing.

Re: Share a Shader!

Posted: Tue Dec 04, 2012 5:36 pm
by Ref
Thanks ioxu!
Very impressive.
First time that my GPU was the limiting factor.
Couldn't find the 'stem' thought :)
Next, the worm hole!

Re: Share a Shader!

Posted: Fri Dec 07, 2012 9:00 pm
by Ref
Starting to get the hang of it but sure is a lot I don't understand.
Attached is a Love version of Quilez's pulse shader.

Re: Share a Shader!

Posted: Mon Dec 17, 2012 2:49 pm
by ioxu
Ref!
You sent me a PM but I can't reply because the board says that you don't accept PMs. Please change your prefs!

Re: Share a Shader!

Posted: Mon Mar 11, 2013 8:17 pm
by MZ|One
These are all great help to all us who are not GLSL-savvy, so thanks everyone!

I've particularly enjoyed the ioxu's luminous effect, which is gorgeous, and I whipped up a quick wrapper, so that I can use it more conveniently – there you have it, in case anyone would find it useful. Also, thanks, ioxu! This was exactly what I needed.

Code: Select all

--
-- The original Light Scattering GLSL shader by Fabien Sanglard
-- http://fabiensanglard.net/lightScattering/index.php
--
-- Adapted to the LOVE PixelEffect by ioxu
-- http://blog.ioxu.com/?p=909
--
-- 'Luminosity' wrapper by mz1
-- www.mz1net.com
--  

-- =================================================================================

-- EXAMPLE USAGE:
-- ---

--[[

function love.load()

	windowSizeX, windowSizeY = 800, 600
	l = Luminosity.new(windowSizeX, windowSizeY)

end

function love.draw()

	-- Draw BG, ...
	-- ...
	
	-- When you want to draw with luminosity:
	
	-- 1] Call 'receive'
	l:receive()
	
	-- 2] Now the luminosity instance will receive all your renders up until you 
	-- call 'process', so draw whatever you want to draw illuminated:
	love.graphics.draw(sprite1, 0, 0, ...)
	love.graphics.draw(sprite2, 0, 0, ...)
	
	-- 3] Call 'process'
	l:process()
	
	-- 4] Now the luminosity instance contains everything that you have drawn in the 
	-- step #2, and it is illuminated. Draw it to the screen when convenient.
	l:draw()

	-- Done. Continue to render whatever else you want to render.
	-- ...

end

-- Remember that you can set the light's position with 'setLightPosition', and also
-- tweak the shader values in the constructor.

]]

-- =================================================================================
-- =================================================================================

Luminosity = {}
Luminosity.__index = Luminosity

-- =================================================================================

function Luminosity.new (canvasSizeX, canvasSizeY)

	local new = {}
	setmetatable(new, Luminosity)
	
	new.canvasSizeX = canvasSizeX
	new.canvasSizeY = canvasSizeY
	
	new.backCanvas = love.graphics.newCanvas( canvasSizeX, canvasSizeY )
	new.raysCanvas = love.graphics.newCanvas( canvasSizeX, canvasSizeY )
		
	new.FX = love.graphics.newPixelEffect[[

		extern number exposure = 1.0;
		extern number decay = 1.0;
		extern number density = 1.0;
		extern number weight = 1.0;
		extern vec2 lightPositionOnScreen= vec2(0.0,0.0);
		extern number NUM_SAMPLES = 100.0 ;

		vec4 effect(vec4 color, Image texture, vec2 texture_coords, vec2 pixel_coords)
		{
			vec2 deltaTextCoord = vec2( texture_coords - lightPositionOnScreen.xy );
			vec2 textCoo = texture_coords.xy;
			deltaTextCoord *= 1.0 / float(NUM_SAMPLES) * density;
			float illuminationDecay = 1.0;
			vec4 cc = vec4(0.0, 0.0, 0.0, 1.0);

			for(int i=0; i < NUM_SAMPLES ; i++)
			{
				textCoo -= deltaTextCoord;
				vec4 sample = Texel( texture, textCoo );
				sample *= illuminationDecay * weight;
				cc += sample;
				illuminationDecay *= decay;
			}
			cc *= exposure;
			return cc;
		}
		]]
	
	new:setLightSource( 0.5, 0.5 )
		
	new.FX:send( 'exposure', 0.2 )
	new.FX:send( 'decay', 0.95 )
	new.FX:send( 'density', 0.4 )
	new.FX:send( 'weight', 0.3 )
	new.FX:send( 'NUM_SAMPLES', 70 )
		
	return new

end

-- =================================================================================

-- 
-- x, y = [0, 1], relative to the canvas size
-- 

function Luminosity:setLightSource (x, y)

	self.FX:send( 'lightPositionOnScreen', { x, 1-y } )

end

-- =================================================================================

function Luminosity:receive()

	-- 
	self.backCanvas:clear()
	self.raysCanvas:clear()
	
	--
	love.graphics.setCanvas( self.backCanvas )
	
end

-- =================================================================================

function Luminosity:process()

	-- 
	love.graphics.setColor( 255,255,255 )
	love.graphics.setCanvas( self.raysCanvas )
	love.graphics.setPixelEffect( self.FX )
			
	--
	love.graphics.draw( self.backCanvas, 0, 0, 0, 1, 1 )
	
	-- 
	love.graphics.setCanvas()
	love.graphics.setPixelEffect()
	
end

-- =================================================================================

function Luminosity:draw (x, y)

	-- 
	love.graphics.setColor( 255,255,255 )
	love.graphics.draw( self.backCanvas, x or 0, y or 0 )

	--
	local bm = love.graphics.getBlendMode()
	love.graphics.setBlendMode( 'additive' )
	love.graphics.draw( self.raysCanvas, x, y, 0, 1, 1 )
	love.graphics.draw( self.raysCanvas, x, y, 0, 1, 1 )
	
	-- Restore the previous blend mode
	love.graphics.setBlendMode( bm )

end

Re: Share a Shader!

Posted: Mon Mar 25, 2013 1:18 am
by retrotails
An accident.

Re: Share a Shader!

Posted: Mon Mar 25, 2013 6:36 am
by Jasoco
retrotails wrote:An accident.
That could be useful for doing "flakey signal" effects. Awesome.

Re: Share a Shader!

Posted: Tue Mar 26, 2013 8:55 pm
by Robin
Nice. Shame the effect gets so damn large after running it a while. Kind of breaks the effect.