Getting black objects from vertex.setFill()

edited August 2015 in GLSL / Shaders

I'm trying to color 3D PShape. if I perform vertex.setEmissive(color) on each vertex this does color the object as expected but this is simply emissive color unaffected by the scene lighting. if instead I try to use .setFill() or .setTint() or .setAmbient() on each vertex I get a completely black and opaque object. if I don't do anything at all then the object has a white or gray fill that does respond to the scene lighting.

I don't understand what I'm doing wrong. How do I assign a color to each vertex in a PShape???

DETAILS: I read in a .obj file which creates a PShape object that is simple a list of GROUPs in which each group contains 3 verticies (a triangular face).

I then iterate over this list of lists setting the color of each vertex with the outcome described above.

My thinking is that I must not understand what setFill or setTint or setAmbient do. I'd like to know. But I'd also like to know how to do what I want which is to paint the faces.

here's a code snippet that I'm using:

        sts = p.loadShape("stshuttle.obj");
        sts.rotateZ(p.PI/2);
        sts.rotateY(-p.PI/2);

                    // loop over the list of GROUP PShapes
        // set odd faces red and even faces yellow

        for (int i =0; i<sts.getChildCount();i++){  

            PShape foo = sts.getChild(i);
            int colr2 = (0==i%2)? 0xFF1000 : 0xFFFF00;

                           // loop over all three of the verticies in the GROUP.
            for (int j = 0; j<foo.getVertexCount();j++) {
                     foo.setFill(j,colr2);   // This turns it black 
            //  foo.setEmissive(j,colr2);  //  works as expected
                            //      foo.setTint(j,colr2)   // this turns it black.

            }

        }

Answers

  • this remains a mystery to me

  • edited September 2015 Answer ✓

    At first glance 0xFF1000 and 0xFFFF00 are color values without any alpha information, thus fully transparent. While the setEmissive() function doesn't care about the alpha value, setFill() and setTint() do.

    Use either Processing's color notation (will automatically add an opaque alpha channel):

    int colr2 = 0 == i % 2 ? #FF1000 : #FFFF00;
    

    Or add the alpha channel yourself:

    int colr2 = 0 == i % 2 ? 0xFFFF1000 : 0xFFFFFF00;
    
  • Thanks! I'll try this. By the way, by what means should I have learned this fact. I've not see what you just told me documented. I didn't pick it up from the javadocs page for processing. So I must be missing some source of documentation.

  • Answer ✓

    No problem. Processing has a dedicated page about color: https://processing.org/reference/color_datatype.html

  • thanks again!

Sign In or Register to comment.