Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

[Solved][1.14.4] TileEntityRenderer: Manual block rendering w/ ambient occlusion?

Featured Replies

Posted

I've got a TER with a variety of animations and OpenGL effects, and one of its properties is to render an arbitrary block on top of it. This is quite easy to do with BlockRendererDispatcher#renderModelBrightness, but the caveat is that it doesn't render with ambient occlusion. Looks great with flat lighting, but sticks out like a sore thumb with smooth lighting.

I've tried using BlockRendererDispatcher#renderModelSmooth, but it then seemingly ignores lighting altogether. I've never been great with rendering code, so here's the relevant excerpt of that in case I just forgot something:

BlockPos pos = tileEntityIn.getPos();
buffer.begin(GL11.GL_QUADS, DefaultVertexFormats.BLOCK);
buffer.setTranslation(-pos.getX(), -pos.getY(), -pos.getZ() - 1);
renderer.getBlockModelRenderer().renderModelSmooth(world, model, state, pos, buffer, true, new Random(), 0, EmptyModelData.INSTANCE);
buffer.setTranslation(0, 0, 0);
tessellator.draw();

I'm probably going about this all wrong. I'd appreciate some pointers!

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

Howdy

I think you're heading in the right direction, the renderModelSmooth is the one that you want; some suggestions

1) pick an existing vanilla RenderBuffer instead of making your own, eg

    IVertexBuilder vertexBuilderBlockQuads = renderBuffer.getBuffer(RenderType.getSolid());

 

Ah wait - you're using 1.14.4.  The principle is the same but you may have used the right buffer modes already.

There are a couple of settings that will stop vanilla applying lighting properly- depends on the source of your model - 

if the Quads in your model have diffuse lighting false, then the direction-depending lighting won't be applied.

if the block is opaque, the light value might be set to zero for quads which aren't at the outermost edges of the block

if the block is glowing, ambient occlusion is turned off

You might just need to trace into the render method to see exactly what is going on - the ambient occlusion & brightness methods are complicated but it's not too difficult to see what they are doing / why there's no lighting being applied at all.

 

This link might be useful for background information

http://greyminecraftcoder.blogspot.com/2020/04/lighting-1144.html

 

Cheers

  TGG

 

  • Author

@TheGreyGhost

Thank you for the tips! I spent a while digging into the lighting code but didn't manage to find anything wrong. Instead, the problem was quite simple and I feel pretty silly for not noticing. The TileEntityRendererDispatcher calls RenderHelper.enableStandardItemLighting before rendering tile entities, so I simply had to call the reverse before rendering the block model and it worked flawlessly.

Also, I changed my code to use BlockRendererDispatcher#renderBlock instead of renderModelSmooth for the sake of accuracy to vanilla, in case anyone cares.

Edited by imacatlolol

I'm eager to learn and am prone to mistakes. Don't hesitate to tell me how I can improve.

  • imacatlolol changed the title to [Solved][1.14.4] TileEntityRenderer: Manual block rendering w/ ambient occlusion?

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

By using this site, you agree to our Terms of Use.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.