Quad culling problem

I’m having trouble trying to render a diagonal quad in my block world. I’m trying to implement minecraft like flowers but the sky keeps getting shown through the texture. I’m not sure if this is face culling going on or what. I think my texture coordinates are in the right order because I can see the flower. Also, it is being rendered in the transparent bucket.

See the screenshot below for what it looks like. I am just trying to get one face working right now and I have included the important part of the code.

Thanks!

package com.chappelle.jcraft.shapes;

import java.util.List;

import com.chappelle.jcraft.Block;
import com.chappelle.jcraft.BlockShape;
import com.chappelle.jcraft.BlockSkin_TextureLocation;
import com.chappelle.jcraft.Chunk;
import com.chappelle.jcraft.Vector3Int;
import com.jme3.math.Vector2f;
import com.jme3.math.Vector3f;

public class BlockShape_Flower extends BlockShape
{
@Override
public void addTo(Chunk chunk, Block block, Vector3Int blockLocation)
{
Vector3f blockLocation3f = new Vector3f(blockLocation.getX(), blockLocation.getY(), blockLocation.getZ());

    addFaceIndices(indices, positions.size());
    positions.add(blockLocation3f.add(new Vector3f(1, 0, 0)));
    positions.add(blockLocation3f.add(new Vector3f(0, 0, 1)));
    positions.add(blockLocation3f.add(new Vector3f(1, 1, 0)));
    positions.add(blockLocation3f.add(new Vector3f(0, 1, 1)));
    addSquareNormals(normals, -1, 0, -1);
    addTextureCoordinates(chunk, textureCoordinates, block.getSkin(chunk, blockLocation, Block.Face.Back).getTextureLocation());
    addLighting(chunk, blockLocation, Block.Face.Back);
}

private void addFaceIndices(List<Short> indices, int offset){
    indices.add((short) (offset + 2));
    indices.add((short) (offset + 0));
    indices.add((short) (offset + 1));
    indices.add((short) (offset + 1));
    indices.add((short) (offset + 3));
    indices.add((short) (offset + 2));
}

private void addSquareNormals(List<Float> normals, float normalX, float normalY, float normalZ){
    for(int i=0;i<4;i++){
        normals.add(normalX);
        normals.add(normalY);
        normals.add(normalZ);
    }
}

private void addTextureCoordinates(Chunk chunk, List<Vector2f> textureCoordinates, BlockSkin_TextureLocation textureLocation){
    textureCoordinates.add(getTextureCoordinates(chunk, textureLocation, 0, 0));
    textureCoordinates.add(getTextureCoordinates(chunk, textureLocation, 1, 0));
    textureCoordinates.add(getTextureCoordinates(chunk, textureLocation, 0, 1));
    textureCoordinates.add(getTextureCoordinates(chunk, textureLocation, 1, 1));
}

@Override
protected boolean canBeMerged(Block.Face face){
	return false;
}

}

Has it been three days alreay? Time really flies. (This question and variations get asked about every 3 days here.)

Well, I can tell a few things from your screen shot… the main one is that your ground is also in the transparent bucket. Which is bad as it makes everything harder and potentially less efficient to render.

Mostly, you need to set the alpha discard threshold on your flower material, though.

Edit for transparent sorting, alpha sorting, alpha sorting z buffer, stuff like that to learn more about why this happens. Or someone else can find my paragraph from three or four days ago that describes it. :slight_smile: I’ve written it a few times this month so want to take a break.

1 Like

I’m pretty sure the ground is not in the transparent bucket. I have other transparent blocks working like glass, ice and water. You can see the glass in the background of the screenshot.

Everything uses the same material so I can’t change material properties for the flower without affecting everything.

I’ll do some more research on the topic using some of the terms you mentioned. I “think” I understand the basics of what is going on but apparently I’m missing something.

You can’t do this with everything sharing the same material. Some things will have to use a different material.

Rendering order is your killer problem.

Well, if you never want partially transparent stuff then you can still set the alpha discard threshold. It will fix your visuals and let you move on to other things.

Wow. Alpha discard threshold fixed it. Although I need to learn about what that is before I move on. Not sure how that may affect performance.

Not sure how to have a different material for each one since I am generating a Mesh and the chunk is 2 geometries(transparent and opaque).

Thanks a bunch!

Well, if you already have two geometries then you can have two materials.

I just know without a doubt that in your screen shot the flower and the obscured thing were in the same bucket.

Ok you meant the transparent geometry can have the material with the alpha discard and the other without it. Yea I can do that easily.

I’ll check on the ground being in the same bucket. It seems like glass wouldn’t work if it was in the same bucket as grass.

You might get lucky. It just depends on which geometry is drawn first and fills the z-buffer. Alpha discard threshold prevents the z-buffer from being written to if alpha is below the threshold.