简体   繁体   中英

GLSL blending modes, creating additive transparency

I have a little shader that looks like this, and has a neat effect.

uniform float beatScale;
varying vec3 vPos;

void main() {

  vec3 normPos = (normalize(vPos) + vec3(1, 1, 1)) / vec3(2, 2, 2);
  float alpha;

  if (normPos.y < beatScale - 0.1) {
    alpha = 0.0;
  } else if (normPos.y < beatScale) {
    alpha = 1.0 - (beatScale - normPos.y) / 0.1;
  } else {
    alpha = 1.0;
  }

  gl_FragColor = vec4(normPos, alpha);    
}

But the transparent parts of my objects in front block the objects behind, knocking out pixels that should have been rendered.

My sorry attempt was:

gl_FragColor = gl_FragColor + vec4(normPos, alpha);

But that didn't seem to change it. I was hoping gl_FragColor had the previous pixel color, but no dice.

How can I add the computed color the color that was there before? I don't care about what's on top, this is all glowy stuff I can simply add together.

如果要进行添加混合,则应关闭深度写入。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM