3

I'm rendering a scene of polygons to multiple render targets so that I can perform postprocessing effects. However, the values I'm setting in the fragment shader don't seem to be accurately reflected in the pixel shader.

Right now the pipeline looks like this:

  • Render basic polygons (using simple shader, below) to an intermediate buffer
  • Render the buffer as a screen-sized quad to the screen.

I'm using WebGL Inspector (http://benvanik.github.com/WebGL-Inspector/) to view the intermediate buffers (created using gl.createFrameBuffer()).

I have a very simple fragment shader when drawing the polygons, something like this:

gl_FragColor = vec4(1, 0, 0, 0.5);

And this before my draw call:

gl.disable(gl.BLEND);

I would expect this to create a pixel in the buffer with a value of exactly (255,0,0,128), but in fact, it creates a pixel with the value of (255,0,0,64) -- half as much alpha as expected.

The program is fairly large and tangly, so I'll update the post with specific details if the answer isn't immediately apparent.

Thanks!

Ipsquiggle
  • 1,814
  • 1
  • 15
  • 25
  • How do you know what the alpha value of that pixel is? What are you drawing that you are writing this pixel value. – Nicol Bolas Jan 24 '12 at 00:40
  • I'm afraid that we'll probably need a bit more information, but one thought jumps to mind immediately: Do you have antialiasing enabled? If so, and if the pixel you are sampling is at the edge of a polygon, it may end up being blended into a lower-than-expected value. – Toji Jan 24 '12 at 01:00
  • @NicolBolas: I have inspected the value of the pixel directly using WebGL Inspector, sampling its onscreen value in the final render, and also be observing its behavior in subsequent processing steps. The value is being drawn from a simple polygon with the above simple fragment shader on it, into a framebuffer, and that framebuffer is then being rendered to the screen buffer. – Ipsquiggle Jan 24 '12 at 23:47
  • @Toji The color is uniform across the entire surface of multiple polygons, I have sampled 100s of points in dozens of different renders trying to hunt down the cause. (I did just learn that AA is enabled by default though, in both Chrome and FF, which is unexpected! Thanks for pointing this out, will investigate if it's related.) – Ipsquiggle Jan 24 '12 at 23:51
  • Have you checked that your render target has no gamma correction applied? If so, it can change the value you are returning – crazyjul Jan 25 '12 at 08:36
  • @crazyjul This gamma thing seems like a pretty good lead, actually. Investigating... – Ipsquiggle Jan 25 '12 at 19:50
  • What about trying "gl_FragColor = vec4(1, 0, 0, 1);" or "gl_FragColor = vec4(1, 0, 0, 0);"? Are you sure that there are 8 bits dedicated to alpha? It would be slightly bizzare, but there's no point in complaining about 0.5 = 64 if you don't know what the scale is. Also, is it affecting your rendering somehow? Or is it that you noticed the values are smaller than expected and it seems strange to you? @crazyjul Gamma should only affect colors. Changing alpha would be a bad idea and would be likely to cause problems in a lot of applications. – the swine Jan 26 '12 at 12:09

1 Answers1

1

Do you have premultiplyAlpha set to true? Fiddling with that is the first thing that came to mind re: weird alpha values.

Ilmari Heikkinen
  • 2,711
  • 1
  • 19
  • 14
  • I would expect this would be messing with the RGB values, not the A values, but I'm willing to check it out. – Ipsquiggle Jan 30 '12 at 22:50