Fade from one camera to another

Hey guys,

saw this post: [url]fade from one camera to another?]

And it gave me a good idea on how to fade from one camera perspective to another, and so I wrote a small script (mostly a function) that will do this for you, it’s pretty simply and has a really pleasing effect.



#- Start panda
import direct.directbase.DirectStart

#- Basic imports needed for this function
from direct.interval.IntervalGlobal import *
from panda3d.core import Point3, Vec3, CardMaker

#- Display a model, load your scene, idk
panda = loader.loadModel('environment')


#- over a period of (fadeInDuration) seconds
def fadeCamera(pos, rot, fadeInDuration = 1.0):
	col = base.getBackgroundColor() #- Get the current background color
	cam2 = base.makeCamera(buffer2)

	cm = CardMaker('displayCard')
	cm.setFrame(-1, 1, -1, 1)
	card = render2d.attachNewNode(cm.generate())

	#- Here is where the magic happens
	#- First fade the card with the live scene texture in
	#- Then move the actual camera
	#- Perform all of these in order, using a Sequence
	fadeCardIn = card.colorScaleInterval(fadeInDuration, 1, 0)
	cleanupCamera = Func(cam2.remove)
	cleanupCard = Func(card.remove)
	cleanupBuffer = Func(base.graphicsEngine.removeWindow, buffer2)

#- Place the camera at one perspective
print 'Performing initial fade!'

def doRandomFade():
	#- This part is really un-important
	import random
	tmp = render.attachNewNode('tmp')
	tmp.lookAt(0, 0, 0)
	r = tmp.getHpr()
	fadeCamera(p, r)
	print 'Performing random fade!'

base.accept('space', doRandomFade)


Hope this helps,


Right, they appear to somewhat “pop” out which I find odd (to be honest) I see no reason why they should be doing that, considering it’s a fully solid image coming into view, perhaps someone more experienced with the lower levels of panda’s rendering system could shed some light on this?



Yeah, there’s trickery related to depth sorting involved with transparency. Read the manual page on “Transparency and Blending” for more information.

I’m still a bit new to DXS, but aren’t these already in the API? Because if it isn’t then I 100% believe that it should be.