Displaying material colors correctly without textures using Assimp

I can’t get assimp to display material colors correctly with oF. I believe it has something to do with the lighting. I’m using the default Assimp Example on OS X 10.6. I have been able to get it to correctly render using an example from the Assimp library (outside oF) - see first image.

So I need help with how to get the megaphone to display correctly in blue. I’m very close, but the materials are showing up as transparent. glDisable(GL_CULL_FACE) is called with this model as it isn’t detected as two sided.

Here is the model I’m working with: megaphone.x, but I have issues with other DAE and 3DS that just have material colors

Rendered using the Assimp library outside of oF (supposed to look like this):

[table]
[tr]
[td]light.enabled() completely washes out the color when specified as the first model to load
[/td]
[td] [/td]
[td]This is strange - if I start with the default assimp example and run astroBoy first and then load the megaphone during runtime, the model just comes out white.

[/td]
[/tr]
[/table]

light disabled, but GL lighting used (see code below). this is the closest i’ve gotten to displaying this correctly, but the surfaces are transparent

  
  
    glEnable(GL_DEPTH_TEST);   //shows completely dark without this  
  
    glEnable(GL_LIGHTING);  // disappears without this  
      
    GLfloat global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };  
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);  
  
    GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);  
  
    GLfloat diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);  
  
    GLfloat ambient[] = {0.2, 0.2f, 0.2f, 0.2f};  
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);  
  
    GLfloat position[] = { 0.5f, 0.5f, 0.5f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_POSITION, position);  
  
    glEnable(GL_LIGHT0);  
  
    // light.enabled();  

1 Like

I’ve found a solution that is so far giving me the most compatibility with the models I’ve tested. Models look good with or without textures now.

I used OpenGL Profiler on the Mac to determine what OpenGL calls were being made between my working sample and openFrameworks rendering incorrectly.

In setup(): enabled depth test, created my own lighting and didn’t set any blending:

  
  
    glEnable(GL_DEPTH_TEST);  
  
    glEnable(GL_LIGHTING);  
      
    GLfloat global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };  
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);  
      
    GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);  
      
    GLfloat diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);  
      
    GLfloat ambient[] = {0.2, 0.2f, 0.2f, 0.2f};  
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);  
      
    GLfloat position[] = { 0.5f, 0.5f, 0.5f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_POSITION, position);  
      
    glEnable(GL_LIGHT0);     
      
    //some model / light stuff  
    glShadeModel(GL_SMOOTH);  
//  light.enable();  
    ofEnableSeparateSpecularLight();  

In ofxAssimpModelLoader.cpp ignore any culling setup and blend modes

  
// Culling  
//if(meshHelper.twoSided)  
//    glEnable(GL_CULL_FACE);  
//else  
//    glDisable(GL_CULL_FACE);  
  
//ofEnableBlendMode(meshHelper.blendMode);  

Excellent! This fixed the problem. Thank you for sharing.

this looks promising!

but still things are pretty messed up here. I used your and only your lighting functions and commented out the culling.

drawing the model via model.drawfaces();

still this is how it appears in finder/preview:

and this on the device using assimpModel

any ideas? the strange thing is that the “inside” seems to look good. but could also be the fact, that if you see the inside there is nothing overlapping, if you know what i mean…
or is it a normal issue?

here’s the full code

  
void testApp::setup(){  
  
    model.loadModel("cala24_2.dae");  
  
    glEnable(GL_DEPTH_TEST);  
      
    glEnable(GL_LIGHTING);  
      
    GLfloat global_ambient[] = { 0.5f, 0.5f, 0.5f, 1.0f };  
    glLightModelfv(GL_LIGHT_MODEL_AMBIENT, global_ambient);  
      
    GLfloat specular[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_SPECULAR, specular);  
      
    GLfloat diffuse[] = {1.0f, 1.0f, 1.0f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_DIFFUSE, diffuse);  
      
    GLfloat ambient[] = {0.2, 0.2f, 0.2f, 0.2f};  
    glLightfv(GL_LIGHT0, GL_AMBIENT, ambient);  
      
    GLfloat position[] = { 0.5f, 0.5f, 0.5f, 1.0f};  
    glLightfv(GL_LIGHT0, GL_POSITION, position);  
      
    glEnable(GL_LIGHT0);  
      
    //some model / light stuff  
    glShadeModel(GL_SMOOTH);  
    //  light.enable();  
    ofEnableSeparateSpecularLight();      
}  
  
void testApp::draw(){  
  
    ofBackground(ofColor(200));  
      
    ofTranslate(ofGetWidth()/2, ofGetHeight()/2);  
    ofTranslate(0,-100);  
     
    model.drawFaces();  
  
}  
  

I’m using oF 0.8.0 and I’ve found that I can get the default light to work with non-texture materials in the assimp example by simply adding glDisable(GL_COLOR_MATERIAL); after light.enable(). It seems that for whatever reason ofEnableLighting() calls glEnable(GL_COLOR_MATERIAL) which means that the ambient and diffuse colors are mapped to the current color and not the material color.

1 Like