def __init__(self):
        base.disableMouse()
        base.cam.node().getLens().setNear(10.0)
        base.cam.node().getLens().setFar(9999999)
        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
        
        # 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])
Beispiel #2
0
 def toggle_cartoon(self):
     ''' Use Cartoon ink filter '''
     self.cartoon = not self.cartoon
     if self.cartoon:
         tempnode = NodePath(PandaNode("temp node"))
         tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.4, 0.6))
         tempnode.setShaderAuto()
         base.cam.node().setInitialState(tempnode.getState())
         self.separation = 1.3 # Pixels
         self.filters = CommonFilters(base.win, base.cam)
         self.filters.setCartoonInk(separation=self.separation)
         # Currently using MAuto antialias, uncomment to use different
         #render.setAntialias(AntialiasAttrib.MBetter)
         #self.filters.finalQuad.setAntialias(AntialiasAttrib.MBetter)
     else:
         self.filters.cleanup()
         base.cam.node().setInitialState(self.alight.getState())
Beispiel #3
0
	def register(self, render, camera, keys, render2d):
		State.register(self, render, camera, keys, render2d)
		self.node.attachNewNode(self.stage.maps[self.room].getNode())


		for c in self.characters:
			self.status[c].reparentTo(self.node2d)

		for char in self.characters.values():
			char.getNode().reparentTo(self.node)
			char.stunRender = self.node

		for l in self.stage.getLights():
			render.setLight(l)

		# COWABUNGA test!!!
		self.hearts = {}
		numChar=0

		self.heartsNode = NodePath(PandaNode('hearts'))
		self.heartsNode.reparentTo(self.node2d)

		for char in self.characters:
			self.hearts[char] = []

			for i in range(Character.maxHearts):
				self.hearts[char].append(Sprite("heart.png", 0.05, 0.05))
				self.hearts[char][i].setPos(-0.8 + 1.4*numChar + (i%3)*0.055 , -0.9 - int(i/3)*0.055)
				self.hearts[char][i].getNode().reparentTo(self.heartsNode)

			numChar += 1

		#COWABUNGA comment this to stop the madness
		render.setAttrib(LightRampAttrib.makeSingleThreshold(0.1, 1))

		# THE TRUE CARTOON SHADER :P
#		self.separation = 1 # Pixels
		self.filters = CommonFilters(base.win, self.camera.camera)
		# cell shading
