Here is some non shader code to draw outlines. It only works in opengl though. Basically, it draws every object twice. On the first draw, the object is drawn normally except it sets the stencil mask to mark out the parts of the screen that have been drawn. The second draw, draws the same object again but slightly bigger in wireframe mode. By checking the stencil buffer during the second draw, the larger object is only shown on the screen in areas untouched by the first object, thus outlining the first object.
In Panda, drawing an object again requires a second camera.
from pandac.PandaModules import loadPrcFileData
import direct.directbase.DirectStart
from panda3d.core import *
#Draw smiley and mark the stencil
npModel = __builtin__.loader.loadModel('smiley')
npModel.reparentTo( __builtin__.render )
npModel.setAttrib( StencilAttrib.make(1,StencilAttrib.SCFAlways,StencilAttrib.SOZero, StencilAttrib.SOKeep,StencilAttrib.SOReplace, 8, 255, 255) )
__builtin__.base.cam.node().setActive(1)
#Setup a false node to setup some initial states
temp = NodePath('')
temp.setTextureOff( 100 )
temp.setColor( 0, 1, 0, 1)
temp.setAttrib( RenderModeAttrib.make( RenderModeAttrib.MWireframe, thickness = 5 ), 1 )
### Don't forget to override the priority of the stencil buffer
temp.setAttrib( StencilAttrib.make(1, StencilAttrib.SCFGreaterThan, StencilAttrib.SOKeep, StencilAttrib.SOKeep,StencilAttrib.SOKeep, 8, 255, 255), 1)
temp.setDepthTest( False )
temp.setDepthWrite( False )
temp.setScale(1.2)
#Make a new camera and inherit the node states from the false node
npCamera = __builtin__.base.makeCamera( __builtin__.base.win, sort = 1, lens = __builtin__.base.camLens, scene = __builtin__.render)
npCamera.node().setInitialState( temp.getState() )
npCamera.node().getDisplayRegion(0).disableClears()
#The two cameras have to be aligned in the same spot at all times.
#Use a task to do this every frame if base.cam moves.
__builtin__.base.cam.setPos( 0, -10, 0)
npCamera.setPos( 0, -10, 0)
print "Stencil Clear Value", __builtin__.base.win.getClearStencil()
print "Stencil Clear Active", __builtin__.base.win.getClearStencilActive()
run()
For lighting shaders, I suggest you google for a free copy of NVidia’s excellent introductory shader book called “The Cg Tutorial”.
[quote]
→ A more complicated thing: a screenshot will explain it better:
http://livingwithanerd.com/wp-content/uploads/2010/10/fallout-2-screenshot.jpg
The walls around the playing characters are fading out. I need to implement this as well.
[quote]
Once you master the outline stencil approach, you can do this without a shader.
Prioritize your draw such that
- Draw the floor + figure first
- Draw a black ball in the same location as the figure and set the stencil buffer to mark that part of the screen. The black ball should be drawn using using ColorBlendAttrib(ColorBlendAttrib.MAdd) such that the black ball doesn’t affect the color of the screen. (Black + Any Color = Unchanged color) We only want to use the black ball to mark the stencil buffer.
- Draw the walls with the stencil rejection set in the same way as the outline method above and now the walls will not draw over the character! Hence, looking transparent.
[/code]