Writing values to a texture

Hi all,

I would like to write values to a texture (more or less in a GPGPU way). In my vertex shader I calculate a position, which I would like to store in a texture for a next rendering pass.

Does anyone have a good suggestion how to do this?

Thanks

http://en.wikipedia.org/wiki/Framebuffer_Object

Thanks, but maybe I should be a little more specific.

Say I calculate, for each vertex, three positions that I want to write to texture. I guess I’d need a geometry shader to extend the current vertex position with 2 new positions and render that to texture or vertex array.

However I’m not sure which render-to-texture strategy to adopt. FBO to Vertex-array seems a good solution.

Anyone with experience in RTT / RTVA?

Direct RTVA is not directly possible on current hardware, and its doubtful it ever will. The next version of OpenGL will be able to “capture” the output of vertex and geometry shaders, which is more powerful than RTVA.

You have to emulate this behaviour by rendering a quad and “reinterpreting” the color values as coordinates by reading back the framebuffer into a PBO and using this as VBO. That way you move the logic from the vertex shader to the fragment shader. Propably you have to use the original vertex array as input texture instead of vertex array, and just render a fullscreen quad for the calculation.

It’s not easy, but it works. You just have to figure out the correct coordinates so one “vertex” in your input will correspond to exactly three pixels in the output. This way you can produce three values in the fragment shader.

Ok, that is a very good suggestion!

Problem is that I generate my set of vertices from a marching cubes approach. I could nicely use a geometry shader to generate the approapriate set of vertices. However, I would like to have these as a 2D texture or vertex array for a new rendering pass.

So problem is I cannot start from a 2D texture as input.

Is this possible?!

What will the “capture” extension be?

So I guess, with the “capturing” of intermediate results you mean the OpenGL transform feedback functionality (equivalent to DX10 stream out).

Just to be sure: does this feedback mean I can store my transformed vertices after either the vertex shader or the geometry shader?

Yes draw GL_POINTS, and use a additional stream for setting the position on the texture. after that use a PBO to convert the texture into a VBO. (uses the vertex shader)
Or save your geometric data in textures, process the data in a fragmentshader an convert the output with a PBO. (uses the fragment shader)

Originally posted by Overmind:
Direct RTVA is not directly possible on current hardware, and its doubtful it ever will.
Uhm, all ATI hardware from 9500 and up are capable of doing direct render to vertex array. It was never exposed in OpenGL (the superbuffers extension never got ratified) but it’s definitely possible and it’s available in DirectX.

Thanks guys. I’ll be working on the transform feedback next week.

Indeed it seems that RTVA is a technique invented by ATI. Nowadays a new appraoch (stream-out for DX10 and Transform Feedback for OpenGL) seems to be the better alternatives!

Stream-out is fine, but there are still plenty of reasons why you’d want to use RTVA and similar approaches even on DX10 level hardware for some techniques. One reason is that stream-out is limited to float attributes. With RTVA you can render to any renderable format, which saves memory and bandwidth. It also doesn’t preserve topology.

One reason is that stream-out is limited to float attributes.
That’s just a limitation of current hardware. I don’t see a fundamental problem here.

The problem with exposing RTVA is that you have to know the exact internal framebuffer format for being able to reinterpret it as vertex data. You force the hardware to support some well known framebuffer formats. As we have it now, the hardware can choose whatever storage layout is best (as long as it provides the requested precision).

Render to texture does not suffer from this problem, because the texture storage format is hidden from the user as well.

Does anyone have a good example that demonstrates transform feedback that writes interleaved varying variables to a buffer?

Originally posted by Overmind:
[QUOTE]That’s just a limitation of current hardware. I don’t see a fundamental problem here.
Agreed.

Originally posted by Overmind:
[QUOTE]The problem with exposing RTVA is that you have to know the exact internal framebuffer format for being able to reinterpret it as vertex data.
This is also the case if you were to expand StreamOut with more types than float.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.