#[SOLVED] Rendering semi-transparent volumes

22 messages · Page 1 of 1 (latest)

brave vessel
#

I am trying to achieve an effect where every block (lets say crafting table) has a 3x3x3 volume around it marked in red, rendered on top of the environment. I was thinking of drawing all the boxes on a new render layer, then applying that layer after the main game with X% opacity. Issue is, i have no idea how to actually implement this as i am terrible at anything rendering-related
Im on 1.16.1 in case that matters
(artistic rendition of what im trying to achieve attached)

vague spoke
#

maybe you can render a big block when WorldRenderEvent.Last called(or use mixin)

#

the code may like" public void render(MatrixStack matrixStack){
RenderListener.saveLocation(this.blockPosition.toLocation());
ResourceLocation identifier = new ResourceLocation("examplemod", "textures/box.png");
ResourceLocation blackIdentifier = new ResourceLocation("examplemod", "textures/black.png");
TextureManager textureManager = Minecraft.getInstance().getTextureManager();
Texture blackTexture=textureManager.getTexture(blackIdentifier);
RenderSystem.disableBlend();

    GL20.glEnable(GL20.GL_POLYGON_OFFSET_FILL);
    GL20.glPolygonOffset(-1.0f,-1.0f);
    Tessellator tessellator = Tessellator.getInstance();
    BufferBuilder bufferBuilder = tessellator.getBuilder();
    Minecraft.getInstance().getTextureManager().bind(identifier);
    bufferBuilder.begin(7, DefaultVertexFormats.POSITION_TEX);
    for(BlockFacing normalFacing:BlockFacing.values()){
        Location location=getFacingBlockLocation(normalFacing);
        boolean hasBlock=RenderListener.hasBlock(location);
        if(hasBlock){
            continue;
        }
        vertexBlockFace(matrixStack,normalFacing);
    }
    tessellator.end();

    GL11.glDisable(GL11.GL_POLYGON_OFFSET_FILL);
    RenderSystem.enableDepthTest();
    RenderSystem.enableBlend();
}"
#

good luck

brave vessel
#

im currently using 1 to draw wireframes

#

but here you're using 7

#

in BufferBuilder#begin

#

it just seems like magic values

vague spoke
#

Yes

#

wait me 3 second

#

in 1.21,there is a class named "DrawMode",there is the code:" public static enum DrawMode {
LINES(4, 2, 2, false),
LINE_STRIP(5, 2, 1, true),
DEBUG_LINES(1, 2, 2, false),
DEBUG_LINE_STRIP(3, 2, 1, true),
TRIANGLES(4, 3, 3, false),
TRIANGLE_STRIP(5, 3, 1, true),
TRIANGLE_FAN(6, 3, 1, true),
QUADS(4, 4, 4, false);"

#

maybe the 7 means "QUADS"

brave vessel
#

alright

#

thats perfect

#

pretty much all i needed

#

im on 1.16.1 though so i guess im sticking to magic values

#

tysm

vague spoke
#

you can found more in "watermedia " or "cinemamod",I forget where i found the code

#

there are similar render function in the mod,when they rendering screen

brave vessel
#

solved using ```java
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL32.GL_SRC_ALPHA, GL32.GL_ONE_MINUS_SRC_ALPHA);

Tessellator tessellator = Tessellator.getInstance();
BufferBuilder buffer = tessellator.getBuffer();

buffer.begin(DRAW_MODE, VertexFormats.POSITION_COLOR);
for (FaceDir dir : FaceDir.values())
this.addFace(buffer, position, size, dir, color);

tessellator.draw();

RenderSystem.defaultBlendFunc();
RenderSystem.disableBlend();