Vertex Colors and RenderModeThickness

I’ve made a targeting laser for my game with some simple eggData code. It’s just an EggLine with 2 vertices and the RenderModeThickness turned up. I successfully applied a gradient glow map to it so that it glows more at the base and less at the tip, but applying a texture with a gradient alpha to it with a texture stage set to modulate doesn’t seem to give it any alpha. I’m wondering if I could use vertex coloring to make the tip of it transparent? If so, how would I accomplish that?

I’m guessing the answer is no, that RenderModeThickness will override it or bypass it or something, but hopefully I’m wrong.

I don’t know why RenderModeThickness would impact the vertex color. You should be able to set a different value for each color in the egg file, and see the results immediately.

David

How would I do that? The API doesn’t show any setColor or some such methods for the EggVertex class.

EggVertex inherits from EggAttributes, which has a set_color() method.

David

Ah, okay. Thanks.

Yeah, that works for the transparency, but the bloom filter stops picking it up too, so I get no glow.

Is there a way I can reconcile the two to work together?

Hmm, I’m not sure what you’re going for. I believe the bloom filter uses the alpha channel to indicate the amount of glow, and this is the same alpha channel that also indicates the amount of transparency when transparency is enabled. So you can’t have both glow and transparency on the same object, unless the glowing parts are also the non-transparent parts.

David

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()