Howdy, Stranger!

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

BlendMode parameters

in Questions Posts: 103

Hey! So I'm trying to figure out the parameters for blendMode() and I'm wondering what parameters you would use to get the same result as blendMode(NORMAL)
Thanks!

Tagged:

Comments

  • dave1707dave1707 Mod
    Posts: 8,455

    @Dwins There's a lot of parameters for blendmode, so it's hard to say what parameter value you need to get a specific result. Here's a program I wrote that allows you to change the parameters and see what the results are. It didn't help me that much, I'm still confused. You can try it, maybe it will help you somewhat.

    function setup()
        font("Courier")
        textMode(CORNER)
        spriteMode(CORNER)
        parameter.integer("m",1,3)
        parameter.integer("r1",0,255,255)
        parameter.integer("g1",0,255,255)
        parameter.integer("b1",0,255,255)    
        parameter.integer("r2",0,255,255)
        parameter.integer("g2",0,255,255)
        parameter.integer("b2",0,255,255)
        parameter.integer("r3",0,255,255)
        parameter.integer("g3",0,255,255)
        parameter.integer("b3",0,255,255)
    
        parameter.integer("src",1,9,1)
        parameter.integer("dst",1,8,1)
    
        parameter.integer("srcA",1,9,1)
        parameter.integer("dstA",1,8,1)
    
        mode={NORMAL,MULTIPLY,ADDITIVE}
        modeS={"NORMAL","MULTIPLY","ADDITIVE"}
        srcTab={ZERO,ONE,DST_COLOR,ONE_MINUS_DST_COLOR,
            SRC_ALPHA,ONE_MINUS_SRC_ALPHA,DST_ALPHA,
            ONE_MINUS_DST_ALPHA,SRC_ALPHA_SATURATE}
        srcTabS={"ZERO","ONE","DST_COLOR","ONE_MINUS_DST_COLOR",
            "SRC_ALPHA","ONE_MINUS_SRC_ALPHA","DST_ALPHA",
            "ONE_MINUS_DST_ALPHA","SRC_ALPHA_SATURATE"}    
        dstTab={ZERO,ONE,SRC_COLOR,ONE_MINUS_SRC_COLOR,
            SRC_ALPHA,ONE_MINUS_SRC_ALPHA,
            DST_ALPHA,ONE_MINUS_DST_ALPHA}
        dstTabS={"ZERO","ONE","SRC_COLOR","ONE_MINUS_SRC_COLOR",
            "SRC_ALPHA","ONE_MINUS_SRC_ALPHA",
            "DST_ALPHA","ONE_MINUS_DST_ALPHA"}
        img1=image(200,200)
        img2=image(200,200)
        img3=image(200,200)
        img4=image(200,200)
        img5=image(200,200)
    end
    
    function draw()
        background(172, 223, 218, 255)
        blendMode(NORMAL)
    
        setContext(img1)
        fill(r1,g1,b1,255)
        ellipse(125,125,100)
        setContext()
    
        setContext(img2)
        fill(r2,g2,b2,255)
        ellipse(75,75,100)
        setContext()
    
        setContext(img3)
        blendMode(NORMAL)
        background(r3,g3,b3,255)
        sprite(img1,0,0,200,200)
        blendMode(mode[m])
        sprite(img2,0,0,200,200)
        setContext()
    
        setContext(img4)
        blendMode(NORMAL)
        background(r3,g3,b3,255)
        sprite(img1,0,0,200,200)
        blendMode(srcTab[src],dstTab[dst])
        sprite(img2,0,0,200,200)
        setContext()
    
        setContext(img5)
        blendMode(NORMAL)
        background(r3,g3,b3,255)
        sprite(img1,0,0,200,200)
        blendMode(srcTab[src],dstTab[dst],srcTab[srcA],dstTab[dstA])
        sprite(img2,0,0,200,200)
        setContext()
    
        blendMode(NORMAL)    
        sprite(img3,10,780)
        sprite(img4,10,480)
        sprite(img5,10,180)
    
        fill(255,0,0)
        text(modeS[m],10,1000)
        r,g,b,a=img3:get(100,100)
        text(string.format("rgb3 %.3f %.3f %.3f %.3f",r3/255,g3/255,b3/255,a/255),210,960)
        text(string.format("rgb1 %.3f %.3f %.3f %.3f",r1/255,g1/255,b1/255,a/255),210,940)
        text(string.format("rgb2 %.3f %.3f %.3f %.3f",r2/255,g2/255,b2/255,a/255),210,920)
        text(string.format("rgb  %.3f %.3f %.3f %.3f",r/255,g/255,b/255,a/255),210,900)
    
        text(srcTabS[src].."  --  "..dstTabS[dst],10,700)
        r,g,b,a=img4:get(100,100)
        text(string.format("rgb3 %.3f %.3f %.3f %.3f",r3/255,g3/255,b3/255,a/255),210,660)
        text(string.format("rgb1 %.3f %.3f %.3f %.3f",r1/255,g1/255,b1/255,a/255),210,640)
        text(string.format("rgb2 %.3f %.3f %.3f %.3f",r2/255,g2/255,b2/255,a/255),210,620)
        text(string.format("rgb  %.3f %.3f %.3f %.3f",r/255,g/255,b/255,a/255),210,600)
    
        text(srcTabS[src].."  --  "..dstTabS[dst],10,420)
        text(srcTabS[srcA].."  --  "..dstTabS[dstA],10,400)
        r,g,b,a=img5:get(100,100)
        text(string.format("rgb3 %.3f %.3f %.3f %.3f",r3/255,g3/255,b3/255,a/255),210,360)
        text(string.format("rgb1 %.3f %.3f %.3f %.3f",r1/255,g1/255,b1/255,a/255),210,340)
        text(string.format("rgb2 %.3f %.3f %.3f %.3f",r2/255,g2/255,b2/255,a/255),210,320)
        text(string.format("rgb  %.3f %.3f %.3f %.3f",r/255,g/255,b/255,a/255),210,300)
    end
    
  • Posts: 103

    Thanks @dave1707 that helped a lot! Someone may want to double check, but I found that setting the parameters to this should give the same result:

    blendMode(NORMAL) = blendMode(ONE,ONE_MINUS_SRC_ALPHA)
    blendMode(MULTIPLY) = blendMode(DST_COLOR,ONE_MINUS_SRC_ALPHA)
    blendMode(ADDITIVE) = blendMode(ONE,ONE)

    @dave1707 I edited your code a bit so it draws the ellipses at half the transparency

Sign In or Register to comment.