GithubHelp home page GithubHelp logo

rayanalysis / panda3d-complexpbr Goto Github PK

View Code? Open in Web Editor NEW
15.0 4.0 2.0 2.56 MB

IBL rendering module supporting real-time reflections and post-processing effects in Panda3D

Home Page: https://pypi.org/project/panda3d-complexpbr/

License: BSD 3-Clause "New" or "Revised" License

Python 42.30% GLSL 57.70%
ibl pbr python

panda3d-complexpbr's Introduction

panda3d-complexpbr

Functional node level scene shader application for Panda3D. complexpbr supports realtime environment reflections for BSDF materials. These reflections are implemented with IBL (Image-based lighting) and PBR (Physically Based Rendering) forward shading constructs. Your machine must support GLSL version 430 or higher. Sample screenshots below.

Featuring support for vertex displacement mapping, SSAO (Screen Space Ambient Occlusion), SSR (Screen Space Reflections), HSV color correction, Bloom, and Sobel based antialiasing in a screenspace kernel shader, which approximates temporal antialiasing. complexpbr.screenspace_init() automatically enables the AA, SSAO, SSR, and HSV color correction. To use the vertex displacement mapping, provide your displacement map as a shader input to your respective model node -- example below in the Usage section.

By default, the environment reflections dynamically track the camera view. You may set a custom position with the 'env_cam_pos' apply_shader() input variable to IE fix the view to a skybox somewhere on the scene graph. This env_cam_pos variable can be updated live afterwards by setting base.env_cam_pos = Vec3(some_pos). The option to disable or re-enable dynamic reflections is available.

As of version 0.5.2, complexpbr will default to a dummy BRDF LUT which it creates on the fly. complexpbr will remind you that you may create a custom BRDF LUT with the provided 'brdf_lut_calculator.py' script or copy the sample one provided. This feature is automatic, so if you provide the output_brdf_lut.png file in your program directory, it will default to that .png image ignoring the lut_fill input. The sample 'output_brdf_lut.png' and the creation script can be found in the panda3d-complexpbr git repo. For advanced users there is an option to set the LUT image RGB fill values via apply_shader(lut_fill=[r,g,b]) . See Usage section for an example of lut_fill.

As of version 0.5.3, hardware skinning support is provided via complexpbr.skin(your_actor) for models with skeletal animations. See Usage section for an example of hardware skinning.

The goal of this project is to provide extremely easy to use scene shaders to expose the full functionality of Panda3D rendering, including interoperation with CommonFilters and setting shaders on a per-node basis.

complexpbr_screen_2

complexpbr_reflections_2

10/30/23 Project Naer (Project Naer complexpbr)

beige_screen_2

silver_screen_1

7/6/23 Lumberyard Bistro (Amazon Lumberyard Bistro | NVIDIA Developer)

bistro_exterior_11

bistro_interior_5

bistro_exterior_10

6/1/23 Sponza (Intel GPU Research Samples)

sponza_screen_1-Thu-Jun-01-08-16-18-2023-26

sponza_screen_1-Thu-Jun-01-08-17-47-2023-15

sponza_screen_1-Thu-Jun-01-06-02-59-2023-22

sponza_screen_2-Thu-Jun-01-05-56-06-2023-591

sponza_screen_1-Fri-Jun-02-08-54-07-2023-428

Usage:

from direct.showbase.ShowBase import ShowBase
import complexpbr

