Jump to content

[1.14.4] TESR Selective Rectanle texturing


Simon_kungen

Recommended Posts

Hi

 

As seen from this video the applied texture (coloured walls) is on both sides, I don't want that.

How would I go about making so the texture is only on the outer side? My idea was to give the "plates" depth by adding a second plate on the inside too but reversed, so I only need to texture two of the four sides of a plate (make it slightly more efficient). Later I also plan on making the plates transparent at times such as when holding a tool, and if I have all sides textured it would end up looking wonky with double layers both being transparent.

 

tesr1.gif

 

Current code (for rendering South plate):

TextureAtlasSprite sprite = Minecraft.getInstance().getTextureMap().getAtlasSprite(texture);
float u1 = sprite.getMinU(), v1 = sprite.getMinV(), u2 = sprite.getMaxU(), v2 = sprite.getMaxV();


combined = getWorld().getCombinedLight(te.getPos().south(),0);
lma = combined >> 16 & 65535;
lmb = combined  & 65535;

buffer.pos(min,min,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u2,v1).lightmap(lma,lmb).endVertex();
buffer.pos(min,max,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u2,v2).lightmap(lma,lmb).endVertex();
buffer.pos(max,max,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u1,v2).lightmap(lma,lmb).endVertex();
buffer.pos(max,min,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u1,v1).lightmap(lma,lmb).endVertex();

 

Link to comment
Share on other sites

My initial thought was to look at how the End Portal was rendered because it is invisible from the bottom, but that only confused me more.

In EndPortalTileEntityRenderer.java it has a bunch of if statements for the different directions which is compared to a final variable in EndPortalTileEntity.java for Direction.UP:

EndPortalTileEntity.java

...
   @OnlyIn(Dist.CLIENT)
   public boolean shouldRenderFace(Direction face) {
      return face == Direction.UP;
   }

 

EndPortalTileEntityRenderer.java

...
         if (tileEntityIn.shouldRenderFace(Direction.SOUTH)) {
            bufferbuilder.pos(x, y, z + 1.0D).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x + 1.0D, y, z + 1.0D).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x + 1.0D, y + 1.0D, z + 1.0D).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x, y + 1.0D, z + 1.0D).color(f3, f4, f5, 1.0F).endVertex();
         }

         if (tileEntityIn.shouldRenderFace(Direction.NORTH)) {
            bufferbuilder.pos(x, y + 1.0D, z).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x + 1.0D, y + 1.0D, z).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x + 1.0D, y, z).color(f3, f4, f5, 1.0F).endVertex();
            bufferbuilder.pos(x, y, z).color(f3, f4, f5, 1.0F).endVertex();
         }
...

 

When doing the same it just stops it from rendering altogether for that plate, so I have no idea what's going on here.

 

The only difference is that I use a numerical value contrary to an object in a switch statement:

 

CableCaseTileEntityRenderer.java

private void renderPlate(T te, byte plate, String texture, BufferBuilder buffer)
{
    TextureAtlasSprite sprite = Minecraft.getInstance().getTextureMap().getAtlasSprite(texture);
    float u1 = sprite.getMinU(), v1 = sprite.getMinV(), u2 = sprite.getMaxU(), v2 = sprite.getMaxV();

    final float[] c = te.getPlate(plate) instanceof ItemElement ? UtilBlocks.toFractal(Util.hex2rgb(((ItemElement) te.getPlate(plate)).getTint()),255) : new float[] {1,1,1};

    int combined, lma, lmb;
    switch (plate) {
        case 3: // South
            combined = getWorld().getCombinedLight(te.getPos().south(),0);
            lma = combined >> 16 & 65535;
            lmb = combined  & 65535;

            buffer.pos(min,min,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u2,v1).lightmap(lma,lmb).endVertex();
            buffer.pos(min,max,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u2,v2).lightmap(lma,lmb).endVertex();
            buffer.pos(max,max,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u1,v2).lightmap(lma,lmb).endVertex();
            buffer.pos(max,min,maxZ).color(c[0],c[1],c[2],ALPHA).tex(u1,v1).lightmap(lma,lmb).endVertex();

            break;
        case 0: // West
            combined = getWorld().getCombinedLight(te.getPos().west(),0);
            lma = combined >> 16 & 65535;
            lmb = combined  & 65535;

            buffer.pos(minZ,min,min).color(c[0],c[1],c[2],ALPHA).tex(u2,v1).lightmap(lma,lmb).endVertex();
            buffer.pos(minZ,max,min).color(c[0],c[1],c[2],ALPHA).tex(u2,v2).lightmap(lma,lmb).endVertex();
            buffer.pos(minZ,max,max).color(c[0],c[1],c[2],ALPHA).tex(u1,v2).lightmap(lma,lmb).endVertex();
            buffer.pos(minZ,min,max).color(c[0],c[1],c[2],ALPHA).tex(u1,v1).lightmap(lma,lmb).endVertex();
...

 

Link to comment
Share on other sites

Hi

 

The difference is in the VertexBuffer (IVertexBuilder) that you're using to render.

 

You can make faces only render on one side if you have back face culling turned on.  Some of the render modes use back face culling, the others don't .  Normal solid blocks, using RenderType.SOLID, have faces which are invisible from the back.

 

For example the difference between this

public static RenderType getEntitySolid(ResourceLocation p_228634_0_) {
  RenderType.State lvt_1_1_ = RenderType.State.getBuilder().texture(new TextureState(p_228634_0_, false, false)).transparency(NO_TRANSPARENCY).diffuseLighting(DIFFUSE_LIGHTING_ENABLED).lightmap(LIGHTMAP_ENABLED).overlay(OVERLAY_ENABLED).build(true);
  return makeType("entity_solid", DefaultVertexFormats.ENTITY, 7, 256, true, false, lvt_1_1_);
}

 

and this

  public static RenderType func_230167_a_(ResourceLocation p_230167_0_, boolean p_230167_1_) {
    RenderType.State lvt_2_1_ = RenderType.State.getBuilder().texture(new TextureState(p_230167_0_, false, false)).transparency(NO_TRANSPARENCY).diffuseLighting(DIFFUSE_LIGHTING_ENABLED).alpha(DEFAULT_ALPHA).cull(CULL_DISABLED).lightmap(LIGHTMAP_ENABLED).overlay(OVERLAY_ENABLED).build(p_230167_1_);
    return makeType("entity_cutout_no_cull", DefaultVertexFormats.ENTITY, 7, 256, true, false, lvt_2_1_);
  }

 

--> .cull(CULL_DISABLE)

 

If you're not familiar with backface culling it's probably worthwhile spending some time to learn a bit about OpenGL, this guide is not too bad to explain the basic concepts of rendering, worth a skim read for key concepts/keywords

https://www.glprogramming.com/red/

 

If you're worried about the back faces for efficiency reasons, I wouldn't bother.  Quad rendering is extremely quick.

 

Cheers

  TGG

  • Like 1
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.



×
×
  • Create New...

Important Information

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