def RenderLightmap(self):
     rj = self.CreateRJ(self.lightmap, 'Lightmap rendering', depthClear=None, setDepthStencil=False, clearColor=(0, 0, 0, 0))
     self.lightmapRenderJob = rj
     self.AddCallback(SkinLightmapRenderer.OnBeforeUnwrap, 'onBeforeUnwrap')
     doHighZOptimization = False
     if not doHighZOptimization:
         rj.PushDepthStencil(None).name = 'Depthbuffer = None'
     rj.RenderScene(SkinLightmapRenderer.Scene()).name = 'Unwrap light pass'
     self.AddCallback(SkinLightmapRenderer.OnAfterUnwrap, 'onAfterUnwrap')
     rj.SetRenderTarget(self.scatteredLightmap.wrappedRenderTarget).name = 'Set Scattermap RT'
     self.AddCallback(SkinLightmapRenderer.OnBeforeBlur, 'onBeforeBlur')
     rj.SetStdRndStates(trinity.RM_FULLSCREEN)
     rj.RenderEffect(self.lightmapScatterEffect).name = 'Light blur pass'
     if self.useExpandOpaque:
         rj.SetRenderTarget(self.lightmap.wrappedRenderTarget).name = 'Set Lightmap RT for expand'
         self.AddCallback(SkinLightmapRenderer.OnBeforeExpand, 'onBeforeExpand')
         rj.RenderEffect(self.lightmapExpandEffect).name = 'Expand lightmap'
     self.AddCallback(SkinLightmapRenderer.OnAfterExpand, 'onAfterExpand')
     rj.PopRenderTarget().name = 'PopRT - main scene rendering'
     if not doHighZOptimization:
         rj.PopDepthStencil()
     if SkinLightmapRenderer.renderJob is not None and SkinLightmapRenderer.renderJob.object is not None:
         step = trinity.TriStepRunJob()
         step.job = rj
         SkinLightmapRenderer.renderJob.object.steps.append(step)
     else:
         jobs = trinity.renderJobs.recurring
         for job in jobs:
             if 'paperdoll' in job.name.lower():
                 step = trinity.TriStepRunJob(rj)
                 step.name = rj.name
                 job.steps.insert(len(job.steps) - 1, step)
                 break
         else:
             rj.ScheduleRecurring()
 def _CreateBackgroundStep(self, scene = None):
     if scene is None:
         scene = self.GetScene()
     job = trinity.CreateRenderJob()
     job.steps.append(trinity.TriStepRenderPass(scene, trinity.TRIPASS_BACKGROUND_RENDER))
     job.steps.append(trinity.TriStepRunJob(self.backgroundDistortionJob))
     self.AddStep('RENDER_BACKGROUND', trinity.TriStepRunJob(job))
 def _DoFormatConversionStep(self, hdrTexture, msaaTexture = None):
     job = trinity.CreateRenderJob()
     job.name = 'DoFormatConversion'
     if msaaTexture is not None:
         if hdrTexture is not None:
             job.steps.append(trinity.TriStepResolve(hdrTexture, msaaTexture))
         else:
             job.steps.append(trinity.TriStepResolve(self.GetBackBufferRenderTarget(), msaaTexture))
             return trinity.TriStepRunJob(job)
     job.steps.append(trinity.TriStepSetStdRndStates(trinity.RM_FULLSCREEN))
     job.steps.append(trinity.TriStepRenderTexture(hdrTexture))
     return trinity.TriStepRunJob(job)
