Hacking COLLADA to add reflectivity

Model with shininess (Phong shader)

If you export a COLLADA DAE model from SketchUp (using either the 3D Model Export feature in SketchUp or my Sketchfab plugin), then you will notice that any materials in the model (colors or textures) look flat (like you can see in the model shown in the web viewer below). Although shininess is not always appropriate, a slight amount of reflectivity can “dress up” such a model significantly.

Default model

The flat textures appear because SketchUp exports COLLADA files in a way that assigns a “Lambert” shader to all materials. This provides accurate texturing, color and transparency but no reflections. A better shading approach is actually written into the COLLADA specification (p. 8-84) and is readily available in many COLLADA viewers (including WebGL viewers like Sketchfab) – it’s a Phong shader. If we want any glossiness, that’s the one we want.

To add glossiness to an already exported COLLADA file, open it in a text editor and use find/replace or any other method you like to replace lines like these:

<lambert>
  <diffuse><color>1.0 0.0 0.0 1.0</color></diffuse>
</lambert>

with

<phong>
  <ambient><color>0.0 0.0 0.0 1.0</color></ambient>
  <specular><color>1.0 1.0 1.0 1.0</color></specular>
  <shininess><float>100.0</float></shininess>
  <reflective><color>1.0 1.0 1.0 1.0</color></reflective>
  <reflectivity><float>0.2</float></reflectivity>
  <diffuse><color>1.0 0.0 0.0 1.0</color></diffuse>
</phong>

Do this for every material that is defined in the file. Just change “lambert” to “phong” but leave the “diffuse” line alone. Then add the other lines. Feel free to modify the parameters to your liking.

  • Denis Bolomier

    Just Awsome !!!! THX Alex

  • Camilo

    How do you manage to put your 3D model on the web?, Is impressive