Glow and display regions

Return to Scripting Issues

Glow and display regions

Postby Brisingr » Sat Mar 10, 2012 9:54 am

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.
Code: Select all
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.
Brisingr
 
Posts: 37
Joined: Thu Aug 05, 2010 12:29 pm

Postby Brisingr » Sun Mar 11, 2012 3:43 pm

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

Does anyone know how to fix this?
Brisingr
 
Posts: 37
Joined: Thu Aug 05, 2010 12:29 pm

Postby drwr » Tue Apr 24, 2012 12:55 pm

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
drwr
 
Posts: 11425
Joined: Fri Feb 13, 2004 12:42 pm
Location: Glendale, CA

Postby Brisingr » Wed Apr 25, 2012 6:44 pm

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

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

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.


I think I will probably pursue this approach as a more permenant fix; it seems much simpler and more reliable.
Brisingr
 
Posts: 37
Joined: Thu Aug 05, 2010 12:29 pm


Return to Scripting Issues

Who is online

Users browsing this forum: Bing [Bot] and 0 guests