additive blending

What functions/constants are there to make different run-time-generated geoms additively blend together? Is it the nodepath.setEffect(s)? I am working towards a plasma/blobby-like appearance (2d-like rendertotexture), but cannot find the right combination of settings to do this with. Any help is appreciated. I have done this in other engines not as powerful as panda, so it should be possible…right?

Hmm, not sure what you mean, but if you mean to merge multiple Geom’s together into one Geom, you can try NodePath.flattenLight, flattenMedium and flattenStrong.

I have to guess, but I think I know what he means.

For a given geom you can have multiple textures. And you can control the way how these textures blend together. For example add (additive), add signed, modulate, replace, alpha blend, and so on.

Now what (I think) he means is how the color of an object blend with the color that is behind the object. Default mode is “replace”, and alpha blending can be turned on using setTransparency. But I don’t know if it is possible to use other blend modes, e.g. additive or modulate.

For those who know OGRE: scene_blend add/modulate/alpha_blend/… would be the corresponding setting.

enn0x

To clarify: I am looking for something like this:

mindstormss.googlepages.com/blob

The executable is there, blobby.exe. it should just run(press escape to exit). This was created in Blitz3d, using surfaces (i think like geoms) inside of a mesh to work. The Code:

note that this is not object oriented, and there is a bunch of timing stuff in the mainloop…Look at initialize() and updateGame() for the actual blobby code

;Set these To what you want
Global Objects=30
Global ScrWidth=800
Global ScrHeight=600
Graphics3D ScrWidth,ScrHeight,0,2

;timing stuff
Const GameUPS=60 ; Updates per second
Global Period=1000/GameUPS 
Global FrameTime=MilliSecs()-Period
Global Tween#, Ticks,iter,StartTime,Elapsed

;not object oriented...
Global Image,render2d,mainmesh,brush,tempPivot
Dim mesh(Objects)
Dim vertsx(3)
Dim vertsy(3)
Dim XPos#(Objects)
Dim YPos#(Objects)
Dim XMove#(Objects)
Dim YMove#(Objects)
Dim Rotation#(Objects)
Dim RotationSpeed#(Objects)

initialize()

Repeat
	StartTime = MilliSecs()
	
	Repeat
		Elapsed=MilliSecs()-FrameTime
	Until Elapsed
	
	Ticks=Elapsed / Period
	Tween=Float(Elapsed Mod Period)/Float(Period)
	
	For i=1 To Ticks
		FrameTime=FrameTime+Period
		If i=Ticks Then
			CaptureWorld
		End If
		UpdateGame()
		UpdateWorld
	Next
	RenderWorld Tween
	Flip
Until KeyDown(1)


Function initialize()
	SeedRnd(MilliSecs())
	
	Image=CreateTexture(512,512)
	render2d=CreatePivot()
	mainmesh=CreateMesh(render2d)
	brush=CreateBrush()
	tempPivot=CreatePivot(render2d)
	
	cam = CreateCamera()
	MoveEntity(cam,0,0,-1)
	
	;create the image/texture... 
	SetBuffer(TextureBuffer(Image))
	For Radius#=1 To 512 Step .5
		Energy#=(Radius*Radius)/1024
		Color Energy,Energy,Energy
		Oval Radius/2.0,Radius/2.0,512-Radius,512-Radius     ;Try Rect
	Next
	SetBuffer(BackBuffer())
	
	PositionEntity render2d,-Float(GraphicsWidth())/GraphicsHeight(),1,0 
	ScaleEntity render2d,2.0/GraphicsWidth(),-2.0/GraphicsWidth(),1
	
	;the magic :)
	EntityBlend(mainmesh,3)
	BrushTexture(brush,Image)
	vertsx(0)=0  : vertsy(0)=0
	vertsx(1)=512: vertsy(1)=0
	vertsx(2)=512: vertsy(2)=512
	vertsx(3)=0  : vertsy(3)=512
	
	For i=0 To Objects-1
		mesh(i)=CreateSurface(mainmesh)
		AddVertex(mesh(i),vertsx(0),vertsy(0),0,0,0)
		AddVertex(mesh(i),vertsx(1),vertsy(1),0,1,0,0)
		AddVertex(mesh(i),vertsx(2),vertsy(2),0,1,1,0)
		AddVertex(mesh(i),vertsx(3),vertsy(3),0,0,1,0)
		AddTriangle(mesh(i),0,1,2)
		AddTriangle(mesh(i),2,3,0)
	Next	
	
	;Set up the positions And movement directions/speeds/angles of Objects
	For Obj=0 To Objects-1
		XPos(Obj)=Rand(0,ScrWidth)
		YPos(Obj)=Rand(0,ScrHeight)
		XMove(Obj)=Rnd(-1,1)
		YMove(Obj)=Rnd(-1,1)
		Rotation(Obj)=Rnd(0,360)
		RotationSpeed(Obj)=Rnd(-.2,.2)
	Next
End Function

Function UpdateGame()
	For Obj=0 To Objects-1
		;Move the Objects
		XPos(Obj)=XPos(Obj)+XMove(Obj)
		YPos(Obj)=YPos(Obj)+YMove(Obj)
		
		;Bounce the Objects off the screen edges
		If XPos(Obj)<0 Or XPos(Obj)>ScrWidth Then XMove(Obj)=-XMove(Obj)
		If YPos(Obj)<0 Or YPos(Obj)>ScrHeight Then YMove(Obj)=-YMove(Obj)
		
		;Rotate the Objects around their corners
		Rotation(Obj)=Rotation(Obj)+RotationSpeed(Obj)
		
		;Set Object Color based on coords/angles
		BrushColor(brush,1024-(Rotation(Obj)Mod 256),512-XPos(Obj),512-YPos(Obj))
		PaintSurface(mesh(obj),brush)
		
		;actually update
		RotateEntity(tempPivot,0,0,Rotation(Obj))
		PositionEntity(tempPivot,XPos(Obj),YPos(Obj),0)
		For i=0 To 3
			TFormPoint(vertsx(i),vertsy(i),0,tempPivot,render2d)
			VertexCoords(mesh(Obj),i,TFormedX(),TFormedY(),0)
		Next
		
	Next
End Function

Ah, I think I get what you mean.

You can try this method:

nodepath.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd))

pro using the ColorBlendAttrib.MAdd makes every thing white… i don’t think that is what he wants…

import direct.directbase.DirectStart
from pandac.PandaModules import *
from random import uniform,random
from direct.task import Task

NUMBER_OF_BLOBS = 100
CHANGE_SPEED = .01
 
blobImage = loader.loadTexture('blob.png')
cm = CardMaker("blob maker")
cm.setFrame(-1,1,-1,1)
def generateBlob():
    blob = aspect2d.attachNewNode(cm.generate())
    blob.setX(uniform(-1,1))
    blob.setZ(uniform(-1,1))
    blob.setTransparency(True)
    blob.setTexture(blobImage)
    blob.setR(uniform(0,360))
    #blob.setScale(.5)
    #blob.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd))
    blob.setColor(random(),random(),random(),.2)
    return blob

blobs = [generateBlob() for i in range(NUMBER_OF_BLOBS)]
    
def update_blobs(task):
    for blob in blobs:
        blob.setX(blob.getX()+uniform(-1,1)*CHANGE_SPEED)
        blob.setZ(blob.getZ()+uniform(-1,1)*CHANGE_SPEED)
    return task.cont
    
taskMgr.add(update_blobs, 'update blobs')
run()

MAdd won’t make the object white, but it will add the texture color to the colors of the object behind it, instead of replacing.
I use it in my game for glow/plasma effects as well.