Jump to content

[1.15.2] Custom rendering interact with lighting


CookieLukas

Recommended Posts

The following code just sets a small rendered plane with the texture of "polished_andesite" at the coordinates 0|60|0
But even in complete darkness, the plane still "glows". How can I get the plane to interact with the local light level?
Im using the following options:

public static final RenderType OVERLAY_PLATE = makeType("overlay_plate",
            DefaultVertexFormats.POSITION_TEX, GL11.GL_QUADS, 256,
            RenderType.State.getBuilder()
                    .layer(PROJECTION_LAYERING)
                    .transparency(TRANSLUCENT_TRANSPARENCY)
                    .texture(new TextureState(new ResourceLocation("minecraft:textures/block/polished_andesite.png"), false, false))
                    .depthTest(DEPTH_ALWAYS)
                    .cull(CULL_DISABLED)
                    .lightmap(LIGHTMAP_DISABLED)
                    .writeMask(COLOR_WRITE)
                    .build(true));

And the following code to render:

	@SubscribeEvent
    public void render(RenderWorldLastEvent event) {
		
		 IRenderTypeBuffer.Impl bufferSource = Minecraft.getInstance().getRenderTypeBuffers().getBufferSource();
	     IVertexBuilder builder = bufferSource.getBuffer(ModRenderTypes.OVERLAY_PLATE);
		 Vec3d view = Minecraft.getInstance().gameRenderer.getActiveRenderInfo().getProjectedView();
		 
		 int x = 0;
		 int y = 60;
		 int z = 0;
		 
		 MatrixStack stack = event.getMatrixStack();
	     stack.push();
	     stack.translate(-view.x, -view.y, -view.z);
		
	     Matrix4f lastStack = stack.getLast().getMatrix();
	     
	     builder.pos(lastStack, x, y + 1.0f, z + 1.0f).tex(0, 1).endVertex();
	     builder.pos(lastStack, x + 1.0f, y + 1.0f, z + 1.0f).tex(1, 1).lightmap(0, 240).endVertex();
	     builder.pos(lastStack, x + 1.0f, y + 1.0f, z).tex(1, 0).lightmap(0, 240).endVertex();
	     builder.pos(lastStack, x, y + 1.0f, z).tex(0, 0).lightmap(0, 240).endVertex();
		 stack.pop();
	     bufferSource.finish(ModRenderTypes.OVERLAY_PLATE);
	     
	}



My idea was to copy some code out of the BlockRendererDispatcher and use it every tick with the measured light level. Is that a possible?
Any help is appreciated,

-Lukas

2021-01-19 16_48_55-Minecraft_ 1.15.2 - Singleplayer.png

Link to comment
Share on other sites

6 hours ago, ChampionAsh5357 said:

Well, it might help if you enable the lightmap associated with the block. Also, why not render a block using BlockRendererDispatcher? Finally, why do you even need to render a custom version of a block?

OK, thats a good idea, Ive managed to do that, now I have two problems:
1)The Lighting, the "blockRenderer.renderBlock" requires a field called "combinedLighting", Ive found the method "mc.worldRenderer.getCombinedLight()"  it requires the a "BlockPos", and a "ILightReader", how can I get the current ILightReader instance?

2) The block is "wobbling" because now I only translate with "stack.translate(0, 60, 1);" what can I do against that? Before, I was translating with:

Vec3d view = mc.gameRenderer.getActiveRenderInfo().getProjectedView();
stack.translate(-view.x, -view.y, -view.z);

 

Link to comment
Share on other sites

6 hours ago, CookieLukas said:

how can I get the current ILightReader instance?

You can look at what implements the interface. You can also infer which classes might need to know the light value (for example, the world).

6 hours ago, CookieLukas said:

2) The block is "wobbling" because now I only translate with "stack.translate(0, 60, 1);" what can I do against that? Before, I was translating with:

To be able to statically project an object, you need to take the position and subtract it from the projected view.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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