rigidbodycombiner slowdown with color

i have experienced quite a huge speed difference on objects having color or colorscale enabled under a rigidbodycombiner versus having no color enabled. i wondered if that may be a “bug”.

test it using the below code by pressing the “t” button.

from pandac.PandaModules import *
loadPrcFileData('', 'show-frame-rate-meter #t')
loadPrcFileData('', 'sync-video #f')
from direct.directbase import DirectStart

import random
import math

from panda3d.core import *

base.disableMouse()
base.camera.setPos(50,50,180)
base.camera.lookAt(50,50,0)

rigidBodyCombiner = RigidBodyCombiner('rdbc')
rootNode = NodePath(rigidBodyCombiner)
rootNode.reparentTo(render)

cm = CardMaker('card')
cardList = list()
for i in xrange(1000):
  card = rootNode.attachNewNode(cm.generate())
  card.setPos(random.random()*100, random.random()*100, 0)
  card.setHpr(0,-90,0)
  card.setScale(random.random()*4+1)
  if True: # enabling one of the settings halves the framerate
    #card.setColorScale(Vec4(random.random()*4+1, random.random()*math.pi, 0, 1))
    card.setColor(Vec4(random.random()*4+1, random.random()*math.pi, 0, 1))
  card.setTransparency(True)
  cardList.append(card)
rigidBodyCombiner.collect()


COLOR_ENABLED = True
def toggleColor():
  global COLOR_ENABLED
  COLOR_ENABLED = not COLOR_ENABLED
  print 'toggle color '+['on','off'][COLOR_ENABLED]
  if COLOR_ENABLED:
    for card in cardList:
      card.setColor(Vec4(random.random()*4+1, random.random()*math.pi, 0, 1), 1)
  else:
    for card in cardList:
      card.setColorOff(1)
  rigidBodyCombiner.collect()

base.accept('t', toggleColor)

while True:
  taskMgr.step()
  dt = globalClock.getDt()
  for c in cardList:
    c.setPos(c.getPos()+Vec3(random.random()-0.5, random.random()-0.5, 0)*2*dt)

in my PC the colored quads halves the fps and plus, commenting your taskloop and using just the classic run(), the difference increase on a factor of 4.

Setting a different color on each node means you are setting a different state on each node. Since the RBC can only accumulate together nodes that share the same state, it means that you are largely defeating the RBC’s optimization.

Consider using flattenLight() to apply the color change down onto the vertices and remove it from the state, so that all nodes may once again have the same state and be properly optimized by the RBC.

David

i think i have tried that as well. getting about the same results. but i may have forgotten something.

my way would be:

node = rdbc.attachNewNode(cm.generate())
node.setColor(c)
node.flattenStrong()
node.setColorOff(1)

rdbc.collect()

am i missing something?

setColorOff() shouldn’t be necessary, and flattenLight() should be sufficient, but that’s about the right idea.

You can get an idea of the effectiveness of your flattening with rbc.getInternalScene().analyze(). Ideally, there should be only one Geom in that scene.

David

Hypnos, if you’re willing to try a different strategy, you could check out drwr’s strategy on this problem.

discourse.panda3d.org/viewtopic … 6213#56213

I haven’t evaluated it myself completely, but it may be relevant.