Volumetric lighting. How to set it?

1.)I didn’t want to set-up the camera before I’d fix up the lighting.
2.)When I instanced the class I had an error:
NameError: name ‘VolumetricLightTest’ is not defined

I got that too. The spelling in your class definition was incorrect. Here is the code that I have so far:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters
class VolumetricLightTest():
    def __init__(self):
        fltr = CommonFilters(base.win, base.cam)
        fltr.setVolumetricLighting(0,32,5.0,0.1,0.1)
        alight = AmbientLight('amibent')
        alight.setColor(VBase4(0.3, 0.3, 0.3, 1))
        alnp = render.attachNewNode(alight)
        plight = PointLight('point')
        plight.setColor(VBase4(0.8, 0.8, 0.8, 1))
        plnp = render.attachNewNode(plight)
        plight.setPos(0, 0, 1)
        render.setLight(alnp)
        self.panda()
    def panda():
        pnda = loader.loadModel("panda")
        pnda.reparentTo(render)
        base.camera.setPos(10,0,0)
        base.camera.lookAt(pnda)
v=VolumetricLightTest()
run()

At this point, it still fails to run, giving:

Traceback (most recent call last):
  File "VLT.py", line 22, in <module>
    v=VolumetricLightTest()
  File "VLT.py", line 7, in __init__
    fltr.setVolumetricLighting(0,32,5.0,0.1,0.1)
AttributeError: CommonFilters instance has no attribute 'setVolumetricLighting'

Even though it is in the reference.

At this point, I will have to turn it over to someone more knowledgeable than I with regards to the lighting effects.

The first argument to setVolumetricLighting should be a NodePath.
You need to create a sphere, make it the color of the sun, reparent it to your light (or reparent your light to it), and pass it as first parameter.

thank you.

how will it effect on the normal mapping example?

if I will tell it that the sun is that shining ball?

Like this.
pro-rsoft.com/screens/normal-map … llight.png

I see there’s still a bug, so I had to insert this before the DirectStart call:

from pandac.PandaModules import loadPrcFileData
loadPrcFileData("", "textures-power-2 none")

I used these parameters:

        # create a sphere to denote the light
        sphere = loader.loadModel("models/sphere")
        sphere.reparentTo(plnp)
        
        cf = CommonFilters(base.win, base.cam)
        cf.setVolumetricLighting(sphere,32,0.5,1.0,0.05)

Note that the current implementation of volumetric lighting lacks a good occlusion-only pass (if you have a bright scene you will notice it) but this will be fixed soon.

This is really ahem:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters
alight = AmbientLight('amibent') 
alight.setColor(VBase4(3, 3, 3, 1)) 
alnp = render.attachNewNode(alight)
plight = PointLight('point')
plight.setColor(VBase4(0.8, 0.8, 0.8, 1))
plnp = render.attachNewNode(plight)
plnp.setPos(0, 0, 1)
render.setLight(alnp)
pnda = loader.loadModel("panda")
pnda.reparentTo(plnp)
base.camera.lookAt(pnda)
fltr = CommonFilters(base.win, base.cam)
fltr.setVolumetricLighting(pnda, 32, 5.0, 0.1, 0.1)
run()

EDIT:
almost the same happens with the normal mapping example, maybe my graphics card is not capable for that?

EDIT2:
if the same thing does not happen to you:

Oh, you might need to put this in Config.prc:

basic-shaders-only #f

By default, panda restricts shaders to the most ancient profiles ever (gack).

Also, from the screenshot I can tell that you did not set “textures-power-2” to “none”.

I ended up like an idiot.

Again.

And yes, it works! And how!

Thanks pro-rsoft.
[size=75]I wonder, you have 3000+ posts, and your’re still not, at least, a V.I.P?[/size]

I find a task is created in CommonFilters:

self.task = taskMgr.add(self.update, “common-filters-update”)

and it is not removed in cleanup().

Hence I get an error when use Volumetric light when I want to remove it:

File “d:\panda3D-1.6.2\direct\filter\CommonFilters.py”, line 240, in update
self.finalQuad.setShaderInput(“casterpos”, Vec4(casterpos.getX() * 0.5 + 0.5
, (casterpos.getY() * 0.5 + 0.5), 0, 0))
AttributeError: ‘NoneType’ object has no attribute ‘setShaderInput’

