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

Unfortunately the assimp importer doesnt honor my rigid bodies, so i need this to function. Heres my journey so far!

See here is the egg! its responding to the directional light!

Heres its frustum:

But its bam version doesnt, everthing is dark ah!

Is there a way I can find the interim gltf before it goes to bam?

So given I think blend2bam does this: its normal gltf from blender → gltf2bam → bam file

Here is that normal gltf:
playground6.gltf (444.5 KB)

Responds to lighting in the gltf viewer!

Great News! Ive definitely narrowed it down to the gltf importer!

Here is Hammy with the assimp gltf importer! Respond to his directional light!

Here he his after import with panda3d-gltf!

My exact problem!

Dont worry, ill find it and fix it! Then ill add the physics material parameters like bounce/friction for ya.

and the diff! Could this warning about a missing material only on gltf be the issue?

Nope, not it, added the material. So it has to be the different node rendering attributes.

Yup, so it looks like there just arent materials when imported via panda3d-gltf:
geom Mesh.001 has material: False
geom Mball.020 has material: False
geom dmesh has material: False
geom dobj has material: False
geom Scene has material: False

but are when imported by assimp:
geom dobj has material: True
geom ROOT has material: False
geom Mball.020 has material: False
geom ROOT has material: False
geom hammy_mesh1.gltf has material: False

