How to use models loaded from .egg (or built-in models) and models loaded from .bam or .glb on the same scene?

Hello.
I’m trying to use models loaded from different sources on the same scene.
For example, I want to place a built-in model (“models/environment”) and a simple model created in blender on the same scene.
The model created in blender is white and has no material.
If I use simplepbr.init() with no arguments, the model renders correctly, but the inline model turns black.
If I specify the node of my model created in blender as the render_node argument, then I get the best option at the moment (simplepbr.init(render_node=self.figure)). But the built-in model becomes, as it were, excessively bright, and the brightness of the background color also changes. While it seems like the changes should have only affected the specified node…
I also want to note that it doesn’t matter if I use .bam or .glb files, the result is the same.
I’d be grateful if someone could shed some light on this.)
In the screenshot in the center is a model loaded from blender

Here is my code:

from direct.showbase.ShowBase import ShowBase
import simplepbr


class MyApp(ShowBase):

    def __init__(self):
        super().__init__(self)
        
        self.setBackgroundColor(0.5, 0.7, 1)

        self.scene = self.loader.loadModel("models/environment")
        self.figure = self.loader.loadModel('figure1.bam')
        # self.figure = self.loader.loadModel('figure1.glb')
        
        simplepbr.init(render_node=self.figure)

        self.scene.reparentTo(self.render)
        self.figure.reparentTo(self.render)

        self.scene.setPos(0, 500, -160)
        
        self.figure.setY(10)
        self.figure.setH(270) 

           
app = MyApp()
app.run()

I think that this is because simplepbr applies one or more post-process effects, which, by their nature, affect the entire scene. Thus even if a given object isn’t itself rendered via simplepbr, the resultant image of the scene will nevertheless be run through simplepbr’s post-processing.

If you want to work around this, you could perhaps re-implement PBR rendering in a shader of your own, replacing simplepbr, and thus allowing you to omit post-processing, or perhaps exert control over what is and isn’t post-processed.

(It’s possible that there’s a way to disable (or effectively disable) the post-processing in simplepbr–but I don’t see it in an admittedly-quick look over the readme.)

1 Like

It’s because of the gamma correction, actually.

Set the format of all textures on the regular models to Texture.F_srgb or Texture.F_srgb_alpha. (In the Egg file you can do this with <Scalar> format { srgb } in the <Texture> entry.)

2 Likes

Ah, I stand gladly corrected, then! :slight_smile:

Thanks, everything works with .egg files now :+1:

I’ll leave a code example here.
Since it’s not obvious, at least for me)

from direct.showbase.ShowBase import ShowBase
import simplepbr
from panda3d.core import Texture


class MyApp(ShowBase):

    def __init__(self):
        super().__init__(self)
        
        self.setBackgroundColor(1, 1, 1)

        # self.scene = self.loader.loadModel("models/environment")
        self.cone = self.loader.loadModel('cone.egg')
        self.figure = self.loader.loadModel('figure1.bam')
        # self.figure = self.loader.loadModel('figure1.glb')
        
        txtCone = self.loader.loadTexture('block.png')
        txtCone.set_format(Texture.F_srgb)
        self.cone.setTexture(txtCone)

        simplepbr.init(render_node=self.figure)

        # self.scene.reparentTo(self.render)
        self.cone.reparentTo(self.render)
        
        self.figure.reparentTo(self.render)

        # self.scene.setPos(0, 500, -160)
        self.cone.setPos(0, 15, 0)
        self.figure.setPos(2, 15, 0)
              
app = MyApp()
app.run()

I want to note that Texture.F_srgb works well with “simple” textures, but distorts “complex” ones (I used textures in .png). For the “complex” ones, I used Texture.F_srgb_alpha.
But, when I tried to apply Texture.F_srgb_alpha to “simple” textures, the following error occurred: AssertionError: image_ptr >= orig_image_ptr && image_ptr + view_size <= orig_image_ptr + tex->get_ram_mipmap_image_size(n) at line 13700 of panda/src/glstuff/glGraphicsStateGuardian_src .cxx

In order to use Texture, you first need to include: from panda3d.core import Texture

Also, maybe someone knows how to return the brightness to the background color) Although this is not such an important issue.

You need to use F_srgb_alpha on textures with alpha channel, F_srgb on ones without. You can check it with tex.num_components, if it’s 4, it has an alpha channel.

Thanks a lot