class main(ShowBase):
    def __init__(self):
        super().__init__()
         
        # apply a scene shader with PBR IBL
        # node can be base.render or any model node, intensity is the desired AO
        # (ambient occlusion reflection) intensity (float, 0.0 to 1.0)
        # you may wish to define a specific position in your scene where the 
        # cube map is rendered from, to IE have multiple skyboxes preloaded
        # somewhere on the scene graph and have their reflections map to your
        # models -- to achieve this, set env_cam_pos=Vec3(your_pos)
        # you may set base.env_cam_pos after this, and it will update in realtime
        # env_res is the cube map resolution, can only be set once upon first call
        
        complexpbr.apply_shader(self.render)
        # complexpbr.screenspace_init()  # optional, starts the screenspace effects
        
        # apply_shader() with optional inputs
        # complexpbr.apply_shader(self.render, intensity=0.9, env_cam_pos=None, env_res=256, lut_fill=[1.0,0.0,0.0])

        # initialize complexpbr's screenspace effects (SSAO, SSR, AA, HSV color correction)
        # this replaces CommonFilters functionality
        complexpbr.screenspace_init()
        
        # make the cubemap rendering static (performance boost)
        complexpbr.set_cubebuff_inactive()
        
        # make the cubemap rendering dynamic (this is the default state)
        complexpbr.set_cubebuff_active()

        # example of how to apply hardware skinning
        fp_character = actor_data.player_character  # this is an Actor() model
        fp_character.reparent_to(self.render)
        fp_character.set_scale(1)
        # set hardware skinning for the Actor()
        complexpbr.skin(fp_character)

        # example of how to use the vertex displacement mapping
        wood_sphere_3 = loader.load_model('assets/models/wood_sphere_3.gltf')
        wood_sphere_3.reparent_to(base.render)
        wood_sphere_3.set_pos(0,0,1)
        dis_tex = Texture()
        dis_tex.read('assets/textures/WoodFloor057_2K-PNG/WoodFloor057_2K_Displacement.png')
        wood_sphere_3.set_shader_input('displacement_map', dis_tex)
        wood_sphere_3.set_shader_input('displacement_scale', 0.1)
        
        # example of how to set up bloom -- complexpbr.screenspace_init() must have been called first
        screen_quad = base.screen_quad
        
        bloom_intensity = 5.0  # bloom defaults to 0.0 / off
        bloom_blur_width = 10
        bloom_samples = 6
        bloom_threshold = 0.7

        screen_quad.set_shader_input("bloom_intensity", bloom_intensity)
        screen_quad.set_shader_input("bloom_threshold", bloom_threshold)
        screen_quad.set_shader_input("bloom_blur_width", bloom_blur_width)
        screen_quad.set_shader_input("bloom_samples", bloom_samples)
        
        # example of how to customize SSR
        ssr_intensity = 0.5  
        ssr_step = 4.0
        ssr_fresnel_pow = 3.0
        ssr_samples = 128  # ssr_samples defaults to 0 / off
        
        screen_quad.set_shader_input("ssr_intensity", ssr_intensity)
        screen_quad.set_shader_input("ssr_step", ssr_step)
        screen_quad.set_shader_input("ssr_fresnel_pow", ssr_fresnel_pow)
        screen_quad.set_shader_input("ssr_samples", ssr_samples)
        
        # example of how to customize SSAO
        ssao_samples = 32  # ssao_samples defaults to 8
        
        screen_quad.set_shader_input("ssao_samples", ssao_samples)
        
        # example of how to HSV adjust the final image
        screen_quad.set_shader_input("hsv_g", 1.3)  # hsv_g (saturation factor) defaults to 1.0
        
        # example of how to modify the specular contribution
        self.render.set_shader_input("specular_factor", 10.0)  # the specular_factor defaults to 1.0
        
        # example of how to directly fill your BRDF LUT texture instead of providing one in your game folder
        complexpbr.apply_shader(base.render, 1.0, env_res=1024, lut_fill=[1.0,0.0,0.0])  # lut_fill=[red, green, blue]
        
        # if complexpbr.screenspace_init() has not been called, you may use CommonFilters
        # scene_filters = CommonFilters(base.win, base.cam)
        # scene_filters.set_bloom(size='medium')
        # scene_filters.set_exposure_adjust(1.1)
        # scene_filters.set_gamma_adjust(1.1)
        # scene_filters.set_blur_sharpen(0.9)

Installing with PyPI:

pip install panda3d-complexpbr

Building:

The module may be built using build.

python -m build
pip install 'path/to/panda3d-complexpbr.whl'

Future Project Goals:

  • Function triggers for building new BRDF LUT samplers in realtime
  • Installation over pip

Requirements:

  • panda3d

sponza_screen_1-Thu-Jun-01-05-39-29-2023-111

sponza_screen_3-Thu-Jun-01-05-56-32-2023-657

sponza_screen_1-Thu-Jun-01-05-55-48-2023-540

sponza_screen_1-Thu-Jun-01-08-28-36-2023-104

sponza_screen_2-Thu-Jun-01-08-23-21-2023-1500

