Exemple #1
0
    def EnableStereo(self, enable):
        if enable == self.stereoEnabled:
            return True
        if enable:

            def leftCallback():
                return self._StereoUpdateViewProjection(trinity.STEREO_EYE_LEFT)

            def rightCallback():
                return self._StereoUpdateViewProjection(trinity.STEREO_EYE_RIGHT)

            leftUpdate = self.AddStep('UPDATE_STEREO', trinity.TriStepPythonCB())
            if leftUpdate is None:
                return False
            leftUpdate.SetCallback(leftCallback)
            self.originalProjection = self.projection
            self.stereoProjection = trinity.TriProjection()
            self.SetCameraProjection(self.stereoProjection)
            rightUpdate = trinity.TriStepPythonCB()
            rightUpdate.name = 'UPDATE_STEREO_RIGHT'
            rightUpdate.SetCallback(rightCallback)
            self.steps.append(rightUpdate)
            index = -1
            try:
                index = self.steps.index(self.GetStep('UPDATE_STEREO'))
            except:
                pass

            if index >= 0:
                count = len(self.steps)
                for i in range(index + 1, count - 1):
                    step = self.steps[i]
                    self.steps.append(step)

            self.stereoEnabled = True
        else:
            index = -1
            for i, step in enumerate(self.steps):
                if step.name == 'UPDATE_STEREO_RIGHT':
                    index = i
                    break

            if index >= 0:
                while len(self.steps) > index:
                    self.steps.removeAt(index)

            self.stereoEnabled = False
            self.RemoveStep('UPDATE_STEREO')
            self.SetCameraProjection(self.originalProjection.object)
        return True
    def RunSimulation(self):
        trinity.settings.SetValue('frustumCullingDisabled', 1)
        trinity.settings.SetValue('eveSpaceSceneVisibilityThreshold', 0)
        trinity.settings.SetValue('eveSpaceSceneLowDetailThreshold', 0)
        trinity.settings.SetValue('eveSpaceSceneMediumDetailThreshold', 0)
        ut.StartTasklet(self._PumpBlue)
        import sceneutils
        scene = sceneutils.GetOrCreateScene()
        scene.objects.append(self.redNodeMutated)
        self._UpdateBoundingBox(True)
        rj = trinity.CreateRenderJob('CallbackJob')
        projection = trinity.TriProjection()
        projection.PerspectiveFov(1, 1, 1, 10000000)
        rj.steps.append(trinity.TriStepSetProjection(projection))
        view = trinity.TriView()
        view.SetLookAtPosition((50000, 0, 0), (0, 0, 0), (0, 1, 0))
        rj.steps.append(trinity.TriStepSetView(view))
        rj.steps.append(trinity.TriStepUpdate(scene))
        rj.steps.append(trinity.TriStepRenderScene(scene))
        rj.steps.append(trinity.TriStepPythonCB(self.AccumulateBounds))
        rj.ScheduleRecurring()
        for i in range(self._passes):
            self.activeIndex[0] = i
            for cs in self.curveSets:
                cs.Play()

            for sys in self.systems:
                sys.ClearParticles()

            self.started[0] = True
            ut.SleepSim(self._time)

        rj.UnscheduleRecurring()
        self._pumpBlue = False
Exemple #3
0
 def _CreateJobFiS(self, rj=None):
     if rj is None:
         rj = self.fisRenderJob
     rj.CreateBasicRenderSteps()
     rj.EnablePostProcessing(True)
     rj.AddStep('CAMERA_UPDATE',
                trinity.TriStepPythonCB(self._UpdateActiveCamera))
Exemple #4
0
 def _CreateJobInterior(self):
     rj = self.incarnaRenderJob
     rj.CreateBasicRenderSteps()
     rj.EnableSceneUpdate(True)
     rj.EnableVisibilityQuery(True)
     rj.AddStep('CAMERA_UPDATE',
                trinity.TriStepPythonCB(self._UpdateActiveCamera))
 def AddCallback(self, func, name, rj = None):
     cb = trinity.TriStepPythonCB()
     weakSelf = weakref.ref(self)
     cb.SetCallback(lambda : SkinLightmapRenderer.FuncWrapper(weakSelf, func))
     cb.name = name
     rj = rj if rj is not None else self.lightmapRenderJob
     rj.steps.append(cb)
