from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, Vec4, Vec3, TextureStage
import simplepbr
class MyApp(ShowBase):
def __init__(self):
# Initialize the base class (ShowBase)
ShowBase.__init__(self)
# Initialize simplepbr with shadows and normal maps enabled
simplepbr.init(enable_shadows=True, use_normal_maps=True)
# Set up the scene
self.set_background_color(0.1, 0.1, 0.2, 1) # Dark blue-gray background
# Create a simple ground plane
ground = self.loader.loadModel("models/box")
ground.set_scale(20, 20, 0.1) # Flat and wide
ground.set_pos(0, 0, -0.05) # Slightly below origin
ground.set_color(0.5, 0.5, 0.5, 1) # Gray color
ground.reparent_to(self.render)
# Load a cube and apply textures (base color and normal map)
cube = self.loader.loadModel("models/box")
cube.set_scale(2, 2, 2) # Larger size for visibility
cube.set_pos(0, 0, 1) # Positioned above ground
cube.reparent_to(self.render)
# Apply a simple base color texture (optional)
base_tex = self.loader.loadTexture("models/textures/brick_color.jpg") # Replace with your texture
cube.set_texture(base_tex, 1) # Priority 1 for base texture
# Apply a normal map texture
normal_tex = self.loader.loadTexture("models/textures/brick_normal.jpg") # Replace with your normal map
ts = TextureStage("normal")
ts.set_mode(TextureStage.MNormal) # Set as normal map
cube.set_texture(ts, normal_tex)
# Create a directional light (simulating the sun)
sun = DirectionalLight("sun")
sun.set_color(Vec4(1.0, 0.95, 0.9, 1) * 1.5) # Warm white light, slightly intensified
sun_node = self.render.attach_new_node(sun)
# Position and orient the "sun" to cast shadows
sun_node.set_pos(10, -10, 20) # High and to the side
sun_node.look_at(0, 0, 0) # Pointing towards the origin
# Enable shadow casting with decent resolution
sun.set_shadow_caster(True, 1024, 1024) # 1024x1024 shadow map
# Adjust the light's lens for better shadow quality
lens = sun.get_lens()
lens.set_film_size(20, 20) # Size of the shadow frustum
lens.set_near_far(1, 100) # Near and far planes for depth precision
# Apply the light to the entire scene
self.render.set_light(sun_node)
# Position the camera
self.camera.set_pos(15, -15, 10)
self.camera.look_at(0, 0, 0)
# Optional: Disable default mouse control for static view
#self.disable_mouse()
# Run the application
app = MyApp()
app.run()
Greetings, and welcome to the forums! I hope that you find your time here to be positive!
As to your question: I think that the problem is simply that the default “box” model doesn’t have tangents and binormals, and that standard normal-mapping thus doesn’t work with it.
If you go to the sample programs and look at the “bump-mapping” sample, the model “abstractroom.egg” seems to have tangents and binormals. Try that one and see whether your code works with it!
Hmm… Your question prompted me to try out your code, and (after installing simplepbr and replacing the texture-paths with textures of my own), I found that… it worked as expected? Even with normal-mapping!
from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, Vec4, Vec3, TextureStage
import simplepbr
import panda3d
#panda3d.core.load_prc_file_data('', 'framebuffer-srgb true')
class MyApp(ShowBase):
def __init__(self):
# Initialize the base class (ShowBase)
ShowBase.__init__(self)
# Initialize simplepbr with shadows and normal maps enabled
simplepbr.init(enable_shadows=True, use_normal_maps=True)
# Load a cube and apply textures (base color and normal map)
cube = self.loader.loadModel("ralph.egg.pz")
cube.set_scale(2, 2, 2) # Larger size for visibility
cube.reparent_to(self.render)
# Run the application
app = MyApp()
app.run()
this code works. but if directional lights added, it renders black. ralph.egg.pz (180.3 KB)
from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, Vec4, Vec3, TextureStage
import simplepbr
import panda3d
#panda3d.core.load_prc_file_data('', 'framebuffer-srgb true')
class MyApp(ShowBase):
def __init__(self):
# Initialize the base class (ShowBase)
ShowBase.__init__(self)
# Initialize simplepbr with shadows and normal maps enabled
simplepbr.init(enable_shadows=True, use_normal_maps=True)
# Load a cube and apply textures (base color and normal map)
cube = self.loader.loadModel("ralph.egg.pz")
cube.set_scale(2, 2, 2) # Larger size for visibility
cube.reparent_to(self.render)
# Create a directional light (simulating the sun)
sun = DirectionalLight("sun")
sun.set_color(Vec4(1.0, 0.95, 0.9, 1) * 1.5) # Warm white light, slightly intensified
sun_node = self.render.attach_new_node(sun)
# Position and orient the "sun" to cast shadows
sun_node.set_pos(10, -10, 20) # High and to the side
sun_node.look_at(0, 0, 0) # Pointing towards the origin
# Enable shadow casting with decent resolution
sun.set_shadow_caster(True, 1024, 1024) # 1024x1024 shadow map
# Adjust the light's lens for better shadow quality
lens = sun.get_lens()
lens.set_film_size(20, 20) # Size of the shadow frustum
lens.set_near_far(1, 100) # Near and far planes for depth precision
# Apply the light to the entire scene
self.render.set_light(sun_node)
# Position the camera
self.camera.set_pos(15, -15, 10)
self.camera.look_at(0, 0, 0)
# Run the application
app = MyApp()
app.run()
[edit]
I’m assuming that the Ralph that you posted above is just the normal Ralph from the Panda3D sample-programs. Is that correct? Or did you modify it in some way…?
I performed my test with the model from the sample-programs.
[/edit]
So, once again, let me ask:
What are your computer specs?
What version of Panda are you using?
What version of Python are you using?
What version of simplepbr are you using?
Are there any errors reported in the terminal when you run the program?
(If you’re not seeing terminal output, try running your program from command-line/terminal/cmd.)
My guess is that there’s some issue in your system–maybe you’re using an old version of Panda, or of simplepbr; maybe your drivers aren’t up-to-date; or something else.
ok. it works when i set setShaderAuto() to that model…
using simplepbr, lighting of gltf model works, but egg not.
using autoshader, lighting of egg model works, but gltf not.