glsl - Alpha-channel all 1.0 in WebGLRenderTarget when reading rendered image for post-processing -
i using three.js render world webglrendertarget. world not full whole screen , thus, has transparent background. purpose provide alpha-channel aware image effects.
i render world webglrendertarget buffer
i try post-process reading buffer , writing real screen
my post-processing function depends on alpha channel. however, looks somehow three.js post-processing shader fails read alpha channel correctly - 1.0 no matter values try put in webglrendertarget.
the simple way demostrate problem.
i create render target:
var rtparameters = { minfilter: three.linearfilter, magfilter: three.linearfilter, format: three.rgbaformat}; for(var i=0; i<this.buffercount; i++) { this.buffers[i] = new three.webglrendertarget(this.width, this.height, rtparameters); } i clear buffer setting alpha 0.3::
function clear(buf) { // debugging purposes set clear color alpha renderer.setclearcolor(new three.color(0xff00ff), 0.3); renderer.cleartarget(buf, true, true, true); } // clean both buffers start clear(buffers[0]); and use buffer read buffer , render screen in post-processing fragment shader function (threejs post-processing examples):
"void main() {", // texture buffer rendered before "vec4 sample = texture2d( texture, vuv);", // goes white (1.0) when trying visualize // alpha channel of rendered webgltarget. // should value 0.3 - slight gray "gl_fragcolor = vec4(sample.a, sample.a, sample.a, 1.0);", "}" other color values read correctly. if use vec4(sample.r, sample.g, sample.b, 1.0) directly copies expected.
is there problem of clearing alpha channel webglrendertarget?
is there problem of reading alpha values having webglrendertarget texture 2d image post-processing in glsl shader?
here fiddle implements believe trying achieve.
Comments
Post a Comment