Exemple #6
0
def CreateSsaoRenderJob(options, width, height, outputRT):
    randomTexture = CreateRandomTexture(options)
    if not randomTexture.isGood:
        return
    linearizeDepth = CreateMaterial('linearizeDepth')
    shaderSSAO = CreateMaterial('normalFree useNormals')
    linearizeDepthAndPackAODepth = CreateMaterial('linearizeDepthAndPack')
    blurX = CreateMaterial('blurX')
    if not options.disableBlending:
        blurY = CreateMaterial('blurY blend')
    else:
        blurY = CreateMaterial('blurY')
    SetMaterialConstants(options, width, height, linearizeDepth,
                         linearizeDepthAndPackAODepth, blurX, blurY,
                         shaderSSAO, randomTexture)
    curHistoryAOZRT = trinity.Tr2RenderTarget(
        width, height, 1, trinity.PIXEL_FORMAT.R16G16_FLOAT)
    fullResAOZRT = trinity.Tr2RenderTarget(width, height, 1,
                                           trinity.PIXEL_FORMAT.R16G16_FLOAT)
    if options.resolutionMode == SSAO_HALF_RES_AO:
        linDepthRT = trinity.Tr2RenderTarget(width / 2, height / 2, 1,
                                             trinity.PIXEL_FORMAT.R32_FLOAT)
        halfResAORT = trinity.Tr2RenderTarget(width / 2, height / 2, 1,
                                              trinity.PIXEL_FORMAT.R8_UNORM)
        outputAOZ = halfResAORT
    else:
        linDepthRT = trinity.Tr2RenderTarget(width, height, 1,
                                             trinity.PIXEL_FORMAT.R32_FLOAT)
        outputAOZ = curHistoryAOZRT
    AddMaterialParam(shaderSSAO, 'DepthMap', linDepthRT)
    AddMaterialParam(shaderSSAO, 'RandomMap', randomTexture)
    if options.resolutionMode == SSAO_HALF_RES_AO:
        AddMaterialParam(linearizeDepthAndPackAODepth, 'SSAOMap', halfResAORT)
    AddMaterialParam(blurX, 'SSAOMap', curHistoryAOZRT)
    AddMaterialParam(blurY, 'SSAOMap', fullResAOZRT)
    linearizeDepth.BindLowLevelShader([])
    shaderSSAO.BindLowLevelShader([])
    linearizeDepthAndPackAODepth.BindLowLevelShader([])
    blurX.BindLowLevelShader([])
    blurY.BindLowLevelShader([])
    rj = trinity.TriRenderJob()
    AddStep(rj, 'SAVE_DS', trinity.TriStepPushDepthStencil(None))
    AddStep(rj, 'SAVE_RT', trinity.TriStepPushRenderTarget())
    cb = GetSSAOCallbackStep(options, width, height, shaderSSAO,
                             linearizeDepth, linearizeDepthAndPackAODepth)
    AddStep(rj, 'UPDATE_CONSTANTS', trinity.TriStepPythonCB(cb))
    AddStep(rj, 'SET_FULLSCREEN_STATES',
            trinity.TriStepSetStdRndStates(trinity.RM_FULLSCREEN))
    AddStep(rj, 'SET_LINEAR_DEPTH_RT',
            trinity.TriStepSetRenderTarget(linDepthRT))
    AddStep(rj, 'LINEARIZE_DEPTH',
            trinity.TriStepRenderFullScreenShader(linearizeDepth))
    AddStep(rj, 'SET_AO_RT', trinity.TriStepSetRenderTarget(outputAOZ))
    AddStep(rj, 'RENDER_AO', trinity.TriStepRenderFullScreenShader(shaderSSAO))
    if options.resolutionMode == SSAO_HALF_RES_AO:
        AddStep(rj, 'SET_TEMP_AO_RT',
                trinity.TriStepSetRenderTarget(curHistoryAOZRT))
        AddStep(
            rj, 'PACK_DEPTH_AND_AO',
            trinity.TriStepRenderFullScreenShader(
                linearizeDepthAndPackAODepth))
    AddStep(rj, 'SET_FULL_AO_RT', trinity.TriStepSetRenderTarget(fullResAOZRT))
    AddStep(rj, 'BLUR_X', trinity.TriStepRenderFullScreenShader(blurX))
    if outputRT is None:
        AddStep(rj, 'RESTORE_RT', trinity.TriStepPopRenderTarget())
    else:
        AddStep(rj, 'SET_OUTPUT_RT', trinity.TriStepSetRenderTarget(outputRT))
    AddStep(rj, 'BLUR_Y', trinity.TriStepRenderFullScreenShader(blurY))
    if outputRT:
        AddStep(rj, 'RESTORE_RT', trinity.TriStepPopRenderTarget())
    AddStep(rj, 'RESTORE_DS', trinity.TriStepPopDepthStencil())
    return rj
    def CreateRenderJobsForLight(self, light):
        """
        Create a renderjob to render out the shadow map for this light, and blur
        it for VSM; optionally also show it on the screen for debugging.
        """
        self.lights.append(light)
        if not SkinSpotLightShadows.REUSE_ENGINE_MAPS:
            light.shadowCasterTypes = 0
        else:
            light.shadowResolution = 1024
        ignoreLight = False
        if self.lightFilter is not None and light.name not in self.lightFilter:
            ignoreLight = True
        elif len(self.lights) > SkinSpotLightShadows.MAX_LIGHTS or light.coneAlphaOuter > 89:
            ignoreLight = True
        if ignoreLight:
            light.importanceScale = 0
            light.importanceBias = -9999
            light.shadowCasterTypes = 0
            return
        light.importanceScale = 0
        light.importanceBias = -len(self.lights)
        if SkinSpotLightShadows.REUSE_ENGINE_MAPS:
            self.RTs[light] = light.GetShadowTextureRes()
            rj = trinity.CreateRenderJob('render shadowmap ' + str(light))
            self.jobs[light] = [rj]
            cb = trinity.TriStepPythonCB()
            cb.name = 'UpdateViewProjForLight'
            cb.SetCallback(lambda : self.UpdateViewProjForLight(None, None, light, None))
            rj.steps.append(cb)
            rj.ScheduleRecurring()
            return
        rj = trinity.CreateRenderJob('render shadowmap ' + str(light))
        renderTarget = None
        while self.width > 8:
            renderTarget = trinity.Tr2RenderTarget(self.width, self.height, 1, self.format)
            if renderTarget is None or not renderTarget.isValid:
                renderTarget = None
                self.width /= 2
                self.height /= 2
                pdCf.Yield()
            else:
                break

        self.RTs[light] = renderTarget
        depthStencil = None
        while self.width > 8:
            depthStencil = trinity.Tr2DepthStencil(self.width, self.height, trinity.DEPTH_STENCIL_FORMAT.D24S8)
            if depthStencil is None or not depthStencil.isValid:
                depthStencil = None
                self.width /= 2
                self.height /= 2
                pdCf.Yield()
            else:
                break

        if not renderTarget or not depthStencil or not renderTarget.isValid or not depthStencil.isValid:
            return
        v = None
        rj.PushViewport()
        rj.PushRenderTarget(renderTarget)
        rj.PushDepthStencil(depthStencil)
        clearColor = (100.0, 1.0, 1.0, 1.0)
        rj.Clear(clearColor, 1.0)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = self.width
        vp.height = self.height
        rj.PushProjection()
        rj.PushViewTransform()
        rj.SetViewport(vp)
        cb = trinity.TriStepPythonCB()
        cb.name = 'UpdateViewProjForLight'
        rj.steps.append(cb)
        stepProj = rj.SetProjection(trinity.TriProjection())
        stepView = rj.SetView(trinity.TriView())
        self.UpdateViewProjForLight(stepView, stepProj, light, v)
        cb.SetCallback(lambda : self.UpdateViewProjForLight(stepView, stepProj, light, v))

        def applyVisualizer(doIt):
            for meshData in self.meshes.itervalues():
                if doIt:
                    meshData.applyShadowEffect()
                else:
                    meshData.applyOriginalEffect()

        cb = trinity.TriStepPythonCB()
        cb.name = 'applyVisualizer(True)'
        cb.SetCallback(lambda : applyVisualizer(True))
        rj.steps.append(cb)
        rj.RenderScene(self.scene)
        cb = trinity.TriStepPythonCB()
        cb.name = 'applyVisualizer(False)'
        cb.SetCallback(lambda : applyVisualizer(False))
        rj.steps.append(cb)
        rj.PopDepthStencil()
        rj.PopRenderTarget()
        rj.PopViewTransform().name = 'TriStepPopViewTransform Restoring state'
        rj.PopViewport()
        rj.PopProjection()
        if SkinSpotLightShadows.renderJob is not None and SkinSpotLightShadows.renderJob.object is not None:
            step = trinity.TriStepRunJob()
            step.job = rj
            SkinSpotLightShadows.renderJob.object.steps.insert(0, step)
        else:
            self.jobs[light] = [rj]
            rj.ScheduleRecurring(insertFront=True)
        if self.debugVisualize:
            rj2 = trinity.CreateRenderJob('visualize shadowmap ' + str(light))
            if light not in self.jobs:
                self.jobs[light] = [rj2]
            else:
                self.jobs[light].append(rj2)
            rj2.PushDepthStencil(None)
            size = 200
            vp2 = trinity.TriViewport()
            vp2.x = 10
            vp2.y = 10 + (size + 10) * (len(self.lights) - 1)
            vp2.width = size
            vp2.height = size
            rj2.PushViewport()
            rj2.PushProjection()
            rj2.PushViewTransform()
            rj2.SetViewport(vp2)
            rj2.SetStdRndStates(trinity.RM_FULLSCREEN)
            rj2.RenderTexture(renderTarget)
            rj2.PopViewTransform()
            rj2.PopProjection()
            rj2.PopViewport()
            rj2.PopDepthStencil()
            rj2.ScheduleRecurring()