#extension GL_OES_standard_derivatives : enable varying vec4 f_Color; varying vec3 f_BC; varying vec4 e_Color; void main(){ if (any(lessThan(f_BC, vec3(0.005)))) { // edge, draw it with the edge color gl_FragColor= e_Color; } else { if (gl_FrontFacing) { // front face, draw it with the face color gl_FragColor = f_Color; } else { // back face, draw it grey gl_FragColor = vec4(0.5, 0.5, 0.5, 1.0); discard; } } }
function InitGL(canvas) { var gl = WebGLUtils.setupWebGL(canvas,'OES_standard_derivatives'); if (!gl) { alert ("WebGL isn't available"); } // required to turn on fwidth and such. gl.getExtension('OES_standard_derivatives'); return gl; }
this.gl.enable(this.gl.BLEND); this.gl.blendFunc(this.gl.SRC_ALPHA, this.gl.ONE_MINUS_SRC_ALPHA);
this.direction = this.gl.CCW; this.gl.frontFace(this.direction);
this.gl.enable(this.gl.CULL_FACE); this.gl.cullFace(this.gl.BACK)
this.gl.enable(this.gl.DEPTH_TEST); this.gl.depthFunc(this.gl.LESS); this.gl.depthMask(this.gl.TRUE);
this.gl.clear(this.gl.COLOR_BUFFER_BIT | this.gl.DEPTH_BUFFER_BIT);