Render the backface differently from front?

itgiawaitgiawa Posts: 99Member
edited July 2021 in Shaders

I've got a cuboid. I discarded the pixels in the top half of the cube and disabled backface culling so you can see inside. I'd like to change the inside faces to be a different color from the outside faces. Is that possible?

I attempted to use the NORMAL to determine if a face is on the inside vs outside of the cube.

    if (length(NORMAL - normalize(vec3(-1, -1, 0))) < 0.5)
    {   // RED
        ALBEDO = vec3(1, 0, 0);
    }
    else if (length(NORMAL - normalize(vec3(1, -1, 1))) < 0.5)
    {   // GREEN
        ALBEDO = vec3(1, 1, 0);
    }

but unfortunately as you can see from the picture the inside and outside appear to have the same NORMAL because we have two green faces and two red faces. Ideally I only want the left green face and upper red face (since those are inside the cube).

Is there anyway I can detect the inside faces using a shader?

Also TwistedTwig if you see this, thanks for the help before.

Comments

  • TwistedTwiglegTwistedTwigleg Posts: 5,251Admin

    @itgiawa said:
    I've got a cuboid. I discarded the pixels in the top half of the cube and disabled backface culling so you can see inside. I'd like to change the inside faces to be a different color from the outside faces. Is that possible?

    I believe you can check if a face/pixel is front facing using the FRONT_FACING boolean passed-in to the fragment shader (variable description). I think checking to see if it's false should tell you if the face is an inside face.

    Also TwistedTwig if you see this, thanks for the help before.

    No problem, happy to help :smiley:

Leave a Comment

BoldItalicStrikethroughOrdered listUnordered list
Emoji
Image
Align leftAlign centerAlign rightToggle HTML viewToggle full pageToggle lights
Drop image/file