Hi Chris, comments inline... On Sun, Nov 23, 2008 at 9:47 AM, Chris Denham <[EMAIL PROTECTED]> wrote: > I have been trying to work out how/if you can use a shader to compute a > value (once per frame) and use that value as a constant in the shader for > the rest of the frame. > > For example, I want to use a shader to find the minimum value in a texture > once at the beginning of a each frame, then use that minimum value (probably > as a uniform) in a fragment shader.
Yes, a uniform would be the right path in. > > It seemed to me I have two problems: > 1. How do I get a shader (or part of a shader) to only execute once per > frame? (Not sure what you mean by part of a shader.) But you could use two passes, with the scene you're analyzing under your special shader, the other pass would render using the result from the first pass > 2. How do I get the minimum value out of the shader in order to get the > application to put it in a uniform? There are three ways I can think of: 1) the usual way: readback final fragment values written to some render target, like a texture or FBO. 2) use the geometry feedback path (I have little experience with this path, so dont know its limitations etc) 3) use CUDA > The only way I could think of to get a value out of a shader was to > render its result to a texture and pick the data out of the texture in the > application. Urgg.. there must be a better way. it's not that distasteful is it? > I had the idea that people may be using shaders as a general purpose 'rocket > powered' implementation for all kinds of general algorithms, but I can't Sure, NV's CUDA does all sorts of general-purpose computing on the GPU, hiding implementation details behind a parallel compute abstraction. At NVISION there was a cool demo using CUDA and GL together to render a scene using both raytracing and rasterization (used raytracing only on a shiny car, used rasterization for the road and other background features, a nice approach for quality/performance tradeoffs) > see how to use them in that way. Does OSG provide a way to use GLSL for > anything other than 'colouring pixels' ;-) ? afaik OSG doesn't have any direct support for CUDA, but that doesn't stop you from interpreting a framebuffer result as something other than colored pixels. cheers -- mew > > Chris. > > - The answers to stupid questions are often more enlightening than the > answers to smart ones. > > _______________________________________________ > osg-users mailing list > [email protected] > http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org > > -- Mike Weiblen -- Boulder Colorado USA -- http://mew.cx/ _______________________________________________ osg-users mailing list [email protected] http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

