Page 1 of 2

[Solved] Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 10:25 am
by ~Tidal
Good day.
Since I want to create a custom glow on every character sprite, I thought a shader would do the trick.
After a few tries, I thought nothing was working, only to realize that the shader applies to the whole texture (ex. 64x64 with every tile or character pose or whatever) and not a single quad, or a batch.
No, my question is: is there a way to make it work only on one quad or batch, without applying every time the shader?

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 1:52 pm
by s-ol
~Tidal wrote:Good day.
Since I want to create a custom glow on every character sprite, I thought a shader would do the trick.
After a few tries, I thought nothing was working, only to realize that the shader applies to the whole texture (ex. 64x64 with every tile or character pose or whatever) and not a single quad, or a batch.
No, my question is: is there a way to make it work only on one quad or batch, without applying every time the shader?
What do you mean? a Shader always applies to everything that is draw as long as it is set. If you only want to apply it t one quad... then do that?

Code: Select all

love.graphics.setShader(myshader)
love.graphics.draw(quad, texture) -- drawn with shader
love.graphics.setShader()

love.graphics.rectangle("fill", 20, 20, 100, 100) -- drawn without shader

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 1:58 pm
by ~Tidal
It is exactly what I want to do.
But I was trying to do a gradient. Simple stuff. But instead of being applied on the current quad/batch drawn, it is applied to the whole picture.
Image
Visual representation.
Edit: I only want to have the lower part of the said quad of a different color than the top part, so I'm working with texture_coords, which don't apply to the quad, but to the original picture.

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 6:37 pm
by Ref
Real stupid but have you tried drawing each sprite to a separate canvas and then apply the shader to all the canvases?

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 6:53 pm
by s-ol
Ref wrote:Real stupid but have you tried drawing each sprite to a separate canvas and then apply the shader to all the canvases?
isn't that the opposite of what he wants to do? :0

OP, please attach your code so we can see what you are actually doing.

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 7:09 pm
by ~Tidal
Ref wrote:Real stupid but have you tried drawing each sprite to a separate canvas and then apply the shader to all the canvases?
aren't canvas supposed to represent static things? IMHO this wouldn't be ok.
anyway, I guess I've solved it.
Since I can't apply the effect on a single quad but it is applied on the whole texture, I tried to think outside the box: instead of using document boundaries, I used each sprite boundaries: via Texel and 1/Width - 1/Height, I got: each pixel value in terms of texture_coord, and each pixel vauel in terms of color and alpha.
Starting from it, it was simple: the shader will be applied to every pixel above the black outline.
For what I was trying to do it is even better. I think in similar situation, a white grid or something could help you a lot.

Re: Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 8:07 pm
by s-ol
~Tidal wrote:
Ref wrote:Real stupid but have you tried drawing each sprite to a separate canvas and then apply the shader to all the canvases?
aren't canvas supposed to represent static things? IMHO this wouldn't be ok.
Canvases can be used to optimize drawing of static things / things that don't change very often, but might also be required for regular drawing and compositing. Most forms of post-processing require canvas'; for example in my ludum dare entry I apply a black-and-white filter to most of the graphics; this is done by drawing all of those to a canvas, and then drawing the canvas with the postprocessing shader.

Re: [Solved] Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 8:27 pm
by ~Tidal
Umh. Thanks.
I don't know, tho. I stopped used canvases for dynamic stuff when I experienced flickering, I was using mouse position to change some text and pictures and I think it wasn't ok. As far as I experienced, canvases don't work very well when you put some of their logic in love.update.

Re: [Solved] Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 9:58 pm
by slime
~Tidal wrote:As far as I experienced, canvases don't work very well when you put some of their logic in love.update.
They work fine anywhere (on the main love thread), as long as you don't draw a canvas to itself. Sometimes it's easy to accidentally do that if you forget to call love.graphics.setCanvas after you're done drawing to it.

Re: [Solved] Shader, but on quad/batch and not whole texture

Posted: Tue Aug 25, 2015 10:23 pm
by BOT-Brad
slime wrote:They work fine anywhere (on the main love thread), as long as you don't draw a canvas to itself. Sometimes it's easy to accidentally do that if you forget to call love.graphics.setCanvas after you're done drawing to it.
Image