Exemple #4
0
 def RenderLightmap(self):
     """
     Create all renderjobs needed to do the whole thing:
     1. Render the scene using a light unwrap shader, saving out diffuse shading only
     2. Dipole blur this map
     3. Render the scene again with regular shading, except that all diffuse lighting comes from the output of step 2.
        This is actually part of the main rendering, we just need to make sure we exit with a decent setup (effect in place, step 2 RT attached)
     """
     rj = self.CreateRJ(self.lightmap,
                        'Lightmap rendering',
                        depthClear=None,
                        setDepthStencil=False,
                        clearColor=(0, 0, 0, 0))
     self.lightmapRenderJob = rj
     self.AddCallback(SkinLightmapRenderer.OnBeforeUnwrap, 'onBeforeUnwrap')
     doHighZOptimization = False
     if not doHighZOptimization:
         rj.PushDepthStencil(None).name = 'Depthbuffer = None'
     rj.RenderScene(SkinLightmapRenderer.Scene()).name = 'Unwrap light pass'
     self.AddCallback(SkinLightmapRenderer.OnAfterUnwrap, 'onAfterUnwrap')
     rj.SetRenderTarget(self.scatteredLightmap.wrappedRenderTarget
                        ).name = 'Set Scattermap RT'
     self.AddCallback(SkinLightmapRenderer.OnBeforeBlur, 'onBeforeBlur')
     rj.SetStdRndStates(trinity.RM_FULLSCREEN)
     rj.RenderEffect(self.lightmapScatterEffect).name = 'Light blur pass'
     if self.useExpandOpaque:
         rj.SetRenderTarget(self.lightmap.wrappedRenderTarget
                            ).name = 'Set Lightmap RT for expand'
         self.AddCallback(SkinLightmapRenderer.OnBeforeExpand,
                          'onBeforeExpand')
         rj.RenderEffect(self.lightmapExpandEffect).name = 'Expand lightmap'
     self.AddCallback(SkinLightmapRenderer.OnAfterExpand, 'onAfterExpand')
     rj.PopRenderTarget().name = 'PopRT - main scene rendering'
     if not doHighZOptimization:
         rj.PopDepthStencil()
     if SkinLightmapRenderer.renderJob is not None and SkinLightmapRenderer.renderJob.object is not None:
         step = trinity.TriStepRunJob()
         step.job = rj
         SkinLightmapRenderer.renderJob.object.steps.append(step)
     else:
         jobs = trinity.renderJobs.recurring
         for job in jobs:
             if 'paperdoll' in job.name.lower():
                 step = trinity.TriStepRunJob(rj)
                 step.name = rj.name
                 job.steps.insert(len(job.steps) - 1, step)
                 break
         else:
             rj.ScheduleRecurring()
Exemple #5
0
 def _SetupRenderJob(self):
     self.renderJob = trinity.CreateRenderJob()
     self.renderJob.name = 'UI'
     self.PrepareBlurredBackBuffer()
     self.sceneViewStep = self.renderJob.SetView()
     self.scaledViewportStep = self.renderJob.SetViewport()
     self.sceneProjectionStep = self.renderJob.SetProjection()
     videoJobStep = self.renderJob.RunJob()
     videoJobStep.name = 'Videos'
     self.videoJob = trinity.CreateRenderJob()
     self.videoJob.name = 'Update videos job'
     videoJobStep.job = self.videoJob
     self.bracketCurveSet = trinity.TriCurveSet()
     self.bracketCurveSet.Play()
     self.renderJob.Update(self.bracketCurveSet).name = 'Update brackets'
     self.renderJob.SetViewport()
     self.renderJob.PythonCB(self.Update).name = 'Update uilib'
     self.desktopRenderJob = trinity.CreateRenderJob()
     self.desktopRenderJob.name = 'Desktop'
     self.renderJob.steps.append(
         trinity.TriStepRunJob(self.desktopRenderJob))
     isFpsEnabled = trinity.IsFpsEnabled()
     if isFpsEnabled:
         trinity.SetFpsEnabled(False)
     self.renderJob.ScheduleRecurring()
     if isFpsEnabled:
         trinity.SetFpsEnabled(True)
