Laipel Posted August 8, 2023 Posted August 8, 2023 (edited) I want to render my Entity like ExpOrb. There RenderType is used. However, I don't need to interract with light, therfore I don't need to specify normals, lightmap and other thinhs like it. I've decided to use RenderSystem.setShaderTexture(int, ResourceLocation) for this purpose. But it doesn't work. Code below just render some quads. @Override public void render(SoulEntity soulEntity, float p_114486_, float pTicks, PoseStack poseStack, MultiBufferSource bufferSource, int p_114490_) { ISoul soul = soulEntity.getSoul(); if(soul == null) return; RenderSystem.depthMask(false); RenderSystem.enableBlend(); RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); RenderSystem.setShader(GameRenderer::getPositionColorShader); RenderSystem.setShaderTexture(0, getTextureLocation(soulEntity)); Tesselator t = RenderSystem.renderThreadTesselator(); poseStack.pushPose(); poseStack.scale(0.6f, 0.6f, 0.6f); poseStack.mulPose(this.entityRenderDispatcher.cameraOrientation()); poseStack.mulPose(Axis.YP.rotationDegrees(180.0F)); Color color = soul.getColor(); Matrix4f matrix4f = poseStack.last().pose(); BufferBuilder bufferBuilder = t.getBuilder(); bufferBuilder.clear(); bufferBuilder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.POSITION_COLOR_TEX); bufferBuilder.vertex(matrix4f, -1.2f, -1.2f, 0.0F).color(color.getRed(), color.getBlue(), color.getGreen(), 90).uv(16, 16).endVertex(); bufferBuilder.vertex(matrix4f, 1.2f, -1.2f, 0.0F).color(color.getRed(), color.getBlue(), color.getGreen(), 90).uv(0, 16).endVertex(); bufferBuilder.vertex(matrix4f, 1.2f, 1.2f, 0.0F).color(color.getRed(), color.getBlue(), color.getGreen(), 90).uv(0, 0).endVertex(); bufferBuilder.vertex(matrix4f, -1.2f, 1.2f, 0.0F).color(color.getRed(), color.getBlue(), color.getGreen(), 90).uv(16, 0).endVertex(); bufferBuilder.vertex(matrix4f, (float) (0f - 0.6), (float) (0.0f - 0.6), 0.0F).color(color.getRed(), color.getBlue(), color.getGreen(), 100).uv(1, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.4f, 0.0f - 0.6f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 100).uv(0, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.4f, 1.0f - 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 100).uv(0, 0).endVertex(); bufferBuilder.vertex(matrix4f, 0f - 0.6f, 1.0f - 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 100).uv(1, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.13f, (0.0f - 0.5f) + 0.13f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 120).uv(1, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.5f - 0.13f, (0.0f - 0.5f) + 0.13f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 120).uv(0, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.5f - 0.13f, 1.0f - 0.5f - 0.13f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 120).uv(0, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.13f, 1.0f - 0.5f - 0.13f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 120).uv(1, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.26f, (0.0f - 0.5f) + 0.26f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 130).uv(1, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.5f - 0.26f, (0.0f - 0.5f) + 0.26f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 130).uv(0, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.5f - 0.26f, 1.0f - 0.5f - 0.26f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 130).uv(0, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.26f, 1.0f - 0.5f - 0.26f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 130).uv(1, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.4f, (0.0f - 0.5f) + 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 140).uv(1, 1).endVertex(); bufferBuilder.vertex(matrix4f, 1f - 0.5f - 0.4f, (0.0f - 0.5f) + 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 140).uv(0, 1).endVertex(); bufferBuilder.vertex(matrix4f,1f - 0.5f - 0.4f, 1.0f - 0.5f - 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 140).uv(0, 0).endVertex(); bufferBuilder.vertex(matrix4f, (0f - 0.5f) + 0.4f, 1.0f - 0.5f - 0.4f, 0.0f).color(color.getRed(), color.getBlue(), color.getGreen(), 140).uv(1, 0).endVertex(); t.end(); RenderSystem.disableBlend(); RenderSystem.depthMask(true); poseStack.popPose(); super.render(soulEntity, p_114486_, pTicks, poseStack, bufferSource, p_114490_); } What do I need to do to bind texture? Edited August 8, 2023 by Laipel Quote
warjort Posted August 8, 2023 Posted August 8, 2023 (edited) That's not how it works. The RenderSystem calls you are using are for direct drawing, e.g. when drawing in the UI or when minecraft itself wants to send the completed buffers to the graphics card. You should be drawing by adding vertices to the shared buffers from the MultiBufferSource based on the RenderType you want to use and let minecraft do the rest. The textures are normally setup as the uv/uv2 coords for the relevant texture atlas during model loading, but you can select a particular texture using a RenderType if you are manually creating vertices. e.g. see how the ArrowRenderer class changes the texture (selects the buffer) using the entityCutout RenderType. Or itemEntityTranslucentCull is what the xp orb uses. See ExperienceOrbRenderer. What should really be happening is (pseudo code): // You do VertextConsumer consumer = multiBufferSource.getBuffer(RenderType.itemEntityTranslucentCull(textureName)); consumer.addVertices(color, normals, etc.); // Other people do the same things to fill the buffers //Then at the end minecraft sends all the buffers doing those direct draw render state changes pnly once for each buffer/render type for (buffer : multiBufferSource) { RenderType renderType = buffer.getRenderType() RenderSystem.setupState(renderType); e.g. blendnig, depth test, textures etc. buffer.updloadToGraphicsCard(); RenderSystem.resetState(); } For the real code see RenderType/RenderStateShard/TextureStateShard With your original code you are trying to drawi every entity directly which is very slow for lots of entities - e.g. continuous graphic card state changes. With the buffered code, you just accumulate vertices in the relevant buffer and then all of them are sent at the end using a single common state change and render call Edited August 8, 2023 by warjort Quote Boilerplate: If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one. If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install Large files should be posted to a file sharing site like https://gist.github.com You should also read the support forum sticky post.
Recommended Posts
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.