PDA

View Full Version : 3 questions



zed
02-24-2011, 01:15 PM
Seems Im the only one asking things, anyways here goes

1/ how to change a webgl canvas's AA value whilst it already exists?

at start up either
gl = canvas.getContext("experimental-webgl", { antialias:true } // works
or
gl = canvas.getContext("experimental-webgl", { antialias:false } // works

but if it already exists how to change its value i.e. if its
gl = canvas.getContext("experimental-webgl", { antialias:true }
and the I call
gl = canvas.getContext("experimental-webgl", { antialias:false }
it will still stay true, I assume I have to destroy the webgl context first + then create a new one? If so whats the best way, or is it possible to change AA on the fly?

2/ (not really webgl also only a minor thing) but how to set a canvas elements zdepth
Ive tried canvas.setAttribute( "style","z-index: 0" ); + also here
<canvas id="GLcanvas" style=" .. " as well, also
document.getElementById("GLcanvas").style.zIndex="-1";

but the values I give it are ignored, which means all the html text I have to give a higher value than the canvas's zvalue, Ild just prefer changing the single webgl canvas value. Note - I can change a canvas element z-value if its a 2d canvas i.e.
document.getElementById('canvas2D').getContext('2d ');
but it seems with webgl canvas's you cant

3/ same scene drawing a blended (src_alpha,1-src_alpha) quad over the scene afterwards.
but the background is showing through!
This seems like its a bug in the brower implementation but it occurs both with chrome(*) + firefox, so is this expected behaviour.

top gl = canvas.getContext("experimental-webgl", { alpha:true,
top gl = canvas.getContext("experimental-webgl", { alpha:false,
http://anarchistsunited.com/crap/error.jpg

(*)though chrome doesnt run webgl anymore for me since yesterday, gah

Lots of text, well cheers anyways Zed

SteveBaker
02-24-2011, 02:37 PM
The problem with the background showing through is because you have created your WebGL canvas with an alpha plane. Bizarrely (because it's so rarely used), this is the default. There was a bug a while back where you got an alpha plane even when you explicitly turned it off...I worked around that by clearing the screen's alpha to fully opaque and then using the color mask to disable subsequent writes to the alpha plane. However, that's probably not needed anymore.

You'll probably want:


gl = canvas.getContext ( "experimental-webgl",
{
alpha : false ,
antialias : true ,
depth : true ,
stencil : false ,
premultipliedAlpha: false } ) ;

zed
02-24-2011, 03:55 PM
Cheer once again Steve
Im not 100% but I assume, the alphaplane is analogous to the alpha buffer in opengl but this is only used in opengl when you specify DST_ALPHA etc.
Im using the common mode SRC_ALPHA, ONE_MINUS_SRC_ALPHA (src_alpha comes from the texture/shader it shouldnt come from the alphaplane/buffer)
or is it different in webgl?

zed
02-24-2011, 04:06 PM
spot the other copy/paste mistake I made in my first post :lol:

top gl = canvas.getContext("experimental-webgl", { alpha:true,
top gl = canvas.getContext("experimental-webgl", { alpha:false,

SteveBaker
02-24-2011, 10:16 PM
Cheer once again Steve
Im not 100% but I assume, the alphaplane is analogous to the alpha buffer in opengl but this is only used in opengl when you specify DST_ALPHA etc.
Im using the common mode SRC_ALPHA, ONE_MINUS_SRC_ALPHA (src_alpha comes from the texture/shader it shouldnt come from the alphaplane/buffer)
or is it different in webgl?

Yeah - exactly - it's the "Destination Alpha" thing - and the blendmode stuff works just the same in WebGL.

But if you write values into the destination alpha of the frame-buffer of a "real" GPU rendering context (like a Windows window or an X11 window) - nothing much happens.

However, when you write to the destination alpha of a canvas, the canvas compositor treats your entire rendered image as translucent - and you see through to the underlying web page.

Now, if you read very carefully the rules for the blend function - you'll find that in SRC_ALPHA/ONE_MINUS_SRC_ALPHA blend mode, the source alpha is written to the frame buffer...hence the destination alpha buffer has values less than one in it when you just render any old translucent polygons into it...and that's why you're seeing the underlying window through translucent polygons - even when there is an opaque polygon behind it.

Quite honestly - I *NEVER* found a good use for destination alpha in regular OpenGL and Direct3D applications - and I was horrified to discover that it's the default in WebGL.

I predict having this conversation many, MANY times over the coming months and years!

-- Steve

zed
02-25-2011, 12:25 PM
Cheer for the clarification, Ill just have to have it turned off then.
I did use dst_alpha for a depth of field effect. But I suppose, practically anything you want to use dst_alpha for, you could use the stencil buffer instead (apart from the blending)

SteveBaker
02-25-2011, 05:50 PM
Well, I suppose you could clear the alpha plane back to opaque after you've finished rendering.