Exemple #6
0
 def CreateSculptingStep(renderJob, append=True):
     ghostStep = trinity.TriStepRunJob()
     ghostStep.name = 'Sculpting overlay'
     if append:
         renderJob.steps.append(ghostStep)
     AvatarGhost.renderStepSlot = blue.BluePythonWeakRef(ghostStep)
     return ghostStep
 def SetRenderTargets(self, customBackBuffer, customDepthStencil, depthTexture, blitTexture, distortionTexture):
     self.RemoveStep('SET_DEPTH')
     if self.GetSwapChain() is not None:
         self.AddStep('SET_SWAPCHAIN_RT', trinity.TriStepSetRenderTarget(self.GetSwapChain().backBuffer))
         self.AddStep('SET_SWAPCHAIN_DEPTH', trinity.TriStepSetDepthStencil(self.GetSwapChain().depthStencilBuffer))
     else:
         self.RemoveStep('SET_SWAPCHAIN_RT')
         self.RemoveStep('SET_SWAPCHAIN_DEPTH')
     activePostProcessing = self.usePostProcessing and self.postProcessingJob.liveCount > 0
     if customBackBuffer is not None:
         self.AddStep('SET_CUSTOM_RT', trinity.TriStepPushRenderTarget(customBackBuffer))
         self.AddStep('SET_FINAL_RT', trinity.TriStepPopRenderTarget())
         if self.msaaEnabled and not activePostProcessing:
             if self.hdrEnabled:
                 self.AddStep('FINAL_BLIT', self._DoFormatConversionStep(blitTexture, customBackBuffer))
             else:
                 self.AddStep('FINAL_BLIT', trinity.TriStepResolve(self.GetBackBufferRenderTarget(), customBackBuffer))
         elif self.hdrEnabled and not activePostProcessing and not self.msaaEnabled:
             self.AddStep('FINAL_BLIT', self._DoFormatConversionStep(customBackBuffer))
         else:
             self.RemoveStep('FINAL_BLIT')
         if self.fxaaEnabled:
             self.AddStep('SET_VAR_GATHER', trinity.TriStepSetVariableStore('GatherMap', customBackBuffer))
             self.RemoveStep('FINAL_BLIT')
         else:
             self.RemoveStep('SET_VAR_GATHER')
     else:
         self.RemoveStep('SET_CUSTOM_RT')
         self.RemoveStep('FINAL_BLIT')
         self.RemoveStep('SET_FINAL_RT')
         self.RemoveStep('SET_VAR_GATHER')
     if customDepthStencil is not None:
         self.AddStep('SET_DEPTH', trinity.TriStepPushDepthStencil(customDepthStencil))
         self.AddStep('RESTORE_DEPTH', trinity.TriStepPopDepthStencil())
     else:
         self.RemoveStep('RESTORE_DEPTH')
     if self.depthTexture is not None:
         if not self.doDepthPass:
             self.AddStep('SET_DEPTH', trinity.TriStepPushDepthStencil(depthTexture))
             self.AddStep('RESTORE_DEPTH', trinity.TriStepPopDepthStencil())
         self._SetDepthMap()
         self.AddStep('SET_VAR_DEPTH', trinity.TriStepSetVariableStore('DepthMap', depthTexture))
     else:
         if not self.msaaEnabled:
             self.RemoveStep('SET_DEPTH')
             self.RemoveStep('RESTORE_DEPTH')
         self.RemoveStep('SET_VAR_DEPTH')
     self._RefreshPostProcessingJob(self.postProcessingJob, self.usePostProcessing and self.prepared)
     self._RefreshPostProcessingJob(self.distortionJob, self.distortionEffectsEnabled and self.prepared)
     self._RefreshPostProcessingJob(self.backgroundDistortionJob, self.distortionEffectsEnabled and self.prepared)
     if distortionTexture is not None:
         self.AddStep('DO_DISTORTIONS', trinity.TriStepRunJob(self.distortionJob))
         distortionTriTextureRes = trinity.TriTextureRes()
         distortionTriTextureRes.SetFromRenderTarget(distortionTexture)
         self.distortionJob.SetPostProcessVariable('Distortion', 'TexDistortion', distortionTriTextureRes)
         self.backgroundDistortionJob.SetPostProcessVariable('Distortion', 'TexDistortion', distortionTriTextureRes)
     else:
         self.RemoveStep('DO_DISTORTIONS')
     self._CreateDepthPass()
 def CreateScatterStep(renderJob, scene, append = True):
     step = trinity.TriStepRunJob()
     step.name = 'Subsurface scattering'
     step.job = trinity.CreateRenderJob('Render scattering')
     if append:
         renderJob.steps.append(step)
     SkinLightmapRenderer.renderJob = blue.BluePythonWeakRef(step.job)
     SkinLightmapRenderer.scene = blue.BluePythonWeakRef(scene)
     return step
 def CreateShadowStep(renderJob, append = True):
     shadowStep = trinity.TriStepRunJob()
     shadowStep.name = 'Spotlight shadows'
     shadowStep.job = trinity.CreateRenderJob('Render shadowmaps')
     if append:
         renderJob.steps.append(shadowStep)
     SkinSpotLightShadows.renderJob = blue.BluePythonWeakRef(shadowStep.job)
     if SkinSpotLightShadows.instance is not None:
         SkinSpotLightShadows.instance.RefreshLights()
     return shadowStep
Exemple #10
0
 def _DoPostProcess(self, pp, source):
     job = trinity.TriRenderJob()
     job.name = 'Run Post Process ' + str(pp.name)
     self._AppendStep(
         'Set var BlitOriginal',
         trinity.TriStepSetVariableStore('BlitOriginal',
                                         self.resolveTarget), job)
     self._AppendStep(
         'Set var BlitCurrent',
         trinity.TriStepSetVariableStore('BlitCurrent', self.resolveTarget),
         job)
     pp.AddSteps(job)
     self._AppendStep(job.name, trinity.TriStepRunJob(job))
