Is there a limit to the number of setTexProjector calls you can make on a NodePath, or any limitations on any of the components there of, that could cause odd behavior?
The reason I ask is because I set up some simple shadowing using texture projection, and I’m getting an error I can’t wrap my head around. I have 4 vehicles racing along a track. They are 4 instances of the same class. In that class is a function that sets up a “shadow” as a texture projected onto the track. When I run the game, 2 of the vehicles have a proper shadow. 1 has no shadow. 1 has 2 shadows (or, sometimes, one shadow). I am making the assertion that it is 2 shadows because it is much more opaque than it should be, but is still showing some transparency on the edges where the image is fuzziest.
Here’s the code in the vehicle class that creates the shadow. Note that I refer to shadows as light, because my vehicles have glowing crap on the bottom and therefore should cast light, not shadow. Functionally, it’s the same as a shadow.
def setupLight(self):
self.lightCaster = render.attachNewNode(LensNode("Light Caster"))
lens = PerspectiveLens()
self.lightCaster.node().setLens(lens)
self.lightCaster.reparentTo(self.model)
self.lightCaster.setPos(0, 0, 10)
self.lightCaster.setHpr(0, -90, 0)
tex = loader.loadTexture("Images/Utilities/Shadow.png")
tex.setWrapU(Texture.WMBorderColor)
tex.setWrapV(Texture.WMBorderColor)
tex.setBorderColor(VBase4(0, 0, 0, 0))
self.projTS = self.track.getTexProjection()
self.track.track.setTexture(self.projTS, tex)
self.track.track.setTexProjector(self.projTS, NodePath(), self.lightCaster)
And this is the getTexProjection method of the track class that it calls:
def getTexProjection(self):
projTS = TextureStage("ProjTexStage")
projTS.setMode(TextureStage.MDecal)
self.track.setTexGen(projTS, TexGenAttrib.MWorldPosition)
return(projTS)
Any thoughts on how I could possibly be misplacing a shadow onto another vehicle, or losing it entirely?