Share a Shader!

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Share a Shader!

Post 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
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post by Ref »

Thanks anyway!
Maybe the Gods of pixeleffects will show mercy and provide a display of their brilliance.
User avatar
ioxu
Prole
Posts: 8
Joined: Wed Mar 30, 2011 2:43 pm

Re: Share a Shader!

Post 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 586 times
edit: here's a youtube of Iñigo livecoding the shader http://www.youtube.com/watch?v=CHmneY8ry84
amazing.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post 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!
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Share a Shader!

Post 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.
Attachments
pulse.love
A water like effect.
(10.49 KiB) Downloaded 483 times
User avatar
ioxu
Prole
Posts: 8
Joined: Wed Mar 30, 2011 2:43 pm

Re: Share a Shader!

Post 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!
User avatar
MZ|One
Citizen
Posts: 52
Joined: Tue May 22, 2012 8:37 am

Re: Share a Shader!

Post 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
User avatar
retrotails
Party member
Posts: 212
Joined: Wed Apr 18, 2012 12:37 am

Re: Share a Shader!

Post by retrotails »

An accident.
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Share a Shader!

Post by Jasoco »

retrotails wrote:An accident.
That could be useful for doing "flakey signal" effects. Awesome.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Share a Shader!

Post by Robin »

Nice. Shame the effect gets so damn large after running it a while. Kind of breaks the effect.
Help us help you: attach a .love.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 2 guests