View Full Version : Saving data from the Fragment shader
05-01-2012, 01:39 PM
I know we can use the fragment shader to render a texture map for a mesh later for an animated texture map (and the 'Learning WebGL", lesson 16 has a great example of that).
But it seems like only 4 bytes (vec4) can be written each time from the fragment shader (RGBA). Is there another way to write out more data per fragment shader access? For example, the x,y,z values of an intersection between a ray and a polygon?
Any thoughts? Or should I just go out and have pizza?
05-08-2012, 09:53 PM
It sounds like you might be asking two questions. The answer to the question, "Can I write more than 16 bytes of data (a vec4 is four 32-bit bytes) per fragment shader operation?" is clear: No. In OpenGL (WebGL's big brother) lets you attach more than one texture to the render buffer and write several values at once, but not in WebGL, which is deliberately stripped down so that it can work on low-end devices.
You might be asking a second question, "Can I write the x,y,z values of an intersection between a ray and a polygon?" The answer is yes. You just have to encode these values into a vec4.
So what do you do if you need to save more information? See my detailed description a bit earlier in this forum on depth peeling transparency. I do 10 renders to a bunch of different textures, each time saving various kinds of information. The final render assembles information from those textures.
05-09-2012, 11:29 AM
Yes, thanks for the correction: vec4 is four 32-bit bytes. I meant writing out to a gl_FragColor to produce a texture map was only 4 bytes (RGBA).
I had a sense that I may need to create several renderers to do the job, each one saving some information in a texture map.
Thanks for the assistance. It's good read other postings to confirm the results I am getting. And will review more of your postings on depth peeling transparency.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.