Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

How do I enable colours (and other features) of the materials?

Looking at the code for the standard material, I see lots of lines like:

#ifdef USE_COLOR

These, for example, seem to control whether or not the per-vertex colour data is used.

Can I enable these directly from my Codea code? Or do I need to make a copy of the material and modify it?


  • Posts: 509

    Okay, figured it out -- or rather, I've figured out what I was doing wrong. I was trying to set colours using:

    pt.model.colors[k] = color(255)

    but the pt.model.colors table is read-only. To set colours (and other attributes) you have to use:


    and then it all works.

  • JohnJohn Admin Mod
    Posts: 643

    Hi @LoopSpace

    Glad you figured it out. Within the shader language #ifdef is a pre-processor directive used to conditionally compile certain parts. The standard shader is really complicated so that it can support a lot of different options (like having a number of optional texture channels and lighting).

    These are driven by options in materials, which you can turn on and off by using material:setOption(name, true/false). I wouldn't recommend playing with them unless you know what you are doing. The USE_COLOR option is automatically set by the renderer when a mesh has a valid set of colors defined. Default meshes have colors all set to white, but it's possible to have different attributes defined.

    At some point if I get time I'd like to make custom materials easy to define in the editor / code.

Sign In or Register to comment.