Is it a bug or you expect user to clean it up in their code instead ? Thank you.

My mistake. I didn’t think there could be a case where there are still filters turned on when cleaned up.
I’ll fix this bug for the next release.

I know this is an old thread, but I haven’t found any clearly newer ones to deal with volumetric lighting.
For several days I have been trying to figure out how to set volumetric lighting in Panda3D. I tried, say, the last example by @MentalDisaster from this thread:

I copied and used it exactly as in this post, only so as not to have to manually zoom out the camera each time, I added a line of code:

base.cam.setPos(0, -28, 8)

The effect of this code is as follows:


It seemed to me that volumetric lighting should make a given object begin to cast visible light rays. Something like:

Instead, against the background of the object, I see some faded copy of it.
Is this really what it should look like? Is this how the Volumetric Lighting filter works in Panda3D? Because maybe it’s not a bug, but a feature and I have wrong expectations?
Since I read that the caster should be basically a light source, I changed the line setting the volumetric lighting filter to:

fltr.setVolumetricLighting(plnp, 32, 5.0, 0.1, 0.1)

However, the effect is basically the same in my opinion:


Oh, one more thing - this code throws such warnings to the console:

Warning: pandac.PandaModules is deprecated, import from panda3d.core instead
:ShowBase(warning): run() is deprecated, use base.run() instead

But I don’t think this affects volumetric lighting, does it?

It just requires careful setup.

from panda3d.core import *
loadPrcFileData("", "textures-power-2 none")

from direct.showbase.ShowBase import ShowBase
from direct.filter.CommonFilters import CommonFilters

base = ShowBase()

plnp = NodePath('VolumetricLighting')
plnp.setPos(0, 25, 5)

pnda = loader.loadModel("panda")
pnda.reparentTo(render)

fltr = CommonFilters(base.win, base.cam)
fltr.setVolumetricLighting(plnp, 128, 5.0, 0.7, 1.0)

base.run()

Result:

2 Likes

Thank you. But… A strange thing: I do not observe this Volumetric Lighting effect on my setup. I copied EXACTLY your code and after running (and manually centring the panda object) I see something completely different:


I have no errors on the console.

Known pipe types:
  CocoaGraphicsPipe
(all display modules loaded.)

Process finished with exit code 0

Does anyone have any idea?

Perhaps this line at the very beginning will help you.

loadPrcFileData("", "basic-shaders-only #f")

from panda3d.core import *
loadPrcFileData("", "textures-power-2 none")
loadPrcFileData("", "basic-shaders-only #f")

from direct.showbase.ShowBase import ShowBase
from direct.filter.CommonFilters import CommonFilters

base = ShowBase()

plnp = NodePath('VolumetricLighting')
plnp.setPos(0, 25, 5)

pnda = loader.loadModel("panda")
pnda.reparentTo(render)

fltr = CommonFilters(base.win, base.cam)
fltr.setVolumetricLighting(plnp, 128, 5.0, 0.7, 1.0)

base.run()

Thank you, but unfortunately… Same effect:

I think you need to determine the capabilities of your OS system, there may be limitations.

If the third version of GL is supported, it is better to explicitly install the profile.

from panda3d.core import *
loadPrcFileData("", "textures-power-2 none")
loadPrcFileData("", "basic-shaders-only #f")
loadPrcFileData("", "gl-version 3 2")


from direct.showbase.ShowBase import ShowBase
from direct.filter.CommonFilters import CommonFilters

base = ShowBase()

plnp = NodePath('VolumetricLighting')
plnp.setPos(0, 25, 5)

pnda = loader.loadModel("panda")
pnda.reparentTo(render)

fltr = CommonFilters(base.win, base.cam)
fltr.setVolumetricLighting(plnp, 128, 5, 0.5, 1)

base.run()
1 Like

Thank you, but actually it is even worse now - I mean no effect at all:


My setup is MacBook Pro (13-inch, M1, 2020), macOS Monterey, Version 12.6.

As far as I know, this is not suitable for running serious games, only casual and so on.

You can get more information about the graphical capabilities by running this code.

from panda3d.core import loadPrcFileData
loadPrcFileData("", "notify-level-glgsg debug")

