Voxelize scene. Where to place the code?

Hi everyone. I’m working on some big graphics modifications, working directly on the source, and now I need to render the objects that are inside a volume to a voxel grid.
To do that I need to render all the objects that collide with that volume with culling disabled with a special shader, but given that the engine has different paths for static and dynamic objects, I don’t even know where to start.
Can anyone provide some help?

Anyone? I got all the other stages that I needed working, but I’m still stuck with this one.

After digging through the rendering code, I think I have an outline of the process that might work, but I wanted to ask the people that know about Unreal Engine first.
Just to be clear, what I need is to render the objects that are inside a volume with a custom pixel/vertex/geometry shader
My idea to do that is something like this:

-Set as the render targets the UAVs
-Get all the primitives bounds( Scene->GetPrimitivesBounds )
-Intersect the bounds with my volume
-For each primitive inside the volume
-Draw it with a custom drawing policy

Is that correct? Also, how do I set up a drawing policy? I looked at the ones of the engine, but I didn’t find one that used geometry shaders.
If anyone can provide some help here, it would be really appreciated, I’m having a hard time with this.

Then I’ll start to implement it, and leave the drawing policy for later.

Thanks! Will you send it as a pm, post it here, or by email?

Hey I’ve got a similar problem - I’ve been trying to duplicate the base rendering code and incorporate a geometry shader into it but I keep getting a CTD whenever I try to run unreal engine without any error messages. I know its something to do with the geometry shader code itself but for some reason the shader debugger doesn’t show the errors.

I want to be able to voxelize every object I put into the scene by directly accessing the triangles using a geometry shader. Are you able to send me your example code as well?

Thanks .

the link doesn’t seem to work though.

to be honest, I actually hacked my way trough.
I added a geometry shader stage to the base pass rendering, and then voxelized directly from the pixel shader. just duplicate the triangles in the gs, and discard then in the pixel shader the voxel ones after voxelizing. The problem with that Is that I was never able to disable culling, so I got some objects popping in and out when I moved the camera.
I, for the moment, only needed to take a few screenshots, so that worked fine, but it is an ugly hack
Here are the screens, btw

Emissive materials:
http://i.imgur.com/bMQAl5O.png

Indirect lighting from a spot light (one bounce):
http://i.imgur.com/GE7dB0s.png

PS: I took those on a GTX 750 Ti and a FX-6300. Everything on the scene is dynamic. Will start to work again on this maybe next month

Hey Ryan that looks awesome. I’m still stuck at getting the geometry shader to work by hacking the base pass rendering as well.
I can’t even get a simple pass-through geometry shader to work (the engine crashes without any error messages after the splash screen). at the moment I feel like it may be something to do with my shader code:

[maxvertexcount(4)]
void GShader(point FBasePassVSToPS input[1], inout TriangleStream<FBasePassVSToPS> OutputStream)
{
// Now we “append” or add the vertices to the outgoing stream list
FBasePassVSToPS outputVert;

{
    outputVert.Position = input[0].Position;
	outputVert.BasePassInterpolants = input[0].BasePassInterpolants;
	outputVert.FactoryInterpolants = input[0].FactoryInterpolants;

	OutputStream.Append(outputVert);
}
OutputStream.RestartStrip();

}

Your code IS wrong. You are creating the triangles from just one point. Plus, it probably crashes because the vertex shader is working with triangles and you are inputing points to the gs
Here’s an example of a pass-trough gs:

Remember that you need to change the inputs and outputs. For example, you can’t use SV_Position as an input to the GS. You can transform the vertices using the vs, then send the position using a TEXCOORD, and on the GS copy it to a SV_Position.
Hope that helps

Thanks guys, I do have the shader debugger on but it seems like it doesn’t like outputVert being an array.

i.e. if I make it outputVert[3], it comes up with error X3018: invalid subscript ‘Position’.
If I don’t do this, it seems to compile without any errors but the splashscreen disappears and nothing loads.

I think perhaps the reason why its not working is because vertex factories does not support geometry shader.
I’ve got this in my code: GeometryShader->SetMesh(VertexFactory, View, PrimitiveSceneProxy, BatchElement);

What do I need to modify to make geometry shaders compatible with vertex factories?

nvm I figured out most of the basis.

What need now is to:

  1. Gather geometry from around camera.
  2. Send that geometry to shader.
  3. Process it in Compute shader to generate voxel repsentation stored in 3D texture.

Steps 2 and 3, are just about writing proper compute shader and I don’t expect anyone will tell me how do it exactly.

But I’m stuck at point one. I just don’t know at which point in C++ to get my geometry and bind to property. Or if that is needed at all. It might be already done somewhere and I could just reuse existing code.