complexpbr_daytime_screen_1

complexpbr_daytime_screen_2

complexpbr_daytime_screen_3

complexpbr_screen_2

complexpbr_screen_3

Vertex Displacement Mapping:

complexpbr_screen_4

panda3d-complexpbr's People

Contributors

rayanalysis avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

panda3d-complexpbr's Issues

Exported landscape model has wrong colors

Hi,
I exported landscape from blender as glTF but it renders as redish:
Screenshot_20230929_002754

Here is material setup:
image

What I tried:

  • I replaced material with default one
  • imported model into fresh Blender project then exported as glTF
  • re-exported arena scene (which is part of Panda3D-Arena-FPS-Sample-Program), but it renders fine
  • changed lights position to make them stay higher

I use:
Blender 3.0.1
Panda3D 1.11

Error on initializing the code

The code written in the readme file gives this error:
Traceback (most recent call last):
File "c:\Users\Lenovo\Mombie challenge edtion\ursina editor\Editor\ok.py", line 94, in
main().run()
^^^^^^
File "c:\Users\Lenovo\Mombie challenge edtion\ursina editor\Editor\ok.py", line 18, in init
complexpbr.apply_shader(self.render)
File "c:\Users\Lenovo\Mombie challenge edtion\ursina editor\Editor\complexpbr_init_.py", line 181, in apply_shader
complexpbr_rig_init(node, intensity=intensity, lut_fill=lut_fill)
File "c:\Users\Lenovo\Mombie challenge edtion\ursina editor\Editor\complexpbr_init_.py", line 146, in complexpbr_rig_init
node.set_shader(base.complexpbr_shader)
TypeError: NodePath.set_shader() argument 1 must be Shader, not NoneType

TypeError: NodePath.set_shader() argument 1 must be Shader, not NoneType

I have the following error traceback when trying to use complexpbr:

"C:\Program Files\Panda3D-1.10.13-x64\python\python.exe" D:\Workspace\Python\project-naer\main.py 
Known pipe types:
  wglGraphicsPipe
(all display modules loaded.)
AL lib: (EE) ALCwasapiPlayback_resetProxy: Audio client returned buffer_len < period*2; expect break up
:shader(error): Could not find shader file: D:\Workspace\Python\project-naer\library\complexpbr\ibl_v.vert
:express(warning): Filename uses Windows-style path: D:\Workspace\Python\project-naer\library\complexpbr\output_brdf_lut.png
:express(warning):   expected Unix-style path: /d/Workspace/Python/project-naer/library/complexpbr/output_brdf_lut.png
:gobj(error): Texture::read() - couldn't read: D:\Workspace\Python\project-naer\library\complexpbr\output_brdf_lut.png
:express(warning): Filename uses Windows-style path: D:\Workspace\Python\project-naer\library\complexpbr\output_brdf_lut.png
:express(warning):   expected Unix-style path: /d/Workspace/Python/project-naer/library/complexpbr/output_brdf_lut.png
:gobj(error): Unable to find texture "D:\Workspace\Python\project-naer\library\complexpbr\output_brdf_lut.png" on model-path /d/Workspace/Python/project-naer;/c/Program Files/Panda3D-1.10.13
-x64/etc/..;/c/Program Files/Panda3D-1.10.13-x64/etc/../models
complexpbr message: Defaulting to dummy LUT.
Traceback (most recent call last):
  File "D:\Workspace\Python\project-naer\main.py", line 213, in <module>
    main = Main()
  File "D:\Workspace\Python\project-naer\main.py", line 56, in __init__
    library.complexpbr.apply_shader(self.render)
  File "D:\Workspace\Python\project-naer\library\complexpbr\__init__.py", line 165, in apply_shader
    complexpbr_rig_init(node, intensity=intensity, lut_fill=lut_fill)
  File "D:\Workspace\Python\project-naer\library\complexpbr\__init__.py", line 128, in complexpbr_rig_init
    node.set_shader(base.complexpbr_shader)
TypeError: NodePath.set_shader() argument 1 must be Shader, not NoneType

Process finished with exit code 1

Here is my code (simplified):

class Main(direct.showbase.ShowBase.ShowBase):

    def __init__(self) -> None:

        super().__init__(self)
        library.complexpbr.apply_shader(self.render)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.