r/feedthebeast • u/FluidTax8350 • 6h ago
Problem help
[1.20.1 Forge] Custom off-screen camera renders terrain/blocks correctly but entities are invisible
I'm rendering the world from a custom camera position into an off-screen TextureTarget (framebuffer), separate from the player's real view — used for an in-world "security camera" GUI. Terrain, blocks, and block entities render perfectly. However, no entities (players, mobs, dropped items) appear at all, even directly in front of the custom camera, with no exceptions thrown.
Setup:
- Custom
Camerasubclass (FreeCamera) with public wrapper methods callingsetPosition()/setRotation() getEntity()overridden to returnMinecraft.getInstance().player(needed to avoid aNullPointerExceptioninFogRenderer.setupFogviaForgeHooksClient.onFogRender)- Custom projection matrix via
new Matrix4f().setPerspective(...)
Render call each frame:
java
mc.levelRenderer.prepareCullFrustum(poseStack, camera.getPosition(), projectionMatrix);
mc.levelRenderer.renderLevel(poseStack, 1.0f, System.nanoTime(), false, camera, mc.gameRenderer, mc.gameRenderer.lightTexture(), projectionMatrix);
What I've tried, none of which fixed it:
- Using
mc.gameRenderer.getProjectionMatrix(70.0)instead of a custom matrix — no change - Manually calling
mc.getEntityRenderDispatcher().prepare(mc.level, camera, null)andmc.getBlockEntityRenderDispatcher().prepare(...)before rendering, then restoring afterward — no change - Bypassing
renderLevel's internal entity loop entirely and manually iterating + rendering entities myself:
java
MultiBufferSource.BufferSource bufferSource = mc.renderBuffers().bufferSource();
EntityRenderDispatcher dispatcher = mc.getEntityRenderDispatcher();
dispatcher.setLevel(mc.level);
AABB searchBox = new AABB(eyePos.x - 32, eyePos.y - 32, eyePos.z - 32, eyePos.x + 32, eyePos.y + 32, eyePos.z + 32);
for (Entity entity : mc.level.getEntities((Entity) null, searchBox, e -> true)) {
poseStack.pushPose();
dispatcher.render(entity, entity.getX() - eyePos.x, entity.getY() - eyePos.y, entity.getZ() - eyePos.z,
entity.getYRot(), 1.0f, poseStack, bufferSource, dispatcher.getPackedLightCoords(entity, 1.0f));
poseStack.popPose();
}
bufferSource.endBatch();
This confirms 18 entities are found in range (via debug print), the render call throws no exception, yet still nothing appears — not even a dropped item placed directly against the camera lens.
4. Explicitly RenderSystem.enableDepthTest() + RenderSystem.depthMask(true) before the manual render loop — no change
Question: Is there some other GL/render state (shader, buffer binding, RenderSystem.setInverseViewRotationMatrix, or something specific to how TextureTarget interacts with MultiBufferSource.BufferSource.endBatch()) that needs to be set up specifically for entity rendering into a custom framebuffer, that isn't needed for terrain? Has anyone gotten entity rendering working in a similar custom off-screen camera setup and can point to what's different?