Glow and display regions

Hey everyone,

This bit of code replicates a problem that occurs in my game, switching back and forth from split screen to single screen. It worked well until I added glow to it. The glow seems to mess up the display regions.

from direct.showbase.DirectObject import DirectObject
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters

class World(DirectObject):
    def __init__(self):
        self.accept('space', self.stepScreens)
        self.screens = 1
        self.model = loader.loadModel('model')
        self.model.reparentTo(render)
        
    def stepScreens(self):
        if self.screens == 1:
            self.addScreen()
            self.screens = 2
        elif self.screens == 2:
            self.removeScreen()
            self.screens = 1
            
    def addScreen(self):
        
        #stuff that works
        cam2node = Camera('cam2')
        self.cam2 = NodePath(cam2node)
        self.cam2.reparentTo(base.cam)
        self.cam2.setPos(0, 0, 0)
        self.rtop = base.cam.node().getDisplayRegion(0)
        self.rbottom = base.win.makeDisplayRegion(0, 1, 0, 0.5)
        self.rbottom.setCamera(self.cam2)
        self.rtop.setDimensions(0, 1, 0.5, 1)
        base.cam.node().getLens().setAspectRatio(float(self.rtop.getPixelWidth()) / float(self.rtop.getPixelHeight()))
        self.cam2.node().getLens().setAspectRatio(float(self.rbottom.getPixelWidth()) / float(self.rbottom.getPixelHeight()))
        
        #stuff that doesn't
        render.setShaderAuto()
        self.filters = CommonFilters(base.win, base.cam)
        self.filters.setBloom(blend=(0,0,0,1), desat=0, intensity=1.0, size="small")
        self.filters2 = CommonFilters(base.win, self.cam2)
        self.filters2.setBloom(blend=(0,0,0,1), desat=0, intensity=1.0, size="small")
        
    def removeScreen(self):
        
        #stuff that doesn't work
        self.filters.cleanup()
        self.filters2.cleanup()
        render.setShaderOff()
        
        #stuff that does
        base.win.removeDisplayRegion(self.rbottom)
        self.rtop.setDimensions(0, 1, 0, 1)
        base.cam.node().getLens().setAspectRatio(float(self.rtop.getPixelWidth()) / float(self.rtop.getPixelHeight()))
        self.cam2.removeNode()
        
w = World()
run()

To run the code you will need any model (it just has to be named “model”) in the same location as the program. The default camera controls are still enabled, so you can look around and see what is happening.

EDIT: I suppose I should clarify. While running the program, press space to switch from one display region to two display regions. After switching back and forth several times, the display regions start getting messed up.

Has anyone seen something like this before?

Thanks in advance.

I’ve been working on this, but I still haven’t found a solution. Here is a video of what I get: brisingr.p3dp.com/screen_glitch.wmv

Does anyone know how to fix this?

It looks like you lost the depth buffer in the bottom DisplayRegion. Maybe you should ensure it is explicitly cleared with self.rbottom.setClearDepthActive(True)?

You also might do better by simply creating two DisplayRegions up front and setting the one active or inactive, instead of constantly destroying and creating them.

David

Thanks! Got all the problems fixed for now. :smiley:

I think I will probably pursue this approach as a more permenant fix; it seems much simpler and more reliable.