from direct.showbase.ShowBase import ShowBase

base = ShowBase()
base.run()

There is comprehensive information on Apple software here.

Logically, you will have a maximum GL profile of 4.1

from panda3d.core import *
loadPrcFileData("", "textures-power-2 none")
loadPrcFileData("", "basic-shaders-only #f")
loadPrcFileData("", "gl-version 4 1")


from direct.showbase.ShowBase import ShowBase
from direct.filter.CommonFilters import CommonFilters

base = ShowBase()

plnp = NodePath('VolumetricLighting')
plnp.setPos(0, 25, 5)

pnda = loader.loadModel("panda")
pnda.reparentTo(render)

fltr = CommonFilters(base.win, base.cam)
fltr.setVolumetricLighting(plnp, 128, 5, 0.5, 1)

base.run()

The question remains which version the CommonFilters requires.

Thanks for all the hints. In practice, I’m not going to code serious games. My area of ​​interest is using Panda3D for the demoscene. And I even managed to achieve something with Panda3D:

But now I just dreamed of creating more advanced effects.
I ran this code which prints "notify-level-glgsg debug". I don’t understand much of it, but here’s what turned out:

/Users/miklesz/PycharmProjects/Demo2023/venv/bin/python /Users/miklesz/PycharmProjects/Demo2023/volumetric_4.py 
Known pipe types:
  CocoaGraphicsPipe
