def create(self): """ Creates this pipeline """ self.debug("Setting up render pipeline") if self.settings is None: self.error("You have to call loadSettings first!") return self.debug("Analyzing system ..") SystemAnalyzer.analyze() self.debug("Checking required Panda3D version ..") SystemAnalyzer.checkPandaVersionOutOfDate(01, 12, 2014) # Mount everything first self.mountManager.mount() # Store globals, as cython can't handle them self.debug("Setting up globals") Globals.load(self.showbase) Globals.font = loader.loadFont("Data/Font/SourceSansPro-Semibold.otf") Globals.font.setPixelsPerUnit(25) # Setting up shader loading BetterShader._DumpShaders = self.settings.dumpGeneratedShaders # We use PTA's for shader inputs, because that's faster than # using setShaderInput self.temporalProjXOffs = PTAInt.emptyArray(1) self.cameraPosition = PTAVecBase3f.emptyArray(1) self.motionBlurFactor = PTAFloat.emptyArray(1) self.lastMVP = PTALMatrix4f.emptyArray(1) self.currentMVP = PTALMatrix4f.emptyArray(1) self.currentShiftIndex = PTAInt.emptyArray(1) # Initialize variables self.camera = self.showbase.cam self.size = self._getSize() self.cullBounds = None # For the temporal reprojection it is important that the window width # is a multiple of 2 if self.settings.enableTemporalReprojection and self.size.x % 2 == 1: self.error( "The window has to have a width which is a multiple of 2 " "(Current: ", self.showbase.win.getXSize(), ")") self.error( "I'll correct that for you, but next time pass the correct " "window size!") wp = WindowProperties() wp.setSize(self.showbase.win.getXSize() + 1, self.showbase.win.getYSize()) self.showbase.win.requestProperties(wp) self.showbase.graphicsEngine.openWindows() # Get new size self.size = self._getSize() # Debug variables to disable specific features self.haveLightingPass = True # haveCombiner can only be true when haveLightingPass is enabled self.haveCombiner = True self.haveMRT = True # Not as good as I want it, so disabled. I'll work on it. self.blurEnabled = False self.debug("Window size is", self.size.x, "x", self.size.y) self.showbase.camLens.setNearFar(0.1, 50000) self.showbase.camLens.setFov(90) self.showbase.win.setClearColor(Vec4(1.0, 0.0, 1.0, 1.0)) # Create GI handler if self.settings.enableGlobalIllumination: self._setupGlobalIllumination() # Create occlusion handler self._setupOcclusion() if self.settings.displayOnscreenDebugger: self.guiManager = PipelineGuiManager(self) self.guiManager.setup() # Generate auto-configuration for shaders self._generateShaderConfiguration() # Create light manager, which handles lighting + shadows if self.haveLightingPass: self.lightManager = LightManager(self) self.patchSize = LVecBase2i(self.settings.computePatchSizeX, self.settings.computePatchSizeY) # Create separate scene graphs. The deferred graph is render self.forwardScene = NodePath("Forward-Rendering") self.transparencyScene = NodePath("Transparency-Rendering") self.transparencyScene.setBin("transparent", 30) # We need no transparency (we store other information in the alpha # channel) self.showbase.render.setAttrib( TransparencyAttrib.make(TransparencyAttrib.MNone), 100) # Now create deferred render buffers self._makeDeferredTargets() # Create the target which constructs the view-space normals and # position from world-space position if self.occlusion.requiresViewSpacePosNrm(): self._createNormalPrecomputeBuffer() if self.settings.enableGlobalIllumination: self._creatGIPrecomputeBuffer() # Setup the buffers for lighting self._createLightingPipeline() # Setup combiner for temporal reprojetion if self.haveCombiner and self.settings.enableTemporalReprojection: self._createCombiner() if self.occlusion.requiresBlurring(): self._createOcclusionBlurBuffer() self._setupAntialiasing() if self.blurEnabled: self._createDofStorage() self._createBlurBuffer() # Not sure why it has to be 0.25. But that leads to the best result aspect = float(self.size.y) / self.size.x self.onePixelShift = Vec2(0.125 / self.size.x, 0.125 / self.size.y / aspect) * self.settings.jitterAmount # Annoying that Vec2 has no multliply-operator for non-floats multiplyVec2 = lambda a, b: Vec2(a.x * b.x, a.y * b.y) if self.antialias.requiresJittering(): self.pixelShifts = [ multiplyVec2(self.onePixelShift, Vec2(-0.25, 0.25)), multiplyVec2(self.onePixelShift, Vec2(0.25, -0.25)) ] else: self.pixelShifts = [Vec2(0), Vec2(0)] self.currentPixelShift = PTAVecBase2f.emptyArray(1) self.lastPixelShift = PTAVecBase2f.emptyArray(1) self._setupFinalPass() self._setShaderInputs() # Give the gui a hint when the pipeline is done loading if self.settings.displayOnscreenDebugger: self.guiManager.onPipelineLoaded() # add update task self._attachUpdateTask()
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()