Jump to content

help with alpha on GLSL filter


LoSboccacc
 Share

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.);
    c.a=0.1;
 }
 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.colonize.setResolution(2048,2048);

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


    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.input.enableDrag(false);

    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?

 

 

 

XkyF1ev.png

Link to comment
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.

 

corr.PNG

Link to comment
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 comment
Share on other sites

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...