Shader not applied on small canvas

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.
Gan_HOPE326
Prole
Posts: 7
Joined: Sun Apr 07, 2013 2:51 pm

Shader not applied on small canvas

Post by Gan_HOPE326 »

I'm trying to create a small canvas as a resource to be used further into the game. The canvas is square, the size is calculated on the basis of the total screen resolution (passed to the function as argument) with a border to make room for the 'blur aura', and the operations performed are:

1) draw a black rectangle (background)
2) draw a white circle
3) apply a blurring shader

I've attached the shader code as well as the code that creates the canvas. My problem is that when I draw the canvas, the blurring effect has not been applied. Another canvas treated with a similar algorithm but with a full-screen size works...

Could you give me any suggestion? Thank you very much!
Attachments
shaders.lua
The file containing the blur shader
(5.99 KiB) Downloaded 176 times
bubble_render_fail.lua
The function not working
(906 Bytes) Downloaded 154 times
User avatar
Ragzouken
Citizen
Posts: 84
Joined: Fri Aug 10, 2012 7:59 am
Contact:

Re: Shader not applied on small canvas

Post by Ragzouken »

You should post a working .love file, it makes it a lot easier for people to help you by seeing the problem and poking around with it themselves.

I imagine one problem you are having is with your inverse width and height variables in the shader code. You need to compute those in the body of the shader; as it stands they are computed once: when you create the shader and before you send width/height. They won't be automatically recomputed every time you change width/height.
Gan_HOPE326
Prole
Posts: 7
Joined: Sun Apr 07, 2013 2:51 pm

Re: Shader not applied on small canvas

Post by Gan_HOPE326 »

Thanks for the suggestion, I'll try. Here's a working love file btw. It draws a single "bubble" Canvas exactly in the middle of the screen.

I tried removing the instructions that send the first values to the shader (H_RES and V_RES in main.lua), but this does not solve the problem. If it was what you suggested, that should have fixed it, I think.
Attachments
Test_bubble_fail.love
(1.57 KiB) Downloaded 178 times
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Shader not applied on small canvas

Post by Nixola »

Oh wow, the .love just crashed here ("love.exe has stopped working")
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
Ragzouken
Citizen
Posts: 84
Joined: Fri Aug 10, 2012 7:59 am
Contact:

Re: Shader not applied on small canvas

Post by Ragzouken »

With the .love you gave the blurring seems to work for me just fine - I'm surprised that it works with the inverse width and height defined where they are. I tried windowed/fullscreen mode and the blur seems to work fine, so maybe it's a driver issue (unless I'm misunderstanding the problem?).

If it wasn't clear, I was suggesting you do this:

Code: Select all

bc_shaders.blur = love.graphics.newPixelEffect [[
	
	extern number width;
	extern number height;
		
	vec4 effect(vec4 pix_col, Image texture, vec2 texture_coords, vec2 screen_coords)
	{
		number inv_w = 1.0/width;
		number inv_h = 1.0/height;
		vec4 sum = vec4(0.0);

		[...]
	} ]]
Gan_HOPE326
Prole
Posts: 7
Joined: Sun Apr 07, 2013 2:51 pm

Re: Shader not applied on small canvas

Post by Gan_HOPE326 »

Just for your information: I'm running Love 0.8.0. I tried the .love file on both linux ubuntu and windows 7 and I get the problem on both platforms.
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Shader not applied on small canvas

Post by Boolsheet »

Not sure if this is related to your problem, but you should not set a Canvas and draw the Canvas to itself.

Code: Select all

love.graphics.setCanvas(myCanvas)
love.graphics.draw(myCanvas) -- Undefined behaviour!
What exactly happens depends on the shader code and the OpenGL implementation. It may work for some without any side effects, others may see complete garbage.
Shallow indentations.
Gan_HOPE326
Prole
Posts: 7
Joined: Sun Apr 07, 2013 2:51 pm

Re: Shader not applied on small canvas

Post by Gan_HOPE326 »

Boolsheet wrote:Not sure if this is related to your problem, but you should not set a Canvas and draw the Canvas to itself.

Code: Select all

love.graphics.setCanvas(myCanvas)
love.graphics.draw(myCanvas) -- Undefined behaviour!
What exactly happens depends on the shader code and the OpenGL implementation. It may work for some without any side effects, others may see complete garbage.
I wasn't sure about this part of the code either. I used it elsewhere in the same program though and did fine. You think I should go with a buffer to stay on the safe side?
User avatar
Boolsheet
Inner party member
Posts: 780
Joined: Wed Dec 29, 2010 4:57 am
Location: Switzerland

Re: Shader not applied on small canvas

Post by Boolsheet »

Yes, you have to draw to something else to be sure that everyone sees the same thing. That means using a second Canvas or taking a different approach.
Shallow indentations.
Gan_HOPE326
Prole
Posts: 7
Joined: Sun Apr 07, 2013 2:51 pm

Re: Shader not applied on small canvas

Post by Gan_HOPE326 »

Ok, I'll try when I am back home. By the way, what is it supposed to happen if I set the PixelEffect BEFORE I draw the circle with love.graphics.circle? Should that produce a blurred circle? Because everytime I tried, it ended up with either nothing happening, or the canvas turning out completely black. Is it to be expected?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 219 guests