Exemple #11
0
 def _CreateDepthPass(self):
     rj = trinity.TriRenderJob()
     if self.enabled and self.doDepthPass and self.depthTexture is not None:
         rj.steps.append(trinity.TriStepPushViewport())
         rj.steps.append(trinity.TriStepPushRenderTarget(self._GetRTForDepthPass()))
         rj.steps.append(trinity.TriStepPushDepthStencil(self.depthTexture))
         rj.steps.append(trinity.TriStepPopViewport())
         rj.steps.append(trinity.TriStepPushViewport())
         rj.steps.append(trinity.TriStepRenderPass(self.GetScene(), trinity.TRIPASS_DEPTH_PASS))
         rj.steps.append(trinity.TriStepPopDepthStencil())
         rj.steps.append(trinity.TriStepPopRenderTarget())
         rj.steps.append(trinity.TriStepPopViewport())
     self.AddStep('RENDER_DEPTH_PASS', trinity.TriStepRunJob(rj))
Exemple #12
0
def CreatePrefixSumJob(inputUav,
                       outputUav,
                       debugging=False,
                       allowRecursion=True,
                       folder='prefixsum'):
    NUM_ELEM = inputUav.numElements
    if NUM_ELEM & 3:
        return None
    NUM_THREAD_PER_BLOCK = 256
    NUM_BLOCKS_PHASE1 = max(1,
                            ((NUM_ELEM + 3) / 4 + NUM_THREAD_PER_BLOCK - 1) /
                            NUM_THREAD_PER_BLOCK)
    fxPath = 'res:/graphics/effect/compute/' + folder + '/'
    phase1fx = trinity.Tr2Effect()
    phase1fx.effectFilePath = fxPath + 'phase1.fx'
    recurse = allowRecursion and NUM_BLOCKS_PHASE1 >= 1024 and NUM_BLOCKS_PHASE1 % 4 == 0
    if not recurse:
        phase2fx = trinity.Tr2Effect()
        phase2fx.effectFilePath = fxPath + 'phase2.fx'
    phase3fx = trinity.Tr2Effect()
    phase3fx.effectFilePath = fxPath + 'phase3.fx'
    blue.resMan.Wait()
    if debugging:
        phase1fx.effectResource.Reload()
        if not recurse:
            phase2fx.effectResource.Reload()
        phase3fx.effectResource.Reload()
    blockOffsets = trinity.Tr2UavBuffer(NUM_BLOCKS_PHASE1,
                                        trinity.PIXEL_FORMAT.R32_UINT)
    blockOffsets.name = 'blockOffsets'
    phase1 = trinity.TriStepRunComputeShader(phase1fx, NUM_BLOCKS_PHASE1, 1)
    if recurse:
        summedBlockOffsets = trinity.Tr2UavBuffer(
            NUM_BLOCKS_PHASE1, trinity.PIXEL_FORMAT.R32_UINT)
        phase2 = CreatePrefixSumJob(blockOffsets, summedBlockOffsets,
                                    debugging)
        phase2 = trinity.TriStepRunJob(phase2)
    else:
        phase2 = trinity.TriStepRunComputeShader(phase2fx, 1, 1)
    phase3 = trinity.TriStepRunComputeShader(phase3fx, NUM_BLOCKS_PHASE1, 1)
    if debugging:
        phase1.logDispatchTime = True
        if not recurse:
            phase2.logDispatchTime = True
        phase3.logDispatchTime = True
    phase1.name = 'phase1'
    phase2.name = 'phase2'
    phase3.name = 'phase3'
    input4 = trinity.Tr2UavBuffer()
    input4.CreateAlias(inputUav, trinity.PIXEL_FORMAT.R32G32B32A32_UINT)
    input4.name = 'input4'
    rj = trinity.CreateRenderJob('PrefixSum')
    phase1.SetSrvBuffer(0, input4)
    phase1.SetUavBuffer(1, blockOffsets)
    phase1.autoClearUav = False
    phase1.autoResetUav = True
    if not recurse:
        phase2.SetUavBuffer(1, blockOffsets)
        phase2.autoClearUav = False
        phase2.autoResetUav = True
    phase3.SetSrvBuffer(0, input4)
    phase3.SetUavBuffer(1, blockOffsets if not recurse else summedBlockOffsets)
    phase3.SetUavBuffer(2, outputUav)
    phase3.autoClearUav = False
    phase3.autoResetUav = True
    rj.steps.append(phase1)
    rj.steps.append(phase2)
    rj.steps.append(phase3)
    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()
 def SetCameraUpdate(self, job):
     self.AddStep('UPDATE_CAMERA', trinity.TriStepRunJob(job))
Exemple #15
0
 def EnablePostProcessing(self, enabled):
     if enabled:
         self.AddStep('RJ_POSTPROCESSING', trinity.TriStepRunJob(self.postProcessingJob))
     else:
         self.RemoveStep('RJ_POSTPROCESSING')