4
\$\begingroup\$

I'm looking for a unity API or function call to allow me to do the following ...

I wrote some really complex functions that are compute shaders. These compute shaders manage a huge compute buffer containing voxel information. I then take portions of (or the entire) voxel buffer in another compute shader and produce a vertex buffer. All of this is done on the GPU with only compute shader calls from the CPU.

Now I want to render that vertex buffer but I must be looking in the wrong place because I can't find any information on how this is done within unity despite there being other examples on how to do this using raw DX or openGL approaches.

Can anyone point me in the right direction to determine how I can render using a specified shader a buffer already in graphics RAM (and ideally give it some textures too)?

\$\endgroup\$

3 Answers 3

2
\$\begingroup\$

Unity has 2 static functions on the graphics class to allow you to do this. It does however avoid the CPU altogether (desired result)

void OnRenderImage()
{
   Graphics.DrawProcedural()
   Grpahics.DrawProceduralIndirect()
}
\$\endgroup\$
0
\$\begingroup\$

Sounds like you want to Render to a Texture.
After you do a render pass to that texture using your shaders, you can attach that texture to a quad and render it with the main camera.

\$\endgroup\$
3
  • \$\begingroup\$ You missed the bit where I have a full set of geometry I want to render that's in a buffer on the gfx card. I want to render a mesh basically. \$\endgroup\$
    – War
    Dec 9, 2013 at 19:45
  • \$\begingroup\$ Ah I see. I have no idea how to do that with Unity. You could use docs.unity3d.com/Documentation/Manual/… and write your own OpenGL/DirectX \$\endgroup\$ Dec 9, 2013 at 21:06
  • \$\begingroup\$ ouch there has to be a better way than that else i might as well use raw dx or openGL ... this is basically the most core component of my game. \$\endgroup\$
    – War
    Dec 9, 2013 at 21:57
0
\$\begingroup\$

If you have vertex and triangle data in your buffer you can use :

Buffer.GetData()

to get back those infos in Vertex and triangle arrays, then with Graphics.GL library, rebuild a mesh and actualise the normals and assign any material you want.

Well only in the case that your buffer is Read Write enabled.

EDIT :

It's not only Unity which prevents you to use data directly from the GPU Buffers by the CPU, it is the whole principle of Accelerated graphics. That said you should be able to read data in your compute shader Try to see on the side of registers, if you can specify a registeer for your buffer (which you can) you have probably a way of reading from this register in a classic shader?

\$\endgroup\$
1
  • \$\begingroup\$ since technically unity prevents you keeping the data on the graphics card and rendering the buffer through a vertex shader i'm going to have to go with this, but really i wanted a direct from gpu to screen solution. Having said that, since asking this question i have decided to rethink my solution. \$\endgroup\$
    – War
    Dec 21, 2013 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .