Jump to content

help with alpha on GLSL filter

Recommended Posts

I'm writing a game and since the map will be quite big, I'm running the game logic in a GLSL shader.

the pipeline works, I see stuff getting updated etc, my only problem is when I try to create a political overlay of the calculated results. In the map (attached screen) the yellow area is colonized.


the problem is, no matter what alpha I return in my fragment, it's this almost but not quite solid yellow.


filter is super simple; if colonized (blue channel of the texture) then emit that player color (fixed yellow for now to simplify):

 vec4 oc = texture2D(uSampler, vTextureCoord);

 vec4 c = vec4(0.);
 //b channel holds colony value
 if (oc.b> 0. ) {
    c = vec4(1.,1.,0.,0.);
 gl_FragColor = c;


I tried whatever value for c.a, but it's always the same result.


the filter is not applied to the galaxy map itself tho: it's another sprite, built on the render texture I use to hold the data, added as child:


    game.colonize= new Phaser.Filter(game,undefined, game.cache.getShader('colonize'));  //game logic

    game.mapper= new Phaser.Filter(game,undefined, game.cache.getShader('mapper')); //color yellow colonized area, the one above

    game.politicalRT = game.make.renderTexture(2048,2048);
    game.politicalRT.render(game.make.sprite(0, 0, 'mas')); //mas hold the mass density of the galaxy

    game.politicalSP = game.make.sprite(0, 0, game.politicalRT); //sp is redrawn on the render texture every update
    game.politicalOL = game.make.sprite(0, 0, game.politicalRT);

    game.politicalSP.filters = [game.colonize ];
    game.politicalOL.filters = [game.mapper ];

    game.galaxymap.inputEnabled = true;

    game.galaxymap.addChild(game.politicalOL); //politicalOL is that yellow blob that doesn't appear properly transparent


the mapper should picture a light, transparent yellow, but it isn't working. is there some magic in blending child filtered sprites?





Link to post
Share on other sites

found out the issue, needed to add

game.politicalOL.blendMode = PIXI.blendModes.ADD;

to the child

but I don't understand why NORMAL does a SCREEN, beside, ADD seems correct but what I wanted was the kind of layer mixing paint programs call 'default', this one will saturate color instead of masking it with the topmost.



Link to post
Share on other sites

There is no magic, but you really have to very carefully examine your code for possible problems. As far as I see it, it plasters 100% alpha all over the surface. I'm gonna need a more complete source of your shader. I had similar issue when I tried using "vColor" - unless you use shader directly, it's not defined and results in glitches. I've noticed that shaders only work 100% "properly" if you attach them directly to renderable objects using their "shader" property.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...