Complexpbr not rendering correctly

Apologies for my previous post as I was too vague.
Here are the details:

I am experimenting with complexpbr and tried to use this code:

from direct.showbase.ShowBase import ShowBase
from panda3d.core import PointLight
import complexpbr
app = ShowBase()
complexpbr.apply_shader(render, default_lighting=True)

model = loader.load_model('model.bam')
model.reparent_to(render)
model.set_y(20)

model2 = loader.load_model('sphere.bam')
model2.reparent_to(render)
model2.set_y(20)
model2.set_z(4)

light = PointLight('light')
light.set_shadow_caster(True)
light_np = render.attach_new_node(light)
light_np.set_y(20)
render.set_light(light_np)

app.run()

However, there were no shadows and the reflections were very weird and can only be seen at an extreme angle.

Here are some screenshots:


The reflections could only be seen at a extreme angle:

The models are exported from blender as a .glb format before converting it to bam via gltf2bam.

However, when I ran samples like the FPS and Project Naer, the rendering seems to be fine.

Please correct me on any errors I am making. Thank you.

This is a bit of a shot in the dark, but are your models perhaps set to be two-sided?

(For one thing, I’m noticing what looks like “some shadow-acne” on the top of the cube near the centre, and one potential cause of that, I believe, is the use of models with two-sided geometry.

And, speculatively, I could see such a setting potentially interfering with other effects, too.)

Hello, thank you for your reply.
How do I make the models one-sided? (e.g. in blender)
Thank you

I’m guessing that you’re using a modern version of Blender? If so, then I’m not all that familiar with it–I still use an old version, in part because I have my pipeline set up for it.

That said, looking around the forums, try investigating the settings for your materials, and ensuring that “Backface Culling” is enabled. (See this post, and this post.)

I have already tried it using a one-sided model but nothings changes.

But when I tried the FPS demo it worked, and the purple sphere is imported directly from the fps, so I am guessing it might probably be the code.

Aah, fair enough!

In that case, I really don’t know, I’m afraid–you may have to wait for one of the forum-members more familiar with complexpbr to arrive!

You aren’t making any errors, complexpbr currently requires you to update the position of the reflection cubemap relative to your camera with a function that looks something like this:

def rotate_cubemap(task):
  base.complexpbr_map.set_h(base.render,base.cam.get_h(base.render))
  base.complexpbr_map.set_p(base.render,base.cam.get_p(base.render) + 90)
  cam_pos = base.cam.get_pos(base.render)
  if base.env_cam_pos is not None:
    base.complexpbr_map.set_pos(base.env_cam_pos[0],base.env_cam_pos[1],base.env_cam_pos[2]+base.complexpbr_map_z)
  else:
    base.complexpbr_map.set_pos(cam_pos[0],cam_pos[1],cam_pos[2]+base.complexpbr_map_z)
  if base.complexpbr_z_tracking:
    cam_relative_pos = base.cam.get_pos(base.render)
    cam_relative_pos[2] = cam_relative_pos[2]-(2 * cam_relative_pos[2])
    base.env_cam_pos = cam_relative_pos

  base.cam_pos = cam_pos

  return task.cont

Depending on how your project is set up, you will need to manually control the orientation of the cubemap relative to your camera.

The behavior you’re seeing is the cubemap is registering at a fixed height. When your camera happens to be at that height, you see the reflection. When you’re above that height, you don’t see it.

*from complexpbr source

1 Like

Thank you for your reply. I tried your method, but the problem persisted. Nevertheless, I explored further and found a unstable fix with the base.complexpbr_z_tracking = True. However, you have to adjust base.complexpbr_map_z to get an accurate reflection, which is weird. I really don’t think that this is the correct method of doing this but it is still a clue to what is the problem.