def load(self): DistributedPartyFireworksActivity.notify.debug('load') DistributedPartyActivity.load(self) self.eventId = PartyGlobals.FireworkShows.Summer self.launchPadModel = loader.loadModel('phase_13/models/parties/launchPad') self.launchPadModel.setH(90.0) self.launchPadModel.setPos(0.0, -18.0, 0.0) self.launchPadModel.reparentTo(self.root) railingsCollection = self.launchPadModel.findAllMatches('**/launchPad_mesh/*railing*') for i in xrange(railingsCollection.getNumPaths()): railingsCollection[i].setAttrib(AlphaTestAttrib.make(RenderAttrib.MGreater, 0.75)) leverLocator = self.launchPadModel.find('**/RocketLever_locator') self.lever.setPosHpr(Vec3.zero(), Vec3.zero()) self.lever.reparentTo(leverLocator) self.toonPullingLeverInterval = None self.sign.reparentTo(self.launchPadModel.find('**/launchPad_sign_locator')) self.rocketActor = Actor('phase_13/models/parties/rocket_model', {'launch': 'phase_13/models/parties/rocket_launch'}) rocketLocator = self.launchPadModel.find('**/rocket_locator') self.rocketActor.reparentTo(rocketLocator) self.rocketActor.node().setBound(OmniBoundingVolume()) self.rocketActor.node().setFinal(True) effectsLocator = self.rocketActor.find('**/joint1') self.rocketExplosionEffect = RocketExplosion(effectsLocator, rocketLocator) self.rocketParticleSeq = None self.launchSound = base.loader.loadSfx('phase_13/audio/sfx/rocket_launch.ogg') self.activityFSM = FireworksActivityFSM(self) self.activityFSM.request('Idle') return
def registerEarlyZTagState(self, name, state): """ Registers a new tag state """ if not self.prepassCam: return # state.setAttrib(CullFaceAttrib.make(CullFaceAttrib.MCullClockwise), 10000) state.setAttrib(ColorWriteAttrib.make(ColorWriteAttrib.COff), 10000) state.setAttrib(AlphaTestAttrib.make(AlphaTestAttrib.MNone, 1.0), 10000) state.setAttrib(DepthWriteAttrib.make(DepthWriteAttrib.MOn), 10000) state.setAttrib(DepthTestAttrib.make(DepthTestAttrib.MLess), 10000) state.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MNone), 10000) self.prepassCam.setTagState(name, state.getState())
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.setBackgroundColor((0, 0, 0, 0)) # Preliminary capabilities check. if not self.win.getGsg().getSupportsBasicShaders(): self.t = addTitle("Firefly Demo: Video driver reports that Cg " "shaders are not supported.") return if not self.win.getGsg().getSupportsDepthTexture(): self.t = addTitle("Firefly Demo: Video driver reports that depth " "textures are not supported.") return # This algorithm uses two offscreen buffers, one of which has # an auxiliary bitplane, and the offscreen buffers share a single # depth buffer. This is a heck of a complicated buffer setup. self.modelbuffer = self.makeFBO("model buffer", 1) self.lightbuffer = self.makeFBO("light buffer", 0) # Creation of a high-powered buffer can fail, if the graphics card # doesn't support the necessary OpenGL extensions. if self.modelbuffer is None or self.lightbuffer is None: self.t = addTitle("Toon Shader: Video driver does not support " "multiple render targets") return # Create four render textures: depth, normal, albedo, and final. # attach them to the various bitplanes of the offscreen buffers. self.texDepth = Texture() self.texDepth.setFormat(Texture.FDepthStencil) self.texAlbedo = Texture() self.texNormal = Texture() self.texFinal = Texture() self.modelbuffer.addRenderTexture(self.texDepth, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPDepthStencil) self.modelbuffer.addRenderTexture(self.texAlbedo, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor) self.modelbuffer.addRenderTexture(self.texNormal, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPAuxRgba0) self.lightbuffer.addRenderTexture(self.texFinal, GraphicsOutput.RTMBindOrCopy, GraphicsOutput.RTPColor) # Set the near and far clipping planes. self.cam.node().getLens().setNear(50.0) self.cam.node().getLens().setFar(500.0) lens = self.cam.node().getLens() # This algorithm uses three cameras: one to render the models into the # model buffer, one to render the lights into the light buffer, and # one to render "plain" stuff (non-deferred shaded) stuff into the # light buffer. Each camera has a bitmask to identify it. self.modelMask = 1 self.lightMask = 2 self.plainMask = 4 self.modelcam = self.makeCamera(self.modelbuffer, lens=lens, scene=render, mask=self.modelMask) self.lightcam = self.makeCamera(self.lightbuffer, lens=lens, scene=render, mask=self.lightMask) self.plaincam = self.makeCamera(self.lightbuffer, lens=lens, scene=render, mask=self.plainMask) # Panda's main camera is not used. self.cam.node().setActive(0) # Take explicit control over the order in which the three # buffers are rendered. self.modelbuffer.setSort(1) self.lightbuffer.setSort(2) self.win.setSort(3) # Within the light buffer, control the order of the two cams. self.lightcam.node().getDisplayRegion(0).setSort(1) self.plaincam.node().getDisplayRegion(0).setSort(2) # By default, panda usually clears the screen before every # camera and before every window. Tell it not to do that. # Then, tell it specifically when to clear and what to clear. self.modelcam.node().getDisplayRegion(0).disableClears() self.lightcam.node().getDisplayRegion(0).disableClears() self.plaincam.node().getDisplayRegion(0).disableClears() self.cam.node().getDisplayRegion(0).disableClears() self.cam2d.node().getDisplayRegion(0).disableClears() self.modelbuffer.disableClears() self.win.disableClears() self.modelbuffer.setClearColorActive(1) self.modelbuffer.setClearDepthActive(1) self.lightbuffer.setClearColorActive(1) self.lightbuffer.setClearColor((0, 0, 0, 1)) # Miscellaneous stuff. self.disableMouse() self.camera.setPos(-9.112, -211.077, 46.951) self.camera.setHpr(0, -7.5, 2.4) random.seed() # Calculate the projection parameters for the final shader. # The math here is too complex to explain in an inline comment, # I've put in a full explanation into the HTML intro. proj = self.cam.node().getLens().getProjectionMat() proj_x = 0.5 * proj.getCell(3, 2) / proj.getCell(0, 0) proj_y = 0.5 * proj.getCell(3, 2) proj_z = 0.5 * proj.getCell(3, 2) / proj.getCell(2, 1) proj_w = -0.5 - 0.5 * proj.getCell(1, 2) # Configure the render state of the model camera. tempnode = NodePath(PandaNode("temp node")) tempnode.setAttrib( AlphaTestAttrib.make(RenderAttrib.MGreaterEqual, 0.5)) tempnode.setShader(loader.loadShader("model.sha")) tempnode.setAttrib(DepthTestAttrib.make(RenderAttrib.MLessEqual)) self.modelcam.node().setInitialState(tempnode.getState()) # Configure the render state of the light camera. tempnode = NodePath(PandaNode("temp node")) tempnode.setShader(loader.loadShader("light.sha")) tempnode.setShaderInput("texnormal", self.texNormal) tempnode.setShaderInput("texalbedo", self.texAlbedo) tempnode.setShaderInput("texdepth", self.texDepth) tempnode.setShaderInput("proj", (proj_x, proj_y, proj_z, proj_w)) tempnode.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.MAdd, ColorBlendAttrib.OOne, ColorBlendAttrib.OOne)) tempnode.setAttrib( CullFaceAttrib.make(CullFaceAttrib.MCullCounterClockwise)) # The next line causes problems on Linux. # tempnode.setAttrib(DepthTestAttrib.make(RenderAttrib.MGreaterEqual)) tempnode.setAttrib(DepthWriteAttrib.make(DepthWriteAttrib.MOff)) self.lightcam.node().setInitialState(tempnode.getState()) # Configure the render state of the plain camera. rs = RenderState.makeEmpty() self.plaincam.node().setInitialState(rs) # Clear any render attribs on the root node. This is necessary # because by default, panda assigns some attribs to the root # node. These default attribs will override the # carefully-configured render attribs that we just attached # to the cameras. The simplest solution is to just clear # them all out. render.setState(RenderState.makeEmpty()) # My artist created a model in which some of the polygons # don't have textures. This confuses the shader I wrote. # This little hack guarantees that everything has a texture. white = loader.loadTexture("models/white.jpg") render.setTexture(white, 0) # Create two subroots, to help speed cull traversal. self.lightroot = NodePath(PandaNode("lightroot")) self.lightroot.reparentTo(render) self.modelroot = NodePath(PandaNode("modelroot")) self.modelroot.reparentTo(render) self.lightroot.hide(BitMask32(self.modelMask)) self.modelroot.hide(BitMask32(self.lightMask)) self.modelroot.hide(BitMask32(self.plainMask)) # Load the model of a forest. Make it visible to the model camera. # This is a big model, so we load it asynchronously while showing a # load text. We do this by passing in a callback function. self.loading = addTitle("Loading models...") self.forest = NodePath(PandaNode("Forest Root")) self.forest.reparentTo(render) self.forest.hide(BitMask32(self.lightMask | self.plainMask)) loader.loadModel([ "models/background", "models/foliage01", "models/foliage02", "models/foliage03", "models/foliage04", "models/foliage05", "models/foliage06", "models/foliage07", "models/foliage08", "models/foliage09"], callback=self.finishLoading) # Cause the final results to be rendered into the main window on a # card. self.card = self.lightbuffer.getTextureCard() self.card.setTexture(self.texFinal) self.card.reparentTo(render2d) # Panda contains a built-in viewer that lets you view the results of # your render-to-texture operations. This code configures the viewer. self.bufferViewer.setPosition("llcorner") self.bufferViewer.setCardSize(0, 0.40) self.bufferViewer.setLayout("vline") self.toggleCards() self.toggleCards() # Firefly parameters self.fireflies = [] self.sequences = [] self.scaleseqs = [] self.glowspheres = [] self.fireflysize = 1.0 self.spheremodel = loader.loadModel("misc/sphere") # Create the firefly model, a fuzzy dot dotSize = 1.0 cm = CardMaker("firefly") cm.setFrame(-dotSize, dotSize, -dotSize, dotSize) self.firefly = NodePath(cm.generate()) self.firefly.setTexture(loader.loadTexture("models/firefly.png")) self.firefly.setAttrib(ColorBlendAttrib.make(ColorBlendAttrib.M_add, ColorBlendAttrib.O_incoming_alpha, ColorBlendAttrib.O_one)) # these allow you to change parameters in realtime self.accept("escape", sys.exit, [0]) self.accept("arrow_up", self.incFireflyCount, [1.1111111]) self.accept("arrow_down", self.decFireflyCount, [0.9000000]) self.accept("arrow_right", self.setFireflySize, [1.1111111]) self.accept("arrow_left", self.setFireflySize, [0.9000000]) self.accept("v", self.toggleCards) self.accept("V", self.toggleCards)
def create(self): """ Creates the pipeline """ self.debug("Setting up render pipeline") self.guiVisible = True # Handy shortcuts self.showbase.accept("1", PStatClient.connect) self.showbase.accept("r", self.reloadShaders) self.showbase.accept("t", self.reloadEffects) self.showbase.accept("f7", self._createBugReport) self.showbase.accept("f8", self.toggleGui) if self.settings is None: self.error("You have to call loadSettings first!") return self.debug("Checking required Panda3D version ..") SystemAnalyzer.checkPandaVersionOutOfDate(12,8,2015) # SystemAnalyzer.analyze() # Mount everything first self.mountManager.mount() # Check if there is already another instance running, but only if specified # in the settings if self.settings.preventMultipleInstances and not self.mountManager.getLock(): self.fatal("Another instance of the rendering pipeline is already running") return # Store globals, as cython can't handle them self.debug("Setting up globals") Globals.load(self.showbase) Globals.resolution = LVecBase2i( \ int(self.showbase.win.getXSize() * self.settings.resolution3D), int(self.showbase.win.getYSize() * self.settings.resolution3D)) Globals.font = loader.loadFont("Data/Font/SourceSansPro-Semibold.otf") Globals.font.setPixelsPerUnit(25) # Check size if Globals.resolution.x % 2 == 1: self.fatal( "The window width has to be a multiple of 2 " "(Current: ", Globals.resolution.x, ")") return if self.settings.displayOnscreenDebugger: self.guiManager = PipelineGuiManager(self) else: self.guiManager = None # Some basic scene settings self.showbase.camLens.setNearFar(0.1, 70000) self.showbase.camLens.setFov(110) self.showbase.win.setClearColor(Vec4(1.0, 0.0, 1.0, 1.0)) self.showbase.camNode.setCameraMask(self.getMainPassBitmask()) self.showbase.render.setAttrib(TransparencyAttrib.make(TransparencyAttrib.MNone), 100) # Create render pass matcher self.renderPassManager = RenderPassManager() # Create last frame buffers self._createLastFrameBuffers() self._precomputeScattering() # Add initial pass self.initialRenderPass = InitialRenderPass() self.renderPassManager.registerPass(self.initialRenderPass) # Add deferred pass self.deferredScenePass = DeferredScenePass(self) self.renderPassManager.registerPass(self.deferredScenePass) # Add lighting pass self.lightingPass = LightingPass() self.renderPassManager.registerPass(self.lightingPass) # Add dynamic exposure pass if self.settings.useAdaptiveBrightness: self.dynamicExposurePass = DynamicExposurePass(self) self.renderPassManager.registerPass(self.dynamicExposurePass) # Add motion blur pass if self.settings.enableMotionBlur: self.motionBlurPass = MotionBlurPass() self.renderPassManager.registerPass(self.motionBlurPass) # Add volumetric lighting # self.volumetricLightingPass = VolumetricLightingPass() # self.renderPassManager.registerPass(self.volumetricLightingPass) # Add bloom pass if self.settings.enableBloom: self.bloomPass = BloomPass() self.renderPassManager.registerPass(self.bloomPass) # Add dof pass if self.settings.enableDOF: self.dofPass = DOFPass() self.renderPassManager.registerPass(self.dofPass) # Add final pass self.finalPostprocessPass = FinalPostprocessPass() self.renderPassManager.registerPass(self.finalPostprocessPass) # Add scene finish pass self.sceneFinishPass = SceneFinishPass(self) self.renderPassManager.registerPass(self.sceneFinishPass) # Create managers self.occlusionManager = AmbientOcclusionManager(self) self.lightManager = LightManager(self) self.antialiasingManager = AntialiasingManager(self) self.dynamicObjectsManager = DynamicObjectsManager(self) self.sslrManager = SSLRManager(self) if self.settings.useTransparency: self.transparencyManager = TransparencyManager(self) if self.settings.enableClouds: self.cloudManager = CloudManager(self) self._createGlobalIllum() # Make variables available self._createGenericDefines() self._createInputHandles() self._createDefaultTextureInputs() self._createViewSpacePass() self._createSkyboxMaskPass() # Create an empty node at render space to store all dummmy cameras on camDummyNode = render.attachNewNode("RPCameraDummys") camDummyNode.hide() # Create an empty node at render space to store the light debug nodes lightDebugNode = render.attachNewNode("RPLightDebugNodes") # Finally matchup all the render passes and set the shaders self.renderPassManager.createPasses() self.renderPassManager.writeAutoconfig() self.renderPassManager.setShaders() # Create the update tasks self._createTasks() # Create the effect loader self.effectLoader = EffectLoader(self) # Apply the default effect to the scene self.setEffect(Globals.render, "Effects/Default/Default.effect", { "transparent": False, "normalMapping": True, "alphaTest": True, }, -10) render.setAttrib(AlphaTestAttrib.make(AlphaTestAttrib.MNone, 1), 999999) # Apply the debug effect to the light debug nodes self.setEffect(lightDebugNode, "Effects/LightDebug.effect", { "transparent": False, "normalMapping": False, "alphaTest": True, "castShadows": False, "castGI": False }, 100) self._setGuiShaders() if self.settings.enableGlobalIllumination: self.globalIllum.reloadShader() # Give the gui a hint when the pipeline is done loading if self.guiManager: self.guiManager.onPipelineLoaded()