Non-Image objects for GLSL shaders

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.
Post Reply
QwertyDragon83
Prole
Posts: 2
Joined: Sun May 06, 2018 4:42 am

Non-Image objects for GLSL shaders

Post by QwertyDragon83 »

I just started messing with GLSL shaders tonight, and I can see how this is a very powerful tool. It took me a while, but I figured most of it out, I think..

However, I have a bit of an issue. I can't seem to figure out how to apply shaders to non-image objects, such as circles and rectangles. If I want to make a blurry rectangle, I shouldn't have to make a rectangle image and draw it to the screen using a blurring shader, I should just be able to use a shader on the rectangle drawing function. Am I wrong?

I noticed that the input for the effect() function is an Image. Is there a way to input a rectangle as an image? Here's my code:

Code: Select all

function love.load()
	shader2 = love.graphics.newShader[[
		vec4 effect(vec4 color, Image texture, vec2 tc, vec2 screen_coords){
			vec4 pix = Texel(texture, tc);//This is the current pixel color
			pix.a = tc.x+tc.y;
			return pix;
		}
	]]
	test = love.graphics.newImage("test.png");
end

function love.draw()
	love.graphics.setShader(shader2);
	love.graphics.setColor(0, 1, 0, 1);
	love.graphics.draw(test, 20, 20);
	love.graphics.rectangle("line", 300, 300, 100, 30);
	love.graphics.setShader();
end
The image is drawn fine and shaded correctly, but the rectangle does not appear at all. Keep in mind I am using love2d v11.1, so rgba values are 0 to 1. I looked for a question like this and couldn't find anything.. Hopefully this hasn't been asked before.
User avatar
zorg
Party member
Posts: 3449
Joined: Thu Dec 13, 2012 2:55 pm
Location: Absurdistan, Hungary
Contact:

Re: Non-Image objects for GLSL shaders

Post by zorg »

Hi and welcome to the forums!

The basic shapes löve allows you to draw are untextured meshes. No texture, no pixel manipulation; you can still mess with the vertices though in a vertex shader.
Me and my stuff :3True Neutral Aspirant. Why, yes, i do indeed enjoy sarcastically correcting others when they make the most blatant of spelling mistakes. No bullying or trolling the innocent tho.
User avatar
pgimeno
Party member
Posts: 3588
Joined: Sun Oct 18, 2015 2:58 pm

Re: Non-Image objects for GLSL shaders

Post by pgimeno »

Apart from what zorg said, unfortunately you don't have enough information in the shader to know the coordinates of the figure drawn, or the ST of the quad (only the UV), but you can compensate for that by using shader:send. You can then use the screen coordinates for reference.
User avatar
Ref
Party member
Posts: 702
Joined: Wed May 02, 2012 11:05 pm

Re: Non-Image objects for GLSL shaders

Post by Ref »

Glad you've got it figured out.
I'm still struggling and hope you post what you come up with.
Best!
Edit: Second shader (primitives) a little more relevant.
Attachments
primitives.love
Simple shapes
(1.6 KiB) Downloaded 154 times
collection.love
Next step?
(3.81 KiB) Downloaded 151 times
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest