Performances problem with shadows and texture offset

Hello, I’ve a performance problem. I’ve this simple application: a quad with a texture on it, and the offset of the texture changes. This is the code:

from panda3d.core import TextureStage
from pandac.PandaModules import Spotlight

from panda3d.core import loadPrcFileData
loadPrcFileData( '', 'want-pstats 1' )
loadPrcFileData( '', 'show-frame-rate-meter #t' )

import direct.directbase.DirectStart

camera.setPos( 0, -2.5, 2.5 )
camera.setHpr( 0, -48, 0)

model = loader.loadModel( 'quad' )
model.reparentTo( render )

ts = TextureStage('ts')
model.setTexture( ts, loader.loadTexture('img2.jpg') )

offset = 0
def update( task ):
  global offset
  offset += .001
  model.setTexOffset( ts, offset, offset )
  return task.cont
taskMgr.add( update, 'TextureUpdate' )

def setupLight():  
  light = render.attachNewNode( Spotlight( 'Spot' ) )
  light.setPos( ( 20, 20, 20 ) )
  light.lookAt( 0,0,0 )
  light.node().setShadowCaster( True, 1024, 1024 )
  render.setLight( light )

  # it costs 2 ms without the texture movement and 8 ms with that

  # it costs 2 ms without the texture movement and 30 ms with that


I would like to see these two effects: shadows and texture offset. Both cost few milliseconds if used separately, but, if I use them together then the performances drop (and I can’t use them in real contexts :frowning: ).

For example, with render.setShaderAuto() and lighting each frame costs 28 ms more.

Here’s the complete code with resources.

Is my lighting setup wrong? Thank you!

The problem is that the setTexOffset() call changes the render state every frame, which when applied to a node that also has setShaderAuto() in effect, means that the auto-shader has to be recomputed every frame.

Solution: don’t apply setShaderAuto() to the same node that receives the setTexOffset() call. For instance, specify:



Thank you David! Now performances are OK. This solution implies that the quad doesn’t receive shadows, is it right? Is there a way to get shadows and variable texture offset?

You’ll have to apply a custom shader to the quad to avoid the problem of the auto-shader.


Ok, thanks!