Lighting / Material rendering issue

I’m trying to load .obj + .mtl files in panda3d using Showbase.loader.loadModel helper method. I would like to get the same rendering than threejs:

But I’m getting this instead:

screenshot-2021-10-27-21-32-11

Except the torso of the robot, all the bodies do no rendering properly. Apparently it is working for the torso because map_Kd is provided.

newmtl black-delrin.002
Ns 81.000006
Ka 1.000000 1.000000 1.000000
Kd 0.100000 0.100000 0.100000
Ks 0.500000 0.500000 0.500000
Ke 0.000000 0.000000 0.000000
Ni 1.450000
d 1.000000
illum 2
map_Kd skin.png

I think otherwise the material appears grey when there is no facing light, which makes sense based on how lighting works in Panda3d. Yet, I don’t know how to get the expected result :confused:

The standard panda render works strangely. You need to use your own shaders, or use the library:

Again, it is incomplete.

Indeed it looks promising !
Just need to figure out why the background appears all back :laughing:

I would guess that your background lacks the full set of PBR textures: colour, metallicity-roughness, normal-map, and possibly emission.

Hum… My ground for instance is just this:

model = GeomNode('floor')
node = self.render.attach_new_node(model)

for xi in range(-10, 11):
    for yi in range(-10, 11):
        tile = GeomNode(f"tile-{xi}.{yi}")
        tile.add_geom(geometry.make_plane(size=(1.0, 1.0)))
        tile_path = node.attach_new_node(tile)
        tile_path.set_pos((xi, yi, 0.0))
        if (xi + yi) % 2:
            tile_path.set_color((0.95, 0.95, 1.0, 1.0))
       else:
           tile_path.set_color((0.13, 0.13, 0.2, 1.0))

The sky is also procedurally generated. So indeed the information you mention are missing :confused:

Well, a quick-and-dirty solution might be to disable shaders for those elements. I’m not sure, but I think that doing so should cause them to be rendered without simplepbr.

Or, of course, you could give them the relevant textures–even if those are just stand-in textures with nothing but a single solid colour each.

1 Like

You are right, disabling the shader makes it render properly, but then the shadow of the robot does not project on the ground anymore. So I think it is not a valid option.

image

Well, you could perhaps then activate the auto-shader on it.

I’m… not sure of how well the auto-shader and simplepbr might behave with both enabled, but it might be worth a try.

… Or you could give your floor PBR textures, as previously suggested. :stuck_out_tongue:

1 Like

you could give your floor PBR textures

I tried to do it, and for some reason it is not helping. Here is how I create the ground now:

model = GeomNode('floor')
node = self.render.attach_new_node(model)
model.add_geom(geometry.make_plane(size=(10.0, 10.0)))
material = Material()
material.set_ambient(Vec4(0.95, 0.95, 1.0, 1.0))
material.set_diffuse(Vec4(0.95, 0.95, 1.0, 1.0))
material.set_specular(Vec3(1.0, 1.0, 1.0))
material.set_roughness(0.4)
node.set_material(material, 1)

Now it renders the ground, but there is still no shadow…
image

Also the lighting is strange and seems inconsistent with my settings:

light = AmbientLight('Ambient Light')
light.set_color(Vec3(0.5, 0.5, 0.5))
node = self.render.attach_new_node(light)

light = DirectionalLight('Directional Light')
light.set_color(Vec3(0.5, 0.5, 0.5))
node = self.render.attach_new_node(light)
node.set_pos(8.0, 8.0, 10.0)
node.look_at(0.0, 0.0, 0.0)

I tried to set set_shader_auto to the ground and background (without material) as suggested, and this time, it is projecting the shadow but there is a weird pattern also appearing. Moreover, I have several windows (one for onscreen display, and others for offscreen rendering for different camera angles) and don’t get the same visual. I guess it is expected based on how simplepbr since to work.

Offscreen:
screenshot-2021-10-28-00-40-41

Onscreen:
image

I would say the offscreen one is almost fine, just the light that is way to dark and the strange pattern on the ground. But the onscreen one is not good, like the colors are faded.

EDIT: Apparently the weird pattern is because of two-sided rendering of the ground. Playing with the color of the lights is also helping but I’m not really satisfied (the floor is too bright while the ground is too dark), and most importantly onscreen and offscreen rendering do not match.

screenshot-2021-10-28-01-05-32

image

A good solution would be to call @Moguri

About the question about the color difference. However, I will assume that the snag is sRGB.

I found this issue: Document requirement that textures need to use an sRGB texture format · Issue #6 · Moguri/panda3d-simplepbr · GitHub
It seems to be related to this indeed. But I’m not sure how to address it.

I tried many things regarding framebuffer properties but nothing works. I’m a little bit disappointed because the offscreen rendering looks neat ! Apart from the lighting that makes the robot appears a bit dark it is just perfect :grinning:

I finally solved the washed out colors issue using only using a subset of what simplepbr is doing. Namely:

        shader_options = {
            'MAX_LIGHTS': 2,
            'USE_NORMAL_MAP': '',
            'ENABLE_SHADOWS': '',
            'ENABLE_FOG': '',
            'USE_OCCLUSION_MAP': ''
        }
        pbr_vert = simplepbr._load_shader_str('simplepbr.vert', shader_options)
        pbr_frag = simplepbr._load_shader_str('simplepbr.frag', shader_options)
        pbrshader = Shader.make(
            Shader.SL_GLSL, vertex=pbr_vert, fragment=pbr_frag)
        self.render.set_attrib(ShaderAttrib.make(pbrshader))

However know I have an issue with the shadows only being rendered from very close distance and specific angle:
image

EDIT: I fixed It ! Apparently it was because one of the object on the scene was not properly render because of missing material, messing up with the whole scene shadow casting…

Now everything works as expected ! Thank you guys !

2 Likes