lights not works
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!
if normal-mapping not works, is not it render basecolor texture? why black color?
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!
See the following screenshot:
In which case, the question becomes: why does it work for me, and not for you?
What can you tell us about your system? Specifically:
- 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.)
ok… i loaded model in another one code and it works.
still this code not works. i will try to find the issue. thanks
1 Like
Well, could you perhaps post the code that works for you? Perhaps there’s a clue in the comparison between the two.
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()
Hmm… Once again, your code seems to work as expected on my machine:
[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.
yea…ralph model is from panda3d sample programs, not modified.
system specs:
dell inspiron 15 laptop
Windows 11
Intel(R) Core™ i5-1334U
gpu: Intel(R) Iris(R) Xe Graphics
panda3d 1.10.14
python 3.10.11
panda3d-simplepbr==0.12.0
cmd output
Known pipe types:
wglGraphicsPipe
(all display modules loaded.)
Hmm… I’m not confident in this, but it looks like your system should be capable enough.
I do note that there’s a more-recent version of Panda–I’m on 1.10.15, while you’re on 1.10.14–so it might be worth your updating Panda.
I’m also on Python 3.11–but I doubt that this is the cause of the discrepancy.
That said, my OS is Ubuntu Linux, so it’s possible that the issue lies with an OS-specific issue.
Hum. Right now, I don’t know–I’m going to pass on this for now, then, and see whether another forum-member has something to offer!