Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
how to efficiently apply multiple shaders — Gideros Forum

how to efficiently apply multiple shaders

so i'd like to add multiple effects stacked on each other on my sprite hierarchy. i can add one shader, render it to a texture, display it, add another shader on that and render it to a texture etc. but this is really slow if the bitmap i work with is full-screen (which it is). is there a better way?
thanks

Comments

  • I still have to properly learn shaders :#
    In my last attempts I could apply multple shaders to one sprite by multiplying the shaders in the result call.
    I don't have the code right now but that was something like:
    function shader : shaders()
       -- bloom
       ...
       -- blur
       ...
       result = bloom * blur
    end
    Hope this makes sense :|
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • hgy29hgy29 Maintainer
    There’s probably not much you can do since what makes it slow is mainly the gpu usage, except if you can merge some shaders together as @MoKaLux suggested, this will avoid storing pixel to memory and sampling it again for the next pass.
  • by merging you mean guys that i combine the shader codes into one somehow?
    in my app i have 7 fx's and maybe more in the future which should be applied in any combination (even more than 2 of them) so there are too many combinations to hard-code them.
  • i have just realized that there is a thing called multiple buffers in glsl, see e.g.
    https://www.shadertoy.com/view/4dcGW2#
    which has buffer a, buffer b, etc.
    as far as i understand with this one could combine multiple shaders into one even if they are not per-pixel computed (like @MoKaLux 's example with bloom*blur).
    how can we do this in gideros glsl? if that's doable then an example would be nice (packaged with gideros examples in long term).

  • keszegh said:

    i have just realized that there is a thing called multiple buffers in glsl, see e.g.
    https://www.shadertoy.com/view/4dcGW2#
    which has buffer a, buffer b, etc.
    as far as i understand with this one could combine multiple shaders into one even if they are not per-pixel computed (like @MoKaLux 's example with bloom*blur).
    how can we do this in gideros glsl? if that's doable then an example would be nice (packaged with gideros examples in long term).

    Unfortunately I am not in the position to help you because I am not the smartest of the pack here :) but if you take a look at effects.lua in your gideros installation folder/library/luashader I think that the Master there did something similar to achieve the Bloom effect:
    self.stack={
    		{ buffer=rt3, shader=getEffect("BloomExtract"), transform=xform},
    		{ buffer=rt1, shader=getEffect("Blur")},
    		{ buffer=rt2, shader=getEffect("Blur")},
    		{ buffer=rt1, shader=getEffect("BloomCombine"),textures={rt3,rt1}, postTransform=pxform},
    	}
    Unfortunately I still am not able to reverse engineer those passages :smiley: if you do please share...
  • @pie , indeed, i also can't follow the code.
    still seems there are still separate rendertargets there, so perhaps it is not exactly the same as buffers within a shader. @hgy29 may tell us more.

    also, while i like the idea of luashaders as i can read them better, on the other hand to translate and modify e.g. a shadertoy code is even harder, thus i still prefer to wotk with glsl shaders (and also i have some of them already from the past and i'm too lazy to translate them) and so i'd need an example on how to do multiple buffers in glsl.
  • hgy29hgy29 Maintainer
    See it that way: each 'effect' pass renders a set of input textures into a buffer (a rendertarget). Buffer here have the meaning as in shadertoy: each shadertoy buffer have its own shader code.

    In Gideros effect stack, effects are chained by default: first effect takes the Sprite input textures and draw into its assigned buffer, second effect takes previous buffer as input texture and draws into its own buffer and so on, until last effect which draws directly on screen.

    If this default chaining is not what you want, you can specify input textures yourself in each effect pass descriptor (like in BloomCombine above).

    About the benefit of working with luashaders and not in GLSL: if you happen to target UWP (HLSL) or iOS/macOS (MSL) in addition to Android, you don't need to write the shader in all three languages.
Sign In or Register to comment.