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()
def fog(cls, param: FogParam, value): if isinstance(value, Iterable): glFogfv(param.value, value) else: glFogf(param.value, value)
def set_fog(self, color, start, end): glFogfv(GL_FOG_COLOR, color) glEnable(GL_FOG) glFogfv(GL_FOG_MODE, GL_LINEAR) glFogfv(GL_FOG_START, start) glFogfv(GL_FOG_END, end)