Howdy, Stranger!

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

Shader alpha

Hello guys,

I'm currently trying to set rect transparency with a shader. ( ripple effect in this case )

Codea built in shader sample represents pretty much my same situation :

-- Use this function to perform your initial setup

function setup()

    allTextures = {
                    "Cargo Bot:Codea Icon",
                    "Small World:Store Extra Large",
                    "Small World:Windmill",
                    "Tyrian Remastered:Boss D",


    m = mesh()
    m.texture = allTextures[Texture]
    m.shader = shader("Effects:Ripple")

    rIdx = m:addRect(0, 0, 0, 0)
    m:setRectColor(rIdx, 255,0,0,10)

-- This function gets called once every frame
function draw()
    -- This sets a dark background color
    background(40, 40, 50)

    -- This sets the line thickness

    -- Here we set up the rect texture and size
    m.texture = allTextures[Texture]
    local cw,ch = spriteSize(allTextures[Texture])
    m:setRect(rIdx, WIDTH/2, HEIGHT/2, cw, ch)

    -- Configure out custom uniforms for the ripple shader
    m.shader.time = ElapsedTime
    m.shader.freq = Freq

    -- Draw the mesh

is there a way to play with rectangles' alpha value?
setRectColor doesn't seem to affect alpha at all or maybe I'm just not using it the right way.

Any idea?

thank you




  • IgnatzIgnatz Mod
    edited February 2015 Posts: 5,396

    @deactive - The problem is that the ripple shader only modifies r,g,b but NOT a.

    If you are comfortable modifying the ripple shader and naming it as something else, then change the last line

    gl_FragColor = vec4(col.rgb * vColor.rgb, col.a);
    gl_FragColor = vec4(col.rgb * vColor.rgb, col.a*vColor.a);
  • Posts: 127

    Hi @ignatz, thank you.
    You answered my question.

  • gl_FragColor = col * vColor;

    should work

Sign In or Register to comment.