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.
Seems like a working approach.
I will send you some example code soon
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?
I will PM it to you, if you want you can clean it up and post into the forums, or whatever else you want.
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?
This is what I sent to , it doesn’t directly answer your question as this is not voxelizing code, or using geometry shaders, but it shows how to use a custom drawing policy:
Okay here is a link to the code: https://drive.google.com/file/d/0Bzq...it?usp=sharing (It is a little messy since its taken straight from the Hair Simulation rendering).
The basic idea is:
-
From FDeferredShadingSceneRenderer::Render, create your templated PrimitiveDrawingInterface pointing to your DrawingPolicyFactory passing in the Current view and the context type (In this case I am using the context type to define the current rendering pass for the hair).
-
Check each mesh to see if it has opted in for this particular drawing policy (Using whatever methods you want, in this case I have a Hair Relevance variable that can be defined in the Scene Proxy). And if it has opted in, then call the SceneProxy’s Draw method
-
Do your typical setup in your scene proxy for drawing a mesh
-
This will lead to the DrawingPolicyFactory Draw method. Here you choose which DrawingPolicy to use to setup and draw the mesh, in this case that depends on the Context Type defined earlier. Here is where you would setup and assign your bound shader state, and setup the shared rendering state.
-
Finally the DrawingPolicy DrawMesh function is called to actually draw the mesh however you want.
Let me know if you need any help, again apologies for the messy code. I can be found most days on irc in the #unrealengine chatroom on freenode, and also am on Skype under the name .
Thanks .
the link doesn’t seem to work though.
Sorry about that, seems the link has stopped working for some reason. Here is a new link:
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
Also on top of what Ryan has written, make sure to run your editor with the -d3ddebug command line argument, it will give you more feedback. And also add r.ShaderDevelopmentMode=1 to the ConsoleVariables.ini file located in the Engine/Config directory.
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?
Take a look at the way Hull/Domain shaders are done in Vertex Factories, the idea is to allow a Vertex Factory to opt in for a Geometry Shader, and have the default set to false, that way you don’t need to modify all the VF’s. Then you will need to make sure that the Geometry Shader gets set when all the other shaders get set.
nvm I figured out most of the basis.
What need now is to:
- Gather geometry from around camera.
- Send that geometry to shader.
- 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.