Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
serkkz opened this issue May 12, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@serkkz
Copy link

serkkz commented May 12, 2022

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

@serkkz serkkz changed the title Use simplepbr and orthographic projection, causes a problem. Use simplepbr and orthographic lens, causes a problem. May 12, 2022
@serkkz serkkz changed the title Use simplepbr and orthographic lens, causes a problem. Using simplepbr and an orthographic lens causes a problem with the material. May 12, 2022
@Moguri
Copy link
Owner

Moguri commented May 26, 2023

simplepbr needs to use a different view vector when used with an orthographic camera. It would be nice to do this based on a pre-processor define. We could check projection type of the camera when setting up the shader, but then we would not be able to detect if the projection changed later. This might be "good enough" since the alternatives (checking in the shader, checking every frame via a task) would all add more runtime cost for a pretty uncommon use case.

@Moguri Moguri added the bug Something isn't working label May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants