Directional Lighting not working when imported with panda3d-gltf, but does when imported with assimp

I’ve been struggling with a similar problem.

  • I want shadows so I’m using setShaderAuto
  • I’m using PBR materials in some models and for model textures
  • (Maybe not relevant) I’m exporting from Blender 3.3 to glTF instead of .bam because textures are lost by blend2bam
  • Directional/colored lighting isn’t working on glTF models once enabling simplepbr (they always work on my CardMaker ‘ground’ with a texture set programmatically)

With render_stage_convert() from sourses.zip above, I’m losing the texture from my model, but directional/colored lighting does work.

I can provide a sample model if useful. I’m struggling to find a combination that works for all of this together.

Hello, of course, provide a model. But archive it along with the short code and don’t forget the textures.

However, note that simplepbr supports shadows. The exception applies only to point sources.

I took the time to check out simplepbr, and it works like a charm.
My node setup of the material:


My code:

#from fix_gltf_bam import render_stage_convert
from panda3d.core import AmbientLight, DirectionalLight, NodePath, loadPrcFileData
#loadPrcFileData("", "show-scene-graph-analyzer-meter true")
import simplepbr

from direct.showbase.ShowBase import ShowBase

class MyApp(ShowBase):

    def __init__(self):
        ShowBase.__init__(self)

        spbr = simplepbr.init()
        spbr.use_normal_maps = True

        model = loader.load_model("MyTest.gltf")
        #render_stage_convert(model, normal = False)
        model.reparent_to(render)

        sun = DirectionalLight("sun")
        sun.set_color((0.8, 0.8, 0.8, 1))
        sun_np = NodePath(sun)
        sun_np.reparent_to(render)

        sun_np.set_z(50)
        sun_np.set_x(40)
        sun_np.set_y(-40)
        sun_np.set_p(-40)
        sun_np.set_h(45)

        sun_np.node().set_shadow_caster(True, 1024, 1024)
        sun_np.node().get_lens().set_film_size(20, 20)
        #sun_np.node().show_frustum()
        render.set_light(sun_np)

        ambient = AmbientLight('alight')
        ambient.set_color((0.2, 0.2, 0.2, 1))
        ambient_np = NodePath(ambient)
        ambient_np.reparent_to(render)
        render.set_light(ambient_np)

        #render.set_shader_auto()

app = MyApp()
app.run()

Output result in Panda3D.

Moguri has done a great job.

2 Likes

That looks great, @serega-kkz! I can’t wait to get results like that :wink:

I created this demo package to show the similar kind problem I’m running into.
lighting.zip (468.0 KB)

  • In order to get the textures rendered from gltf I have to use the fix_material_gltf() function from earlier in this post, but directional lighting doesn’t work (back/right quadrant in the demo layout)
  • Your later fix from the .zip file fixes directional lighting, but I can no longer see the texture (front/right quadrant in the demo layout)

The problem is that your texture doesn’t have a name. I have to understand how this happened, did you create the models programmatically? or exported from blender, in which case I can see how you have configured the material nodes? Screenshot of the nodes of the material please.

Ah, I realized they are included in your model. I need to process it somehow in my script, too.

Okay, yeah, I had used packed textures in my glTF (embedded). I retried with gltf+bin and that works better (see screenshot).

Material node configs included for completeness.


It was not necessary, I already realized that the texture is included in the model, respectively, it does not have a file name. I released a fix, but found a minor bug with the unlit side, but we’ll postpone it for the next day.

A new version of the gltf pipeline correction module, now the presence of a texture is determined by size, not by name. Returned manipulations with the material that can be customized at will. For example, the metallicity parameter is disabled for the material, the two-wayness will also be disabled.

sourse.zip (17.1 KB)

1 Like

This works perfectly for my purposes. Thank you!

1 Like