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!
Shader not applied on small canvas
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 7
- Joined: Sun Apr 07, 2013 2:51 pm
Shader not applied on small canvas
- Attachments
-
- shaders.lua
- The file containing the blur shader
- (5.99 KiB) Downloaded 190 times
-
- bubble_render_fail.lua
- The function not working
- (906 Bytes) Downloaded 162 times
Re: Shader not applied on small canvas
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.
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.
-
- Prole
- Posts: 7
- Joined: Sun Apr 07, 2013 2:51 pm
Re: Shader not applied on small canvas
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.
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 199 times
Re: Shader not applied on small canvas
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
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Re: Shader not applied on small canvas
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:
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);
[...]
} ]]
-
- Prole
- Posts: 7
- Joined: Sun Apr 07, 2013 2:51 pm
Re: Shader not applied on small canvas
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.
Re: Shader not applied on small canvas
Not sure if this is related to your problem, but you should not set a Canvas and draw the Canvas to itself.
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.
Code: Select all
love.graphics.setCanvas(myCanvas)
love.graphics.draw(myCanvas) -- Undefined behaviour!
Shallow indentations.
-
- Prole
- Posts: 7
- Joined: Sun Apr 07, 2013 2:51 pm
Re: Shader not applied on small canvas
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?Boolsheet wrote:Not sure if this is related to your problem, but you should not set a Canvas and draw the Canvas to itself.
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.Code: Select all
love.graphics.setCanvas(myCanvas) love.graphics.draw(myCanvas) -- Undefined behaviour!
Re: Shader not applied on small canvas
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.
-
- Prole
- Posts: 7
- Joined: Sun Apr 07, 2013 2:51 pm
Re: Shader not applied on small canvas
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?
Who is online
Users browsing this forum: No registered users and 7 guests