Volumetric lighting. How to set it?

I am interested in effects for a while.

I find that setting bloom or cartoon ink is too easy. So I thought it would be nice to try something harder. In reference I have found this:

So I’ve written this:

import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters
class VolumtericLightTest():
    def __init__():
        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)
    def panda():
        pnda = loader.loadModel("panda")
        pnda.reparentTo(render)
        base.camera.lookAt(pnda)
    panda()
run()

And… nothing.

What’s the problem?

Not sure about the lighting, but you need to do a couple other things:

the call to panda() should be inside init so that panda gets called during initialization.

Then you need to instantiate the class:

v=VolumetricLightTest() #<-- in place of the current panda() call
run()

Finally, you may want to do a:

base.camera.setPos(10,0,0)

right before the lookAt(pnda) so that the camera is back away from your object a little bit. Otherwise it gets clipped by the renderer.

–Joe

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()