Example #1
0
 def setDefaultSceneFBO(self):
     """ set the default fbo for offscreen scene rendering. """
     drawSceneFBO = FBO()
     drawSceneFBO.addColorTexture(self.sceneTexture)
     drawSceneFBO.setDepthTexture(self.sceneDepthTexture)
     drawSceneFBO.create()
     self.appendFBO(drawSceneFBO, self.drawSceneComplete, self.sceneCamera)
    def _setupReflectionPass(self):
        """
        prepends a rendering pass each frame,
        rendering the reflected scene to fbo.
        """
        # get configurable map size
        w, h = self.segment.getAttr("reflectionMapSize", (512, 512))
        self.reflectionColor = Texture2D(width=w, height=h)
        self.reflectionColor.create()
        reflectionDepth = DepthTexture2D(width=w, height=h)
        reflectionDepth.create()

        reflectionFBO = FBO()
        reflectionFBO.addColorTexture(self.reflectionColor)
        reflectionFBO.setDepthTexture(reflectionDepth)
        reflectionFBO.create()

        # draw the reflected scene with same camera as scene
        self.app.prependFBO(reflectionFBO, self._drawReflectedScene, self.app.sceneCamera)
Example #3
0
    def processFrame(self, timePassedSecs):
        """ draws a scene """

        # update the model view matrix
        self.sceneCamera.updateKeys()
        self.sceneCamera.update()

        # process queued GLObject events
        GLObject.signalsEmit()

        # enable some default scene states
        glEnable(GL_DEPTH_TEST)

        ######## SHADOW MAP RENDERING START ########

        # offset the geometry slightly to prevent z-fighting
        # note that this introduces some light-leakage artifacts
        glEnable(GL_POLYGON_OFFSET_FILL)
        glPolygonOffset(1.1, 4096.0)

        # cull front faces for shadow rendering,
        # this moves z-fighting to backfaces.
        glCullFace(GL_FRONT)
        # enable depth rendering shader.
        # FIXME: support segment geometry shader!
        #          geometry shader could change the shadow shape!
        self.depthShader.enable()

        map(_updateLightShadowMap, self.lights)
        glBindFramebuffer(GL_FRAMEBUFFER, 0)

        glDisable(GL_POLYGON_OFFSET_FILL)
        ######## SHADOW MAP RENDERING STOP ########

        #### TODO: FOG: integrate FOG ####
        glEnable(GL_FOG)
        glFogi(GL_FOG_MODE, GL_EXP2)
        # approximate the atmosphere's filtering effect as a linear function
        sunDir = array([4.0, 4.0, 4.0, 0.0], float32)  # TODO: FOG: what is the sun dir ?
        skyColor = array([0.8, sunDir[1] * 0.1 + 0.7, sunDir[1] * 0.4 + 0.5, 1.0], float32)
        glClearColor(*skyColor)
        glFogf(GL_FOG_DENSITY, 0.4)
        glFogf(GL_FOG_START, 16.0)
        glFogf(GL_FOG_END, self.farClip)
        glFogfv(GL_FOG_COLOR, skyColor)

        # fill projection matrix
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.projectionMatrix)
        glMatrixMode(GL_MODELVIEW)

        # draw stuff in 3d projection
        lastCam = None
        glPushAttrib(GL_COLOR_BUFFER_BIT)
        for (fbo, draw, cam) in self.sceneFBOS:
            # render to fbo
            fbo.enable()
            if cam != lastCam:
                cam.enable()
                lastCam = cam
            draw()
        # disable render to texture
        FBO.disable()
        glPopAttrib()
        glViewport(0, 0, self.winSize[0], self.winSize[1])

        #### TODO: FOG: integrate FOG ####
        glDisable(GL_FOG)

        # change to orthogonal projection
        glMatrixMode(GL_PROJECTION)
        glLoadMatrixf(self.orthoMatrix)
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()

        # no depth test needed in orthogonal rendering
        glDisable(GL_DEPTH_TEST)

        # draw orthogonal to the screen
        self.orthogonalPass()