Quick Links: Gideros Home | Download Gideros | Developer Guide
Bloom effect on multiple objects
  • Guys,

    Is it possible do have the bloom effect, but not on the entire scene or container that contains multiple sprites.
    I need some of the flying objects on the scene to have bloom, and some not.
    Say 20 objects with bloom and 20 without.
    Is this doable per sprite without affecting the performance?
    And if so - how exactly to do it?

    Thanks!!!
  • there is a 'bloom effect' example using shaders, that should be good to get you started (and luckily you need the same effect so you can use the shaders mostly without the need to understand the details).
  • SinisterSoftSinisterSoft +1 -1
    Maintainer Accepted Answer
    Here is the single pass bloom shader I used in Bacteria (with help from @hgy29 ):
    shaderV=[[
    attribute highp vec3 vVertex;
    attribute mediump vec2 vTexCoord;
    uniform highp mat4 vMatrix;
    varying mediump vec2 fTexCoord;
     
    void main() {
    vec4 vertex = vec4(vVertex,1.0);
    gl_Position = vMatrix*vertex;
    fTexCoord=vTexCoord;
    }
    ]]
     
    bloomF=[[
    uniform lowp sampler2D fTexture;
    varying mediump vec2 fTexCoord;
     
    void main() {
    lowp vec4 colour=texture2D(fTexture,fTexCoord);
    lowp vec4 sum=vec4(0.0,0.0,0.0,0.0);
    for (int i=-2;i<=2;i++){
    for (int j=-2;j<=2;j++){
    lowp vec2 offset=vec2(float(i),float(j))*0.0015;
    sum+=texture2D(fTexture,fTexCoord+offset);
    }
    }
    gl_FragColor=(sum/22.0)+colour;
    }
    ]]
     
    local result,reply=pcall(Shader.new,shaderV,bloomF,Shader.FLAG_FROM_CODE,{
    {name="vMatrix",type=Shader.CMATRIX,sys=Shader.SYS_WVP,vertex=true},
    {name="fColor",type=Shader.CFLOAT4,sys=Shader.SYS_COLOR,vertex=false},
    {name="fTexture",type=Shader.CTEXTURE,vertex=false}, },
    {{name="vVertex",type=Shader.DFLOAT,mult=3,slot=0,offset=0},
    {name="vColor",type=Shader.DUBYTE,mult=4,slot=1,offset=0},
    {name="vTexCoord",type=Shader.DFLOAT,mult=2,slot=2,offset=0}, })
     
    if result then
    bloomShader=reply
    else
    print("bloom shader error:",reply)
    end


    Here is a video of it working (with values tweaked for the game)...



    I also had a trick to add a phosphor decay effect.
  • A single pass shader will be your best bet at reducing gpu draw time. You could have it so that it only affects certain colours, etc - you would have to modify the code though.
  • kussakov +1 -1 (+1 / -0 )
    Member
    Thanks a lot @SinisterSoft !!! I will try it!

    (As for the GPU time - my game has special effects on/off settings. If the device is slow or they want to preserve battery they can disable the effects)

    @keszegh, I already use the bloom example, but it is per container/scene.

    Likes: SinisterSoft

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Login with Facebook Sign In with OpenID

In this Discussion

Top Posters