Skip to main content
gamedev.net
🔒 Locked

GLSL framebuffer read

Started by atetanat Jul 30, 2007 at 6:51 AM 2 replies 4.5k views
Original Post
atetanat
atetanat
Is there any hacks or extensions or anything at all that lets you access the framebuffer (or depth-buffer) in GLSL. I had lots of shader plans, did all the tutorials about GLSL, then only read too late that you can't access the framebuffer. Now it seems 3/4 of my shader ideas are impossible: 1) Everyday basic transparent objects have per-channel transparencies - a piece of green cellophane is mostly opaque to red / blue, and mostly transparent to green. gl_FragColor = (gl_OldColor.xyz * material_alpha.xyz) + (lighting results etc); 2) Volumetric transparencies: Depth-sort faces, then, take the distance between old Z and new Z and alpha = pow(volume_alpha, ((gl_FragDepth - gl_OldDepth) / normalized_eye_vector.z)); gl_FragColor = gl_OldColor * volume_alpha; 3) Single-polygon sphere-shader, where depth is calculated from the coordinates. And many more. Framebuffer access must be coming in the future, right? I mean, this seems almost as important as having uniform and attribute values. During fixed transparency calcs the framebuffer pixel must be read from memory to the GPU anyway, and the depth must be read for depth-testing. One other thing - is there any way to access a VBO array of floats from GLSL (vertex), or any other large array apart from textures? Thanks.
riku
riku
You can't read the framebuffer from a shader.

What you can do is render to a texture (perhaps using a framebuffer object), then use that texture as an input to your shader. You can render the color, depth and stencil buffers to a texture (you probably need GL_EXT_packed_depth_stencil for stencil, separate stencil buffers usually don't work with current hardware) and use them in your shader.

In your vertex shaders you can't access vertex information about any other vertex than the one being processed. You do not have access to VBO's or whatever. You can use textures as lookup tables, and you could write your data in a texture, but this sounds a bit of a hack. The latest hardware has geometry shaders which can use information about the adjacent vertices of the current vertex being processed.


-Riku
atetanat
atetanat
Thanks.

Er, can you read from the texture you're currently rendering to?

Ie, get the raw pixel coords, take a GL_NEAREST sample of the pixel about to be written using a sampler2D, manually perform the alpha-blend or depth-test, then write the pixel.
Enrico
Enrico
Quote:
Original post by atetanat
Er, can you read from the texture you're currently rendering to?

No, you can not. The result should be an error or undefined. Depends on implementation.

--

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.