Question

I am creating a particle emitter with a texture that is a white circle with alpha. Unable to color the sprites using color passed to the fragment shader.

I tried the following:

    gl_FragColor = texture2D(Sampler, gl_PointCoord) * colorVarying;

This seems to be doing some kind of additive coloring.

What I am attempting is porting this: http://maniacdev.com/2009/07/source-code-particle-based-explosions-in-iphone-opengl-es/ from ES 1.1 to ES 2.0

Was it helpful?

Solution

with your code, consider the following example:

  • texture2D = (1,0,0,1) = red - fully opaque
  • colorVarying = (0,1,0,0.5) = green - half transparent

then gl_FragColor would be (0,0,0,0.5) black - half transparent.

Generally, you can use mix to interpolate values, but if I understood your problem then its even easier.

Basically, you only want the alpha channel from your texture and apply it to another color, right? then you could do this:

gl_FragColor = vec4(colorVarying.rgb, texture2D(Sampler, gl_PointCoord).a)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top