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.