(all display modules loaded.)
:display:gsg:glgsg(debug): GL_VENDOR = Apple
:display:gsg:glgsg(debug): GL_RENDERER = Apple M1
:display:gsg:glgsg(debug): GL_VERSION = 2.1 Metal - 76.3
:display:gsg:glgsg(debug): GL_VERSION decoded to: 2.1
:display:gsg:glgsg(debug): GL_SHADING_LANGUAGE_VERSION = 1.20
:display:gsg:glgsg(debug): Detected GLSL version: 1.20
:display:gsg:glgsg(debug): Using compatibility profile
:display:gsg:glgsg(debug): GL Extensions:
  GL_APPLE_aux_depth_stencil             GL_APPLE_client_storage
  GL_APPLE_element_array                 GL_APPLE_fence
  GL_APPLE_float_pixels                  GL_APPLE_flush_buffer_range
  GL_APPLE_flush_render                  GL_APPLE_packed_pixels
  GL_APPLE_pixel_buffer                  GL_APPLE_rgb_422
  GL_APPLE_row_bytes                     GL_APPLE_specular_vector
  GL_APPLE_texture_range                 GL_APPLE_transform_hint
  GL_APPLE_vertex_array_object           GL_APPLE_vertex_point_size
  GL_APPLE_vertex_program_evaluators     GL_APPLE_ycbcr_422
  GL_ARB_color_buffer_float              GL_ARB_depth_buffer_float
  GL_ARB_depth_clamp                     GL_ARB_depth_texture
  GL_ARB_draw_buffers                    GL_ARB_draw_elements_base_vertex
  GL_ARB_draw_instanced                  GL_ARB_fragment_program
  GL_ARB_fragment_program_shadow         GL_ARB_fragment_shader
  GL_ARB_framebuffer_object              GL_ARB_framebuffer_sRGB
  GL_ARB_half_float_pixel                GL_ARB_half_float_vertex
  GL_ARB_imaging                         GL_ARB_instanced_arrays
  GL_ARB_multisample                     GL_ARB_multitexture
  GL_ARB_occlusion_query                 GL_ARB_pixel_buffer_object
  GL_ARB_point_parameters                GL_ARB_point_sprite
  GL_ARB_provoking_vertex                GL_ARB_seamless_cube_map
  GL_ARB_shader_objects                  GL_ARB_shader_texture_lod
  GL_ARB_shading_language_100            GL_ARB_shadow
  GL_ARB_shadow_ambient                  GL_ARB_sync
  GL_ARB_texture_border_clamp            GL_ARB_texture_compression
  GL_ARB_texture_compression_rgtc        GL_ARB_texture_cube_map
  GL_ARB_texture_env_add                 GL_ARB_texture_env_combine
  GL_ARB_texture_env_crossbar            GL_ARB_texture_env_dot3
  GL_ARB_texture_float                   GL_ARB_texture_mirrored_repeat
  GL_ARB_texture_non_power_of_two        GL_ARB_texture_rectangle
  GL_ARB_texture_rg                      GL_ARB_transpose_matrix
  GL_ARB_vertex_array_bgra               GL_ARB_vertex_blend
  GL_ARB_vertex_buffer_object            GL_ARB_vertex_program
  GL_ARB_vertex_shader                   GL_ARB_window_pos
  GL_ATI_separate_stencil                GL_ATI_texture_env_combine3
  GL_ATI_texture_float                   GL_EXT_abgr
  GL_EXT_bgra                            GL_EXT_bindable_uniform
  GL_EXT_blend_color                     GL_EXT_blend_equation_separate
  GL_EXT_blend_func_separate             GL_EXT_blend_minmax
  GL_EXT_blend_subtract                  GL_EXT_clip_volume_hint
  GL_EXT_debug_label                     GL_EXT_debug_marker
  GL_EXT_draw_buffers2                   GL_EXT_draw_range_elements
  GL_EXT_fog_coord                       GL_EXT_framebuffer_blit
  GL_EXT_framebuffer_multisample         GL_EXT_framebuffer_multisample_blit_scaled
  GL_EXT_framebuffer_object              GL_EXT_framebuffer_sRGB
  GL_EXT_geometry_shader4                GL_EXT_gpu_program_parameters
  GL_EXT_gpu_shader4                     GL_EXT_multi_draw_arrays
  GL_EXT_packed_depth_stencil            GL_EXT_packed_float
  GL_EXT_provoking_vertex                GL_EXT_rescale_normal
  GL_EXT_secondary_color                 GL_EXT_separate_specular_color
  GL_EXT_shadow_funcs                    GL_EXT_stencil_two_side
  GL_EXT_stencil_wrap                    GL_EXT_texture_array
  GL_EXT_texture_compression_dxt1        GL_EXT_texture_compression_s3tc
  GL_EXT_texture_env_add                 GL_EXT_texture_filter_anisotropic
  GL_EXT_texture_integer                 GL_EXT_texture_lod_bias
  GL_EXT_texture_rectangle               GL_EXT_texture_sRGB
  GL_EXT_texture_sRGB_decode             GL_EXT_texture_shared_exponent
  GL_EXT_timer_query                     GL_EXT_transform_feedback
  GL_EXT_vertex_array_bgra               GL_IBM_rasterpos_clip
  GL_NV_blend_square                     GL_NV_conditional_render
  GL_NV_depth_clamp                      GL_NV_fog_distance
  GL_NV_fragment_program2                GL_NV_fragment_program_option
  GL_NV_light_max_exponent               GL_NV_texgen_reflection
  GL_NV_texture_barrier                  GL_NV_vertex_program2_option
  GL_NV_vertex_program3                  GL_SGIS_generate_mipmap
  GL_SGIS_texture_edge_clamp             GL_SGIS_texture_lod
  GL_SGI_color_matrix
