Skip to content

Using simplepbr and an orthographic lens causes a problem with the material. #41

Open
@serkkz

Description

@serkkz

When I use an orthographic the lens, the properties of the material are lost, as you can see, the specular glare has disappeared.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, Material, NodePath, Camera, OrthographicLens

import simplepbr

class MyApp(ShowBase):
    def __init__(self):
        super().__init__()
        
        # Setting up a new node for rendering.
        my_aspect2d = NodePath("my_aspect2d")

        my_lens = OrthographicLens()
        my_lens.set_film_size(8, 8)
        my_lens.set_near_far(-1000, 1000)

        camera = Camera("camera_orthographic")
        camera.set_lens(my_lens)

        camera_np = NodePath(camera)
        camera_np.set_scale(base.win.get_x_size()/base.win.get_y_size()*1.0, 1.0, 1.0)
        camera_np.reparent_to(my_aspect2d)

        display_region = base.cam.node().get_display_region(0)
        display_region.camera = camera_np
        
        # PBR initialization
        pbr = simplepbr.init(render_node = my_aspect2d, camera_node = camera_np)
        pbr.enable_shadows = True

        # Creating a scene.
        material = Material("test")
        material.set_shininess(128)

        plane = base.loader.load_model("plane.egg")
        plane.set_material(material)
        plane.reparent_to(my_aspect2d)

        sphere = base.loader.load_model("sphere.egg")
        sphere.set_material(material)
        sphere.reparent_to(my_aspect2d)

        light = DirectionalLight("sun")
        light.set_shadow_caster(True, 512, 512)
        light_np = NodePath(light)
        light_np.set_hpr(35, -25, 0)
        light_np.reparent_to(my_aspect2d)

        my_aspect2d.set_light(light_np)

        # Calculation of the bounding box for the shadow map.
        bmin, bmax = my_aspect2d.get_tight_bounds(light_np)
        light_lens = light.get_lens()
        light_lens.set_film_offset((bmin.xz + bmax.xz) * 0.5)
        light_lens.set_film_size(bmax.xz - bmin.xz)
        light_lens.set_near_far(bmin.y, bmax.y)

app = MyApp()
app.run()

2

The test scene with the perspective lens works as expected.

from direct.showbase.ShowBase import ShowBase
from panda3d.core import DirectionalLight, Material, NodePath

import simplepbr

class MyApp(ShowBase):
    def __init__(self):
        super().__init__()

        # PBR initialization
        pbr = simplepbr.init()
        pbr.enable_shadows = True

        # Creating a scene.
        material = Material("test")
        material.set_shininess(128)

        plane = base.loader.load_model("plane.egg")
        plane.set_material(material)
        plane.reparent_to(render)

        sphere = base.loader.load_model("sphere.egg")
        sphere.set_material(material)
        sphere.reparent_to(render)

        light = DirectionalLight("sun")
        light.set_shadow_caster(True, 512, 512)
        light_np = NodePath(light)
        light_np.set_hpr(35, -25, 0)
        light_np.reparent_to(render)

        render.set_light(light_np)

        # Calculation of the bounding box for the shadow map.
        bmin, bmax = render.get_tight_bounds(light_np)
        light_lens = light.get_lens()
        light_lens.set_film_offset((bmin.xz + bmax.xz) * 0.5)
        light_lens.set_film_size(bmax.xz - bmin.xz)
        light_lens.set_near_far(bmin.y, bmax.y)

app = MyApp()
app.run()

1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions