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

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
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

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

Post 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?
Last edited by ~Tidal on Tue Aug 25, 2015 7:09 pm, edited 1 time in total.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

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

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

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

Post by Ref »

Real stupid but have you tried drawing each sprite to a separate canvas and then apply the shader to all the canvases?
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

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

Post 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.
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

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

Post 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.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
~Tidal
Prole
Posts: 27
Joined: Sat Jan 10, 2015 8:19 pm

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

Post 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.
User avatar
slime
Solid Snayke
Posts: 3166
Joined: Mon Aug 23, 2010 6:45 am
Location: Nova Scotia, Canada
Contact:

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

Post 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.
User avatar
BOT-Brad
Citizen
Posts: 87
Joined: Tue Dec 02, 2014 2:17 pm
Location: England

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

Post 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
Follow me on GitHub! | Send me a friend request on PSN!
Post Reply

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests