My objective is to simulate the phenomenon that occurs when you call show() on a collision ray with the bloom filter active. You get a pixel thin line that fades away toward the tip, with a large bloom at the base that also fades away toward the tip. The only problem is you can only get it in white through that method, and I want it in red. I think it would be a cool effect for a laser sight.
I’ve got it pretty much figured out now. Instead of creating a single line, I’m creating two lines. One goes on the end of the other. The first line I set up to glow, the second line I set up to fade into transparency. It’s pretty close to what I’m after. My only regret is that I can’t get the glow to cover the whole thing, and fade out with the transparency, but from what you’ve said and my own experimentation I don’t think that’s possible.
I’ll go with what I have, thanks again.
If you’re curious about what i was trying to accomplish still, here’s some example code to show you. It requires a single image, for which I used a 32x32 png that is all white, with no alpha, and set to greyscale.
import direct.directbase.DirectStart
from pandac.PandaModules import *
from direct.filter.CommonFilters import CommonFilters
class Example:
def __init__(self):
base.setBackgroundColor(0, 0, 0)
# Sets the background color to black to make it easier to see things.
base.disableMouse()
self.filters = CommonFilters(base.win, base.cam)
filterok = self.filters.setBloom(blend=(0,0,0,1),
desat=-0.5, intensity=3.0, size=2, mintrigger=0)
render.setShaderAuto()
base.camera.setPos(-100, -100, 0)
base.camera.setH(-60)
self.setupEggDataExample()
self.setupColRayExample()
def setupEggDataExample(self):
self.laserData1 = EggData()
self.laserVP1 = EggVertexPool("Laser Vertex Pool 1")
self.laserData1.addChild(self.laserVP1)
self.laserData2 = EggData()
self.laserVP2 = EggVertexPool("Laser Vertex Pool 2")
self.laserData2.addChild(self.laserVP2)
vert1 = EggVertex()
vert1.setPos(Point3D(0,0,5))
vert1.setUv(Point2D(0, 0))
self.laserVP1.addVertex(vert1)
vert2 = EggVertex()
vert2.setPos(Point3D(90,0,5))
vert2.setUv(Point2D(1, 1))
self.laserVP1.addVertex(vert2)
vert3 = EggVertex()
vert3.setPos(Point3D(90,0,5))
vert3.setUv(Point2D(0, 0))
vert3.setColor(VBase4(1,0,0,1))
self.laserVP2.addVertex(vert3)
vert4 = EggVertex()
vert4.setPos(Point3D(100,0,5))
vert4.setUv(Point2D(1, 1))
vert4.setColor(VBase4(1,0,0,0))
self.laserVP2.addVertex(vert4)
line = EggLine()
self.laserData1.addChild(line)
line.addVertex(self.laserVP1.getVertex(0))
line.addVertex(self.laserVP1.getVertex(1))
line = EggLine()
self.laserData2.addChild(line)
line.addVertex(self.laserVP2.getVertex(0))
line.addVertex(self.laserVP2.getVertex(1))
self.laserData1.setCoordinateSystem(CSDefault)
self.laserData2.setCoordinateSystem(CSDefault)
self.laserData1.writeEgg(Filename("TargetingLaser1.egg"))
self.laserData2.writeEgg(Filename("TargetingLaser2.egg"))
self.model1 = loader.loadModel("TargetingLaser1.egg")
self.model2 = loader.loadModel("TargetingLaser2.egg")
self.model1.setRenderModeThickness(1)
self.model1.reparentTo(render)
self.model1.setLightOff()
self.model1.setColor(1,0,0,1)
self.model1.setZ(2)
self.model2.setRenderModeThickness(1)
self.model2.reparentTo(render)
self.model2.setLightOff()
self.model2.setZ(2)
self.glowTex = loader.loadTexture("White.png")
self.glowTex.setFormat(Texture.FAlpha)
self.glowTS = TextureStage("glowTS")
self.glowTS.setMode(TextureStage.MGlow)
self.model1.setTexture(self.glowTS, self.glowTex)
def setupColRayExample(self):
self.CN = CollisionNode("RayCN")
self.cRay = CollisionRay(Point3(0,0,-5), Vec3(1,0,0))
self.CN.addSolid(self.cRay)
self.CN.setFromCollideMask(BitMask32.bit(0))
self.CN.setIntoCollideMask(BitMask32.allOff())
self.CNP = render.attachNewNode(self.CN)
self.CNP.show()
E = Example()
run()