#		filterok = self.filters.setCartoonInk(separation=self.separation)
		# glow
		filterok = self.filters.setBloom(blend=(0.5,0.5,0.5,1), desat=-0.5, intensity=0.5, size="small")

		self.camera.setPos(0, -2.5, -2.5)
		self.camera.lookAt(0, 0, 0)
    def compose_filters(self, win, cam, seperation=.6):
        """
        function to handle the composing, which makes for the basic look and feel of the game
        also handles any filters which are attached to the cam
        :return:
        """
        # set up the lightramp effect
        tempnode = NodePath(PandaNode("temp node"))
        tempnode.setAttrib(LightRampAttrib.makeSingleThreshold(
            0.5, 0.4))  # warning can be ignored..
        tempnode.setShaderAuto()
        cam.node().setInitialState(tempnode.getState())

        self.separation = seperation  # Pixels
        self.filters = CommonFilters(win, cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            return
Beispiel #5
0
    def __init__(self):
        # Initialize the ShowBase class from which we inherit, which will
        # create a window and set up everything we need for rendering into it.
        ShowBase.__init__(self)

        self.disableMouse()
        self.cam.node().getLens().setNear(10.0)
        self.cam.node().getLens().setFar(200.0)
        camera.setPos(0, -50, 0)

        # Check video card capabilities.
        if not self.win.getGsg().getSupportsBasicShaders():
            addTitle("Toon Shader: Video driver reports that Cg 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()
        self.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(self.win, self.cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            addTitle(
                "Toon Shader: Video card not powerful enough to do image postprocessing")
            return

        # Show instructions in the corner of the window.
        self.title = addTitle(
            "Panda3D: Tutorial - Toon Shading with Normals-Based Inking")
        self.inst1 = addInstructions(0.06, "ESC: Quit")
        self.inst2 = addInstructions(0.12, "Up/Down: Increase/Decrease Line Thickness")
        self.inst3 = addInstructions(0.18, "V: View the render-to-texture results")

        # Load a dragon model and animate it.
        self.character = Actor()
        self.character.loadModel('models/nik-dragon')
        self.character.reparentTo(render)
        self.character.loadAnims({'win': 'models/nik-dragon'})
        self.character.loop('win')
        self.character.hprInterval(15, (360, 0, 0)).loop()

        # Create a non-attenuating point light and an ambient light.
        plightnode = PointLight("point light")
        plightnode.setAttenuation((1, 0, 0))
        plight = render.attachNewNode(plightnode)
        plight.setPos(30, -50, 0)
        alightnode = AmbientLight("ambient light")
        alightnode.setColor((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", self.bufferViewer.toggleEnable)
        self.accept("V", self.bufferViewer.toggleEnable)
        self.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)
Beispiel #6
0
    def __init__(self):
        # Initialize the ShowBase class from which we inherit, which will
        # create a window and set up everything we need for rendering into it.
        ShowBase.__init__(self)

        self.disableMouse()
        self.cam.node().getLens().setNear(10.0)
        self.cam.node().getLens().setFar(200.0)
        camera.setPos(0, -50, 0)

        # Check video card capabilities.
        if not self.win.getGsg().getSupportsBasicShaders():
            addTitle(
                "Toon Shader: Video driver reports that Cg 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()
        self.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(self.win, self.cam)
        filterok = self.filters.setCartoonInk(separation=self.separation)
        if (filterok == False):
            addTitle(
                "Toon Shader: Video card not powerful enough to do image postprocessing"
            )
            return

        # Show instructions in the corner of the window.
        self.title = addTitle(
            "Panda3D: Tutorial - Toon Shading with Normals-Based Inking")
        self.inst1 = addInstructions(0.06, "ESC: Quit")
        self.inst2 = addInstructions(
            0.12, "Up/Down: Increase/Decrease Line Thickness")
        self.inst3 = addInstructions(0.18,
                                     "V: View the render-to-texture results")

        # Load a dragon model and animate it.
        self.character = Actor()
        self.character.loadModel('models/nik-dragon')
        self.character.reparentTo(render)
        self.character.loadAnims({'win': 'models/nik-dragon'})
        self.character.loop('win')
        self.character.hprInterval(15, (360, 0, 0)).loop()

        # Create a non-attenuating point light and an ambient light.
        plightnode = PointLight("point light")
        plightnode.setAttenuation((1, 0, 0))
        plight = render.attachNewNode(plightnode)
        plight.setPos(30, -50, 0)
        alightnode = AmbientLight("ambient light")
        alightnode.setColor((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", self.bufferViewer.toggleEnable)
        self.accept("V", self.bufferViewer.toggleEnable)
        self.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)
Beispiel #7
0
 def __init__(self):  #basic init start
     base.disableMouse()
     self.wp = WindowProperties()
     self.wp.setCursorHidden(True)
     base.win.requestProperties(self.wp)
     cm = CardMaker("cursor")
     cm.setFrame(0, 0.1, -0.13, 0)
     self.cust_mouse = render.attachNewNode(cm.generate())
     self.cust_mouse_tex = []
     self.cust_mouse_tex.append(
         loader.loadTexture("models/cursors/blank_cursor.png"))
     self.cust_mouse_tex.append(
         loader.loadTexture("models/cursors/main_cursor.png"))
     self.cust_mouse.setTexture(self.cust_mouse_tex[0])
     self.cust_mouse.setTransparency(TransparencyAttrib.MAlpha)
     self.cust_mouse.reparentTo(render2d)
     self.cust_mouse.setBin("gui-popup", 100)
     base.mouseWatcherNode.setGeometry(self.cust_mouse.node())
     #text and background
     textVersion = OnscreenText(text="v0.0",
                                font=arcFont,
                                pos=(1.15, -0.95),
                                fg=(0, 0, 0, 1),
                                bg=(1, 1, 1, 0.8))
     base.setBackgroundColor(1, 1, 1)
     self.curdir = (appRunner.p3dFilename.getDirname()
                    if appRunner else "..")
     self.main_config = json.loads("".join([
         line.rstrip().lstrip()
         for line in file(self.curdir + "/config.json", "rb")
     ]))
     #arrows (GENERAL)
     self.arrow = loader.loadModel("models/static/arrow")
     self.lst_arrows = []
     self.c_arr = CardMaker("arrow_hide")
     self.c_arr.setFrame(-1, 1, -0.8, 0.6)
     #light ramp
     self.rampnode = NodePath(PandaNode("temp node"))
     self.rampnode.setAttrib(LightRampAttrib.makeSingleThreshold(0.1, 0.7))
     self.rampnode.setShaderAuto()
     base.cam.node().setInitialState(self.rampnode.getState())
     #ink filter
     self.filters = CommonFilters(base.win, base.cam)
     self.filterok = self.filters.setCartoonInk(separation=1)
     #keyboard inputs
     self.accept("escape", sys.exit, [0])
     #lights
     self.lst_lghts = []
     #ambient light (permanent)
     self.alghtnode = AmbientLight("amb light")
     self.alghtnode.setColor(Vec4(0.4, 0.4, 0.4, 1))
     self.alght = render.attachNewNode(self.alghtnode)
     render.setLight(self.alght)
     #language recup
     self.langtab = self.main_config["lang"][self.main_config["lang_chx"]]
     self.lang = json.loads("".join([
         line.rstrip().lstrip()
         for line in file("misc/lang/" + self.langtab[0] + ".json", "rb")
     ]))
     #common gui elements
     self.voile = []
     self.voile.append(
         DirectFrame(frameSize=(-2, 2, -2, 2), frameColor=(0, 0, 0, 0.8)))
     self.voile[0].setBin("gui-popup", 1)
     self.voile[0].hide()
     self.voile.append(arcLabel("", (0, 0, 0.3), txtalgn=TextNode.ACenter))
     self.voile[1].setBin("gui-popup", 1)
     self.voile[1].reparentTo(self.voile[0])
     self.voile.append(arcLabel("", (0, 0, 0.17), txtalgn=TextNode.ACenter))
     self.voile[2].setBin("gui-popup", 1)
     self.voile[2].reparentTo(self.voile[0])
     self.voile.append(
         arcButton(self.lang["main_dialog"]["valid"], (-0.2, 0, 0),
                   None,
                   txtalgn=TextNode.ACenter))
     self.voile[3].setBin("gui-popup", 1)
     self.voile[3].reparentTo(self.voile[0])
     self.voile.append(
         arcButton(self.lang["main_dialog"]["cancel"], (0.2, 0, 0),
                   None,
                   txtalgn=TextNode.ACenter))
     self.voile[4].setBin("gui-popup", 1)
     self.voile[4].reparentTo(self.voile[0])
     #mouse handler
     self.mouse_trav = CollisionTraverser()
     self.mouse_hand = CollisionHandlerQueue()
     self.pickerNode = CollisionNode('mouseRay')
     self.pickerNP = camera.attachNewNode(self.pickerNode)
     self.pickerNode.setFromCollideMask(BitMask32.bit(1))
     self.pickerRay = CollisionRay()
     self.pickerNode.addSolid(self.pickerRay)
     self.mouse_trav.addCollider(self.pickerNP, self.mouse_hand)
     self.pickly_node = render.attachNewNode("pickly_node")
     #init main scene
     self.scene = mainScene(self)