Hey all,
Im working on a game in which I will be using a few shaders to make fancy effects and what not; Just some basic ones to change the color of a sprite though.
However, I have noted that you can only load 1 shader at the time, and apply it to a sprite, whereas I would like to be able to apply 2 shaders to a sprite.
For example, normally a sprite would be grayscaled, but when a certain variable is true it should be grayscaled, as well as have a different shader on top of it.
Im thinking I may need to use some kind of loop where I activate shader1, draw it to a canvas, activate shader2, draw it to a canvas, etc, until I get the image I want, then draw it to the screen, but I'm not sure how to do so.
Can anybody help me out here?
Applying multiple shaders to a effect?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Re: Applying multiple shaders to a effect?
You can draw the original sprite to canvas with one shader set, then draw the canvas onto the screen with the other shader set.
I would not recommend this though. It is probably better to instead write a shader that handles both, based on an externa value that you can set with shader:send().
I would not recommend this though. It is probably better to instead write a shader that handles both, based on an externa value that you can set with shader:send().
Re: Applying multiple shaders to a effect?
It's exactly the concept of multi-pass rendering, to apply multiple shader to a same object you'll need to render it back to a canvas where you'll apply the new shader. So to achieve what you want you can setup a multi-pass system (but it's really needed in cases where you need the result of the previous shader for your new computation) or just write a "bigger" shader handling all the cases you need (or switch between multiple shaders depending on the situation).Im thinking I may need to use some kind of loop where I activate shader1, draw it to a canvas, activate shader2, draw it to a canvas, etc, until I get the image I want, then draw it to the screen, but I'm not sure how to do so.
A typical example of multi-pass effects is gaussian blur for instance, you can have an example in this post:
viewtopic.php?f=5&t=80216&start=10#p184638
To apply this effect on my character, I have a total of 5 canvas and 4 shaders.
Re: Applying multiple shaders to a effect?
wouldn't two canvas' be enough? You can just render back-and-forth. Or do you access the other data inbetween?Fenrir wrote:It's exactly the concept of multi-pass rendering, to apply multiple shader to a same object you'll need to render it back to a canvas where you'll apply the new shader. So to achieve what you want you can setup a multi-pass system (but it's really needed in cases where you need the result of the previous shader for your new computation) or just write a "bigger" shader handling all the cases you need (or switch between multiple shaders depending on the situation).Im thinking I may need to use some kind of loop where I activate shader1, draw it to a canvas, activate shader2, draw it to a canvas, etc, until I get the image I want, then draw it to the screen, but I'm not sure how to do so.
A typical example of multi-pass effects is gaussian blur for instance, you can have an example in this post:
viewtopic.php?f=5&t=80216&start=10#p184638
To apply this effect on my character, I have a total of 5 canvas and 4 shaders.
Re: Applying multiple shaders to a effect?
Thing is; I have never actually used canvases (canvas-i, canvasses?) before, so I think I might just go for the "all-in-one" shader, which will have boolean variables that will control which part of the shader to apply.
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Applying multiple shaders to a effect?
Use this as an opportunity to learn all about canvases they will be needed eventually anyway.
Re: Applying multiple shaders to a effect?
* probably it depends on what you are doingbobbyjones wrote:Use this as an opportunity to learn all about canvases they will be needed eventually anyway.
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
Re: Applying multiple shaders to a effect?
I think I'll probably try to incorporate canvasas as the frame buffer, as I heard its more efficient?
That will also mean I can implement my camera on it a lot more easialy, which would be nice
That will also mean I can implement my camera on it a lot more easialy, which would be nice
Re: Applying multiple shaders to a effect?
No it will most likely be slower because you are doing two draw calls to draw one thing (draw calls are a lot more expensive than people think). But most likely you have more than enough processing power so don't worry about it. Just do what makes sense to you as long as you are being reasonable.Tjakka5 wrote:I think I'll probably try to incorporate canvasas as the frame buffer, as I heard its more efficient?
That will also mean I can implement my camera on it a lot more easialy, which would be nice
My Tox ID: 0F1FB9170B94694A90FBCF6C4DDBDB9F58A9E4CDD0B4267E50BF9CDD62A0F947E376C5482610
-
- Party member
- Posts: 730
- Joined: Sat Apr 26, 2014 7:46 pm
Re: Applying multiple shaders to a effect?
How will it be slower? Lol he isn't using canvases yet. Once he adds it in his performance should increase lol. That's the point of canvases.
Who is online
Users browsing this forum: Bing [Bot] and 4 guests