def __init__(self): base.disableMouse() base.cam.node().getLens().setNear(10.0) base.cam.node().getLens().setFar(200.0) camera.setPos(0, -50, 0) # Check video card capabilities. if (base.win.getGsg().getSupportsBasicShaders() == 0): addTitle("Toon Shader: Video driver reports that shaders are not supported.") return # Enable a 'light ramp' - this discretizes the lighting, # which is half of what makes a model look like a cartoon. # Light ramps only work if shader generation is enabled, # so we call 'setShaderAuto'. tempnode = NodePath(PandaNode("temp node")) tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4)) tempnode.setShaderAuto() base.cam.node().setInitialState(tempnode.getState()) # Use class 'CommonFilters' to enable a cartoon inking filter. # This can fail if the video card is not powerful enough, if so, # display an error and exit. self.separation = 1 # Pixels self.filters = CommonFilters(base.win, base.cam) filterok = self.filters.setCartoonInk(separation=self.separation) if (filterok == False): addTitle("Toon Shader: Video card not powerful enough to do image postprocessing") return # Post the instructions. self.title = addTitle("Panda3D: Tutorial - Toon Shading with Normals-Based Inking") self.inst1 = addInstructions(0.95,"ESC: Quit") self.inst2 = addInstructions(0.90,"Up/Down: Increase/Decrease Line Thickness") self.inst3 = addInstructions(0.85,"V: View the render-to-texture results") # Load a dragon model and animate it. self.character = Actor() self.character.loadModel('models/samples/cartoon/nik_dragon') self.character.reparentTo(render) self.character.loadAnims({'win': 'models/samples/cartoon/nik_dragon'}) self.character.loop('win') self.character.hprInterval(15, Point3(360, 0,0)).loop() # Create a non-attenuating point light and an ambient light. plightnode = PointLight("point light") plightnode.setAttenuation(Vec3(1,0,0)) plight = render.attachNewNode(plightnode) plight.setPos(30,-50,0) alightnode = AmbientLight("ambient light") alightnode.setColor(Vec4(0.8,0.8,0.8,1)) alight = render.attachNewNode(alightnode) render.setLight(alight) render.setLight(plight) # Panda contains a built-in viewer that lets you view the # results of all render-to-texture operations. This lets you # see what class CommonFilters is doing behind the scenes. self.accept("v", base.bufferViewer.toggleEnable) self.accept("V", base.bufferViewer.toggleEnable) base.bufferViewer.setPosition("llcorner") self.accept("s", self.filters.manager.resizeBuffers) # These allow you to change cartooning parameters in realtime self.accept("escape", sys.exit, [0]) self.accept("arrow_up", self.increaseSeparation) self.accept("arrow_down", self.decreaseSeparation)
def __init__(self): base.disableMouse() base.cam.node().getLens().setNear(10.0) base.cam.node().getLens().setFar(200.0) camera.setPos(0, -50, 0) # Check video card capabilities. if (base.win.getGsg().getSupportsBasicShaders() == 0): addTitle( "Toon Shader: Video driver reports that shaders are not supported." ) return # Enable a 'light ramp' - this discretizes the lighting, # which is half of what makes a model look like a cartoon. # Light ramps only work if shader generation is enabled, # so we call 'setShaderAuto'. tempnode = NodePath(PandaNode("temp node")) tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.5, 0.4)) tempnode.setShaderAuto() base.cam.node().setInitialState(tempnode.getState()) # Use class 'CommonFilters' to enable a cartoon inking filter. # This can fail if the video card is not powerful enough, if so, # display an error and exit. self.separation = 1 # Pixels self.filters = CommonFilters(base.win, base.cam) filterok = self.filters.setCartoonInk(separation=self.separation) if (filterok == False): addTitle( "Toon Shader: Video card not powerful enough to do image postprocessing" ) return # Post the instructions. self.title = addTitle( "Panda3D: Tutorial - Toon Shading with Normals-Based Inking") self.inst1 = addInstructions(0.95, "ESC: Quit") self.inst2 = addInstructions( 0.90, "Up/Down: Increase/Decrease Line Thickness") self.inst3 = addInstructions(0.85, "V: View the render-to-texture results") # Load a dragon model and animate it. self.character = Actor() self.character.loadModel('models/samples/cartoon/nik_dragon') self.character.reparentTo(render) self.character.loadAnims({'win': 'models/samples/cartoon/nik_dragon'}) self.character.loop('win') self.character.hprInterval(15, Point3(360, 0, 0)).loop() # Create a non-attenuating point light and an ambient light. plightnode = PointLight("point light") plightnode.setAttenuation(Vec3(1, 0, 0)) plight = render.attachNewNode(plightnode) plight.setPos(30, -50, 0) alightnode = AmbientLight("ambient light") alightnode.setColor(Vec4(0.8, 0.8, 0.8, 1)) alight = render.attachNewNode(alightnode) render.setLight(alight) render.setLight(plight) # Panda contains a built-in viewer that lets you view the # results of all render-to-texture operations. This lets you # see what class CommonFilters is doing behind the scenes. self.accept("v", base.bufferViewer.toggleEnable) self.accept("V", base.bufferViewer.toggleEnable) base.bufferViewer.setPosition("llcorner") self.accept("s", self.filters.manager.resizeBuffers) # These allow you to change cartooning parameters in realtime self.accept("escape", sys.exit, [0]) self.accept("arrow_up", self.increaseSeparation) self.accept("arrow_down", self.decreaseSeparation)
def __init__(self): # Check video card capabilities. if (base.win.getGsg().getSupportsBasicShaders() == 0): addTitle("Normal Mapping: Video driver reports that shaders are not supported.") return # Post the instructions self.title = addTitle("Panda3D: Tutorial - Normal Mapping (aka Bump Mapping)") self.inst1 = addInstructions(0.95, "Press ESC to exit") self.inst2 = addInstructions(0.90, "Move mouse to rotate camera") self.inst3 = addInstructions(0.85, "Left mouse button: Move forwards") self.inst4 = addInstructions(0.80, "Right mouse button: Move backwards") self.inst5 = addInstructions(0.75, "Enter: Turn normal maps Off") # Load the 'abstract room' model. This is a model of an # empty room containing a pillar, a pyramid, and a bunch # of exaggeratedly bumpy textures. self.room = loader.loadModel( \ "models/samples/normal_mapping/abstractroom") self.room.reparentTo(render) # Make the mouse invisible, turn off normal mouse controls base.disableMouse() props = WindowProperties() props.setCursorHidden(True) base.win.requestProperties(props) # Set the current viewing target self.focus = Vec3(55,-55,20) self.heading = 180 self.pitch = 0 self.mousex = 0 self.mousey = 0 self.last = 0 self.mousebtn = [0,0,0] # Start the camera control task: taskMgr.add(self.controlCamera, "camera-task") self.accept("escape", sys.exit, [0]) self.accept("mouse1", self.setMouseBtn, [0, 1]) self.accept("mouse1-up", self.setMouseBtn, [0, 0]) self.accept("mouse2", self.setMouseBtn, [1, 1]) self.accept("mouse2-up", self.setMouseBtn, [1, 0]) self.accept("mouse3", self.setMouseBtn, [2, 1]) self.accept("mouse3-up", self.setMouseBtn, [2, 0]) self.accept("enter", self.toggleShader) self.accept("j", self.rotateLight, [-1]) self.accept("k", self.rotateLight, [1]) self.accept("arrow_left", self.rotateCam, [-1]) self.accept("arrow_right", self.rotateCam, [1]) # Add a light to the scene. self.lightpivot = render.attachNewNode("lightpivot") self.lightpivot.setPos(0,0,25) self.lightpivot.hprInterval(10,Point3(360,0,0)).loop() plight = PointLight('plight') plight.setColor(Vec4(1, 1, 1, 1)) plight.setAttenuation(Vec3(0.7,0.05,0)) plnp = self.lightpivot.attachNewNode(plight) plnp.setPos(45, 0, 0) self.room.setLight(plnp) self.room.setShaderInput("light", plnp) # Add an ambient light alight = AmbientLight('alight') alight.setColor(Vec4(0.2, 0.2, 0.2, 1)) alnp = render.attachNewNode(alight) self.room.setLight(alnp) # create a sphere to denote the light sphere = loader.loadModel("models/samples/normal_mapping/sphere") sphere.reparentTo(plnp) # load and apply the shader. This is using panda's # built-in shader generation capabilities to create the # shader for you. However, if desired, you can supply # the shader manually. Change this line of code to: # self.room.setShader(Shader.load("bumpMapper.sha")) self.room.setShaderAuto() self.shaderenable = 1