1

I draw a plane with a texture in libgdx, and it disappears when you look at it from the other side. Is there any way to make double-sided shader?

    private Model createPlaneModel(final float width, final float height, final Material material,
                                   final float u1, final float v1, final float u2, final float v2) {

        modelBuilder.begin();
        MeshPartBuilder bPartBuilder = modelBuilder.part("rect",
                GL20.GL_TRIANGLES, VertexAttributes.Usage.Position |
                VertexAttributes.Usage.Normal |
                VertexAttributes.Usage.TextureCoordinates,
                material);
        //NOTE ON TEXTURE REGION, MAY FILL OTHER REGIONS, USE GET region.getU() and so on
        //bPartBuilder.setUVRange(u1, v1, u2, v2);
        bPartBuilder.rect(
                -(width*0.5f), -(height*0.5f), 0,
                (width*0.5f), -(height*0.5f), 0,
                (width*0.5f), (height*0.5f), 0,
                -(width*0.5f), (height*0.5f), 0,
                1, 1, 1);


        return (modelBuilder.end());
    }
Community
  • 1
  • 1
lucidyan
  • 3,575
  • 2
  • 22
  • 24

1 Answers1

2

EDIT: I have read your question again and you said you want to render the same face from both sides. This is done by disableing backFaceCulling, like i wrote at the end of the post. Anyways i would not do that, because:

  1. Backface culling gives a performance boost, as faces are normaly not visible from there backside
  2. Every Face should have different normals, the normals for a frontface point to +z (for example) and the one for the backface to -z.

Also i want to tell you, that the normals you have set in the example code are not correct. The Normals are perpendicular to the face. This tutorial should show you the basics of normals and vectors.

Original Post

Look at this question.
As i am the asker of both questions (the one you linked and the one i linked) i know your problem.
The rect() method you use takes 15 parameters:

  1. 1-3 are x,y,z value of the left lower corner
  2. 4-6 are x,y,z value of the left upper corner
  3. 7-9 are x,y,z value of the right upper corner
  4. 10-12 are x,y,z value of right lower corner
  5. 13-15 are the x,y,z normals of the rect.

The face expects, that you give the corners, as you are looking at it directly. If you are using the wrong order, the face "expects" you are looking from the other side (the right lower corner is the left lower corner if you are looking from behing :P).
As backFaceCulling is enabled you won't see the face, as it expects you are at its backsite, which should never be visible to you (On the other side there should be another face, as it has other normals to).
I hope this is clear for you. Anyways to have the rect visible from both sides you have to disable backFaceCulling. I think you have to disable it you should add the IntAttribute.CullFace to the Material.

Community
  • 1
  • 1
Robert P
  • 9,398
  • 10
  • 58
  • 100