:display:gsg:glgsg(debug): HAS EXT GL_EXT_debug_marker 1
:display:gsg:glgsg(debug): HAS EXT GL_KHR_debug 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_debug_output 0
:display:gsg:glgsg(debug): gl-debug disabled and unsupported.
:display:gsg:glgsg(debug): HAS EXT GL_ARB_ES3_compatibility 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_texture_storage 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_clear_texture 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_clear_buffer_object 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_texture_array 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_seamless_cube_map 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_texture_cube_map_array 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_texture_buffer_object 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_texture_compression_rgtc 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_array_bgra 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_type_10f_11f_11f_rev 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_framebuffer_object 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_map_buffer_range 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_buffer_storage 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_array_object 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_tessellation_shader 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_geometry_shader4 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_geometry_shader4 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_program 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_fragment_program 1
:display:gsg:glgsg(debug): HAS EXT GL_NV_gpu_program5 0
:display:gsg:glgsg(debug): HAS EXT GL_NV_gpu_program4 0
:display:gsg:glgsg(debug): HAS EXT GL_NV_vertex_program3 1
:display:gsg:glgsg(debug): HAS EXT GL_NV_fragment_program2 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_compute_shader 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_gpu_shader4 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_attrib_64bit 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_vertex_attrib_binding 0
:display:gsg:glgsg(debug): HAS EXT ARB_shader_storage_buffer_object 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_instanced_arrays 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_draw_instanced 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_draw_indirect 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_framebuffer_object 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_direct_state_access 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_framebuffer_no_attachments 0
:display:gsg:glgsg(debug): HAS EXT GL_NV_framebuffer_multisample_coverage 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_viewport_array 0
:display:gsg:glgsg(debug): Occlusion query counter provides 32 bits.
:display:gsg:glgsg(debug): HAS EXT GL_ARB_timer_query 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_blend_func_extended 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_texture_mirror_clamp 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_texture_mirror_clamp_to_edge 0
:display:gsg:glgsg(debug): max texture dimension = 16384, max 3d texture = 2048, max 2d texture array = 2048, max cube map = 16384
:display:gsg:glgsg(debug): max_elements_vertices = 1048575, max_elements_indices = 150000
:display:gsg:glgsg(debug): vertex buffer objects are supported.
:display:gsg:glgsg(debug): Supported compressed texture formats:
  GL_COMPRESSED_RGB_S3TC_DXT1_EXT
  GL_COMPRESSED_RGBA_S3TC_DXT3_EXT
  GL_COMPRESSED_RGBA_S3TC_DXT5_EXT
:display:gsg:glgsg(debug): HAS EXT GL_EXT_texture_filter_anisotropic 1
:display:gsg:glgsg(debug): HAS EXT GL_ARB_shader_image_load_store 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_shader_image_load_store 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_sampler_objects 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_multi_bind 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_internalformat_query2 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_bindless_texture 0
:display:gsg:glgsg(debug): HAS EXT GL_ARB_get_program_binary 0
:display:gsg:glgsg(debug): HAS EXT GL_EXT_stencil_two_side 1
:display:gsg:glgsg(debug): max lights = 8
:display:gsg:glgsg(debug): max clip planes = 6
:display:gsg:glgsg(debug): max texture stages = 8
:display:gsg:glgsg(debug): No program binary formats supported.
:display:gsg:glgsg(debug): HAS EXT GL_NV_gpu_program5 0
:display:gsg:glgsg(debug): HAS EXT GL_NV_gpu_program4 0
:display:gsg:glgsg(debug): HAS EXT GL_NV_fragment_program2 1
:display:gsg:glgsg(debug): Supported Cg profiles:
:display:gsg:glgsg(debug):   arbvp1
:display:gsg:glgsg(debug):   fp40
:display:gsg:glgsg(debug):   arbfp1
:display:gsg:glgsg(debug):   vp40
:display:gsg:glgsg(debug):   glslv
:display:gsg:glgsg(debug):   glslf
:display:gsg:glgsg(debug):   glslg
:display:gsg:glgsg(debug): Cg GLSL version = CG_GL_GLSL_120
:display:gsg:glgsg(debug): Cg latest vertex profile = vp40
:display:gsg:glgsg(debug): Cg latest fragment profile = fp40
:display:gsg:glgsg(debug): Cg latest geometry profile = unknown
:display:gsg:glgsg(debug): basic-shaders-only #f
:display:gsg:glgsg(debug): Cg active vertex profile = vp40
:display:gsg:glgsg(debug): Cg active fragment profile = fp40
:display:gsg:glgsg(debug): Cg active geometry profile = unknown
:display:gsg:glgsg(debug): shader model = 3.0
:display:gsg:glgsg(debug): GLGraphicsStateGuardian 0x7fda93815210 destructing

Process finished with exit code 0

I also tried to force "gl-version 4 1" but the effect was like forcing "gl-version 3 2" (which is none, unfortunately).
Based on this thread from Stack Overflow, I realized that Mac in general has problems with OpenGL and the solution could be Vulkan. Therefore, I can see 3 solutions:

  1. Someone will give me an else idea.
  2. I will wait for the new shader pipeline based on Vulkan, which has been announced by @rdb for some time:
    The Year 2021 in Review | Panda3D
  3. I will not see any other solutions and maybe I will write a shader from scratch that implements Volumetric Lighting on the old OpenGL (which would be a solution, although probably quite desperate).