Problem with volumetric lighting

Hey all

I’m trying to get a volumetric lighting effect to work with the following code:


from direct.directbase.DirectStart import *
from direct.filter.CommonFilters import CommonFilters

class World:
    def __init__(self):
        base.setBackgroundColor(0, 0, 0)
        self.LoadModels()
        taskMgr.add(self.timer, "timer")

    def LoadModels(self):
        self.sun2 = loader.loadModel("models/sphere")
        self.sun2.reparentTo(render)
        self.sun2.setScale(0.9)

        self.filters = None
        self.filters = CommonFilters(base.win, base.cam)
        self.filters.setVolumetricLighting(self.sun2,32,0.7,0.99,0.05)

        self.sun = loader.loadModel("models/sphere")
        self.sun.reparentTo(render)

    def timer(self, task):
        self.sun.setShaderInput("time", task.time)
        return task.cont

World = World()
run()

And the result I’m willing to achieve is the one on the left of this pic. The one I’m getting is the right.

This code was taken from Demomaster’s sun example. When ran via the demomaster’s environment, the result is the one I want (left), and when run as a standalone panda script, I get the right result.

Anyone have any idea on how to fix this?

Try putting “textures-power-2 none” in Config.prc, does that help?

That fixed it, thanks a ton!

Now, is there any way to avoid the rays I circulated in this picture? Like limit the filter to only affect the sun?

You could perhaps create a fullscreen buffer rendering only the sun and then creating your CommonFilters object on that buffer.

In Panda3D 1.8.1 and above, this will be easier; you will be able to render your sun to the stencil buffer or to an auxiliary buffer, and then specify a ‘source = “aux0”’ (or whatever) argument to setVolumetricLighting, or use the output of the bloom stage, like “bloom0”.