How to check if face in mesh is culled/invisible to camera?

Hi everyone,

If I have a static or skeletal mesh, is there a way to get the IDs of all the faces in that mesh that are invisible to the camera (culled)?

Obviously the Unreal Engine knows it should not draw them, but I couldn’t find a way to access that info in the reference.

Perhaps unnecessary, but I have attached two images to illustrate.

Thank you for any ideas or feedback!

That’s normally handled at the shader level, not the application level. For example, you can use the SV_IsFrontFace Semantic in HLSL to find out if a triangle is front facing or not - but that data isn’t saved off each frame or send back to the CPU.

Hi Matt, thank you for this information. I managed to script it inside 3D Studio Max, but I didn’t know it would be so hard to in UE4.

Indeed I would need the data since I want to do complex vertex animation which is different for each vertex.

As I’m new to UE4, am I correct in stating that I would have to study writing a new shading model with my own custom geometry shaders embedded in the shader section of the engine?

Like in this article: Unreal Engine 4 Rendering Part 6: Adding a new Shading Model | by Matt Hoffman | Medium

If that is the case then I have a long study period ahead of me…

You could get the normal of each polygon and do a dot product with the camera direction vector. Any face that is less than 90 degrees from the camera direction is facing away from the camera.

EDIT: This won’t find polygons that are facing the camera but hidden by other surfaces between the polygon and the camera.

Hi GBX, that is exactly what I did in 3DSMax, I also added a raycasting part to find front facing faces that were occluded by other faces.

I was just hoping that info on faces (like being culled/visible or not) would be available inside UE4 giving way to a much faster and realtime version.

But I’m really disappointed now that things like access to faces, vertices et cetera is way more difficult than in 3DSMax. ;-(

That is too slow to be done on CPU… this is why you need “shader code” to calculate that (on GPU)

Thanks Bruno, I looked into it and I had no idea that HLSL can be used for ray casting, but I saw a lot of examples online.

Would this be possible from a Custom expression or do I need to embed that code in the engine?

I have no idea… In regard to HLSL code I’m as smart as a rock :slight_smile:
There’s some graphics programmers around AnswerHub from time to time, they might help…


Awesome, thanks!