Hello Panda3D :D.
I do have a question regarding 3d models, I have a model with no texture or material, I was able to add the texture in the code, but now I want to make it bump-mapping, and I didn’t know how. So in that case what should we do to add a bump mapping into a 3d model which has no texture mapping?
I’ve tried the following code, but it did not work:
from panda3d.core import Texture, TextureStage
# Load diffuse texture and create a TextureStage
diffuse_tex = loader.loadTexture('path/to/diffuse_texture.png')
diffuse_stage = TextureStage('diffuse-stage')
diffuse_stage.setMode(TextureStage.MModulate)
# Load normal texture and create a TextureStage
normal_tex = loader.loadTexture('path/to/normal_texture.png')
normal_stage = TextureStage('normal-stage')
normal_stage.setMode(TextureStage.MNormal)
# Create a GeomNode and apply textures
geom_node = my_model_node.find('**/+GeomNode')
if geom_node:
# Apply diffuse texture
geom_node.setTexGen(diffuse_stage, TexGenAttrib.MWorldPosition)
geom_node.setTexture(diffuse_stage, diffuse_tex)
# Apply normal texture
geom_node.setTexGen(normal_stage, TexGenAttrib.MWorldPosition)
geom_node.setTexture(normal_stage, normal_tex)
I think that the main thing that’s missing might simply be that in Panda, normal-mapping is provided via shaders. As a result, seeing the effect of your normal-map might call for either activating the automatic shader-generator, or applying a shader of your own that implements normal-mapping.
The former (the automatic shader-generator) is perhaps the simpler option. Presuming that you have no other shaders in effect, you should be able to apply the shader-generator by calling “setShaderAuto()” on either the NodePath that you want to have so shaded, or on a NodePath above it in the scene-graph (e.g. a “world” or “level” node, or even just “render”). Like so:
I think the problem is that in your model there are no tangents and binormals that are necessary to calculate the illumination of the relief, and also a light source is needed.