mrdoob/three.js — Issue #1359: Writing to texture alpha channel and using in a post-process shader
Author: scottrabin
Created: 2012-02-19 17:30:10+00:00
State: open

I'm trying to adapt the water refraction algorithm from http://http.developer.nvidia.com/GPUGems2/gpugems2_chapter19.html, but I'm having trouble writing to and then using the alpha channel as a mask. The way the shader is described in that article is to first render to a texture and lay down an alpha mask for all refractive meshes, then reprocess the image using the alpha mask to resample the texture in the refraction calculation.

My code demonstration is available at http://scottrabin.github.com/Terrain/

The general synopsis is: first, render the scene into a texture `rtTexture`, using `waterFragmentShaderMask` to render the water plane (outputting a 0-alpha color). Then, render that texture onto a quad. Right now, I'm just attempting to see where the alpha mask would show up on the rendered image, so in the quad fragment shader I change the blue quantity to 1 for alpha < 0.5. Unfortunately, nothing shows up; I've been at this for a few hours and I simply don't know enough to determine why it isn't working and how to fix it.

I'm also calling `renderer.context.blendFuncSeparate( ONE, ZERO, ONE, ZERO );` per the suggestion of someone on Stack Overflow in order to set the alpha value of the pixel to the value set in the fragment shader.

All I would like is for the post-process fragment shader to correctly render pixels that should have been blue from the water as blue depending on the alpha mask. Thanks!