I have a basic question on using these api. I found that if I call setShaderInput regularly and if one of the child node under this node has the auto shader turned on, the performance of the system will be downgraded significantly.
Can you explain why it happens ? Looks like the autoshader keep recreating the shader program ?
Here is a test program. The FPS is about 454 after the program started. If now press “1”, the FPS goes down to 380. Now press “t”, the FPS goes down to about 8.
from pandac.PandaModules import loadPrcFileData
#loadPrcFileData("", "want-directtools #t")
#loadPrcFileData("", "want-tk #t")
loadPrcFileData("", "sync-video #f")
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.task import Task
from direct.interval.IntervalGlobal import *
import math
from direct.actor.Actor import Actor
class World():
def __init__(self):
self.LoadModel()
base.accept("1", self.setshader1)
base.accept("2", self.setshader2)
base.accept("t", self.startTimeTask)
def startTimeTask(self):
taskMgr.add(self.setTime, "settime")
def LoadModel(self):
base.setBackgroundColor(255, 0, 0)
base.disableMouse()
base.cam.setPos(0, -25, 1.5)
self.actor= Actor('panda.egg', {'walk' : 'panda-walk.egg'})
self.actor.setScale(0.25,0.25,0.25)
self.actor.reparentTo(render)
self.actor.loop("walk")
base.camera.lookAt(self.actor.getPos())
maker = CardMaker( 'leaf' )
maker.setFrame( 0, 1, 0, 1)
self.ground = render.attachNewNode(maker.generate())
self.ground.setPos(Vec3(-50,0,0))
self.ground.setHpr(0,-90,0)
self.ground.setScale(100,100,1)
dlight = NodePath(DirectionalLight('dlight'))
dlight.reparentTo(base.cam)
render.setLight(dlight)
##
## plight = PointLight('plight')
## plight.setColor(VBase4(0.4, 0.4, 0.4, 1))
## #plight.setAttenuation(Point3(0, 0, 0.01))
## plnp = render.attachNewNode(plight)
## plnp.setPos(0, 5, 5)
## render.setLight(plnp)
def setshader1(self):
render.setShaderAuto()
def setshader2(self):
self.actor.setShaderAuto()
def setTime(self, task):
render.setShaderInput('time', task.time)
return task.cont
world = World()
run()