[GeeXLab] A Simple Way to Show Your Blender Models in Real Time 3D
In this article, I explain how to show in real time 3D with GeeXLab a model you’ve made in Blender. Blender game engine allows you to create such an object viewer. But I propose you another way to create a simple object viewer.
First, the Windows demo is available here:
You need a valid Python 2.6.2 or 2.6.3 installation to run the demo. Unzip the demo archive somewhere and Start_Demo_Speculars.bat. The MSAA (anti-aliasing) is set to 4X.
I used a 3D model made by Satyr (with Blender 2.49b). This model has been exported in OBJ format. Blender OBJ exporter does a good job: it can export vertices normals (fundamental for nice lighting) and can create a material file. See the end of this tutorial to know how to export a model in OBJ format.
This model is cool because it uses only one baked texture:
The real size of this texture is 4096×4096. A baked texture is a texture that contains object color and lighting calulations such as shadows or ambient occlusion. How can we do baking with Blender? Honestly I don’t know yet but I know that Satyr is preparing a cool tutorial on this subject. So stay tuned, it will be published soon 😉
Models with baked textures look real. But it’s static. Here is a simple trick to improve a little bit the scene realism: normal maps:
Thanks to normal maps we’ll be able to add a touch of dynamic lighting. But it’s out of question to do all lighting calculations. We’ll focuse only on specular part of the lighting equation. In the following screenshot, we easly see the specular highlights on the base:
The complete source code is in the Blender_OBJ_Demo_Lighting.xml file. And the core of the demo is this piece of code:
<model name="myModel" filename="data/VaseEtTabouret.obj" > <position x="0.0" y="0.0" z="0.0" /> <scale x="5.0" y="5.0" z="5.0" /> <loading_option load_texture="TRUE" compute_vertices_normals="FALSE" compute_tangent_space_vectors="TRUE" /> </model>
The OBJ file contains vertices normals then you must tell GeeXLab to not compute them again. This is the purpose of the line compute_vertices_normals=”FALSE”. The line compute_tangent_space_vectors=”TRUE” allows to compute vectors for bump mapping.
The other important part of the source code is how attaching a specular bump mapping shader (GLSL) to the model materials (the model has 3 materials). This is done with the following lines:
<texture name="bumpMap" filename="data/AllInOne_NM_4k.jpg" /> <material name="Vase_mat_AllInOneMap.png" shader_program="BumpMappingShader" > <specular r="0.7" g="0.7" b="0.7" a="1.0" exp="20.0" /> <add_texture name="bumpMap" /> </material> <material name="Tabouret_mat_AllInOneMap.png" shader_program="BumpMappingShader" > <specular r="0.3" g="0.3" b="0.2" a="1.0" exp="90.0" /> <add_texture name="bumpMap" / </material>
AllInOne_NM_4k.jpg is the normal map (a 4096×4096 normal map). Vase_mat_AllInOneMap.png, Vase_mat_AllInOneMap.png and Tabouret_mat_AllInOneMap.png are three materials defined in the OBJ material file. BumpMappingShader is the GLSL shader that performs specular bump mapping. The source code of the shader is also in the demo. Each material has already the color map (file AllInOneMap_4k.jpg) in the texture unit 0. The color map has been loaded during the loading of the model. The line
<add_texture name="bumpMap" />
allows to add the normal map and attach it to material next texture unit, the texture unit 1.
That’s all. I think you have now the important elements to make an object viewer with GeeXLab. And if you want more fun, you can add some post processing effects (more effects soon available…).
- GeeXLab: Laboratory for Real Time 3D Learning and Experiments
- [Shader Library] Night Vision Post Processing Filter (GLSL)