well false alarm, that was an object that was inside my other object that shouldnt have been there and no, doesnt have a material. Sigh =( back to the drawing board.

Okay, so the core difference is yours assings fallback textures for pbr, assimp does not.

When I do this:

hamster.applyTextureColors()

and fix the gltf to be one sided:

"doubleSided":false,

I get light respected… finally:

I hope this helps! Do we need fallbacks?

welp, and if i remove rigidbodies off of things they respect the directional light…but… only if they are not textured. If they are textured, the turn white hahaha. I cant make this up. Alright, i need to sleep. I cant look at this anymore. Hopefully this will help you make sense of things.

1 Like

This was my one sided entire night long debugging session ported over from private message with moguri, so sorry for the bad formatting, just assume minutes to hours passed in between talking points.

1 Like

I think you need to perform this function for debugging purposes on the model obtained by panda3d-gltf and assimp

from direct.showbase.ShowBase import ShowBase
from panda3d.core import MaterialAttrib, TextureAttrib

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

        panda = loader.load_model("panda")

        self.get_pipeline(panda)

    def get_pipeline(self, node):
        for node_path in node.find_all_matches('**/+GeomNode'):
            geom_states = node_path.node().get_geom_states()
            print("Node name: ", node_path.name)
            for geom_state in geom_states:
                if geom_state.has_attrib(MaterialAttrib):
                    print(geom_state.get_attrib(MaterialAttrib).get_material())
                '''if geom_state.has_attrib(TextureAttrib):
                    texture_stages = geom_state.get_attrib(TextureAttrib).get_on_stages()
                    for texture_stage in texture_stages:
                        print(texture_stage, geom_state.get_attrib(TextureAttrib).get_on_texture(texture_stage))'''
                print("------------------------")

test = Test()
test.run()

I think there should be a difference in the material.

Okay will report back!

They are identical. but this is how i originally spotted the twoSided detail (talked about above)

assimp

Known pipe types:
  glxGraphicsPipe
(1 aux display modules not yet loaded.)
Node name:  Cube.002
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Cube.003
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Sphere
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------
Node name:  Cube.009
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------
Node name:  Cube.010
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Cube.007
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------
No gamepad found.

panda-gltf

Known pipe types:
  glxGraphicsPipe
(1 aux display modules not yet loaded.)
Node name:  Cube.002
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Cube.003
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Sphere
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------
Node name:  Cube.009
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------
Node name:  Cube.010
Material Material.001
  base_color = 0.8 0.00161385 0 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 1

------------------------
Node name:  Cube.007
Material Material.003
  base_color = 1 1 1 1
  refractive_index = 1.5
  emission = 0 0 0 0
  roughness = 0.5
  metallic = 0
  local = 0
  twoside = 0

------------------------

The difference is their textures. Assimp has none, gltf adds defaults. But I even removed those. Its odd but the differentiating factor is whether or not it has a damn rigidbody. I did notice that my gltf does not have the blender extensions for it?

Hmm, maybe the problem is that your geometry is inherited from physical nodes, and lighting is disabled for them. It is necessary to change the order of inheritance, the geometry that is rendered should be at the top of the hierarchy.

nvm textures are the same, that was just for hammy it looks like.

Okay, good idea ill test that out.

Unfortunately that did not do it.

render/World/Scene/Cube/Cube/Cube.007
ModelRoot Scene
  PandaNode Cube.001 T:m(pos 1.82039 142.517 -6.91868 hpr 29.6564 0 0)
    GeomNode Cube.002 (1 geoms: S:(ColorAttrib CullFaceAttrib MaterialAttrib))
  PandaNode Cube.003 T:m(pos 0.19733 116.986 -8.7649)
    GeomNode Cube.003 (1 geoms: S:(ColorAttrib CullFaceAttrib MaterialAttrib))
  PandaNode Sphere [mass friction] T:m(pos 0 7.35034 0)
    GeomNode Sphere (1 geoms: S:(ColorAttrib CullFaceAttrib MaterialAttrib))
  PandaNode Cube [friction mass] T:m(pos -3.83839 31.405 -16.0629 hpr 0 16.9346 0)
    GeomNode Cube.007 (1 geoms: S:(CullFaceAttrib MaterialAttrib TextureAttrib))
      BulletRigidBodyNode Cube (1 shapes) inactive static mass=0
  PandaNode Cube.004 T:m(pos -3.41965 202.667 -16.0629 hpr 0 -10.0633 0)
    GeomNode Cube.009 (1 geoms: S:(ColorAttrib CullFaceAttrib MaterialAttrib))
  PandaNode Cube.002 T:m(pos 0.19733 83.4659 -8.7649 hpr 0 -11.7652 0)
    GeomNode Cube.010 (1 geoms: S:(ColorAttrib CullFaceAttrib MaterialAttrib))

This is getting exhausting, maybe ther is a way i can make it asthetically appealing without using light ramps and setShaderOn? =((((

I think I’ll have to install panda3d-gltf and personally experiment with it.

Hey thanks for trying regardless.

The investigation is over, during which it was found out that when using the glif format, the emission parameter is also set for the material. What is perceived as radiation with a standard auto shader.

I wrote a small function to fix the models obtained through the gltf format. An example of use is attached.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import AmbientLight, DirectionalLight, MaterialAttrib, NodePath

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

        gltf = loader.load_model("test_box.gltf")
        gltf.set_pos(1.5, 0, 1)
        gltf.reparent_to(render)

        # If you are using the panda3d-gltf loader or a bam file obtained through the 
        # gltf2bam utility, call this command to clear the emission parameter of the material
        self.fix_material_gltf(gltf)
  
        model1 = loader.load_model("box")
        model1.reparent_to(render)
        model1.set_scale(10, 10, 1)
        model1.set_pos(-4, -4, -1)

        alight = AmbientLight("alight")
        alight.set_color((0.2, 0.2, 0.2, 1))

        np_alight = NodePath(alight)
        np_alight.reparent_to(render)

        slight = DirectionalLight('slight')
        slight.getLens().set_film_size(10)
        slight.getLens().set_near_far(0.1, 17)
        slight.set_color((1,1,1,1))
        #slight.show_frustum()
        slight.set_shadow_caster(True, 1024, 1024)

        np_slight = NodePath(slight)
        np_slight.reparent_to(render)

        np_slight.set_pos(0, 10, 5)
        np_slight.set_hpr(180, -20, 0)

        render.set_shader_auto()
        render.set_light(np_alight)
        render.set_light(np_slight)

    def fix_material_gltf(self, node):
        for node_path in node.find_all_matches('**/+GeomNode'):
            geom_states = node_path.node().get_geom_states()
            for geom_state in geom_states:
                if geom_state.has_attrib(MaterialAttrib):
                    mat = geom_state.get_attrib(MaterialAttrib).get_material()
                    mat.clear_emission()

test = Test()
test.run()
1 Like

WHATTTTTTT, did you test it with a rigidbody? You are the man, ill test.

In fact, this problem is present without a rigidbody.

Well, for me, it doesnt appear to be resolved. They DO look lighter, but, they are not responding to directional light still, showing shadow, and the red material is gone off of those platforms.

The only option is if you lay out a minimal example along with models and code.

Would you be okay getting added to a github repo? If so pass along email. If not, ill re-create a different example.

I think it would be better to make a separate example for all members of the community, in case I can’t find the source of the problem.

You didnt enable a lightramp, key issue in mine. I think thats a starting point. Im trying to use toon shading.