Example #1
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)
Example #2
0
def CreateSceneWithUI():
    del trinity.renderJobs.recurring[:]
    scene2d = trinity.Tr2Sprite2dScene()
    scene2d.width = 512
    scene2d.height = 512
    scene2d.clearBackground = True
    scene2d.isFullScreen = False
    tex = trinity.Tr2RenderTarget(512, 512, 1,
                                  trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
    scene, screen = CreateScene3d(trinity.TriTextureRes(tex))
    scene2d.translation = screen.translation
    scene2d.rotation = screen.rotation
    scene2d.scaling = screen.scaling
    SetupAnimation(scene2d)
    rj = trinity.CreateRenderJob()
    rj.name = 'Scene with UI'
    rj.Update(scene).name = 'Update 3D scene'
    rj.Update(scene2d).name = 'Update 2D scene'
    rj.SetPushRenderTarget(tex).name = 'Set texture as render target'
    rj.RenderScene(scene2d).name = 'Render 2D scene'
    rj.SetPopRenderTarget().name = 'Set framebuffer as render target'
    rj.RenderScene(scene).name = 'Render 3D scene'
    rj.ScheduleRecurring()
    picker = Scene2dPicker(scene2d)
    trinity.device.tickInterval = 0
Example #3
0
 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))
Example #4
0
 def DoPreProcessEffectForPhotoSvc(self, size):
     renderTarget = trinity.Tr2RenderTarget(2 * size, size, 0, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
     vp = trinity.TriViewport()
     vp.width = 2 * size
     vp.height = size
     if not self.LoadRedFiles():
         return
     trinity.WaitForResourceLoads()
     heightMapParam1 = self.__GetBakeShaderParameter('NormalHeight1', 'trinity.TriTextureParameter')
     if heightMapParam1 is not None:
         heightMapParam1.resourcePath = self.heightMapResPath1
     heightMapParam2 = self.__GetBakeShaderParameter('NormalHeight2', 'trinity.TriTextureParameter')
     if heightMapParam2 is not None:
         heightMapParam2.resourcePath = self.heightMapResPath2
     renderTargetSizeParam = self.__GetBakeShaderParameter('TargetTextureHeight', 'trinity.TriTextureParameter')
     if renderTargetSizeParam is not None:
         renderTargetSizeParam.value = size
     trinity.WaitForResourceLoads()
     rj = trinity.CreateRenderJob('Height normal Compositing')
     rj.PushRenderTarget(renderTarget)
     rj.SetViewport(vp)
     rj.PushDepthStencil(None)
     rj.Clear((0.0, 0.0, 0.0, 0.0))
     rj.RenderEffect(self.effectHeight)
     rj.PopDepthStencil()
     rj.PopRenderTarget()
     rj.GenerateMipMaps(renderTarget)
     rj.ScheduleOnce()
     rj.WaitForFinish()
     tex = trinity.TriTextureRes()
     tex.CreateAndCopyFromRenderTarget(renderTarget)
     heightMapParamList = self.__GetPlanetShaderParameters('HeightMap', 'trinity.TriTextureParameter')
     for heightMapParam in heightMapParamList:
         heightMapParam.SetResource(tex)
Example #5
0
    def CreateComponent(self, name, state):
        """
        Create a UIDesktop component and return it. This performs a little bit of namespace magic
        which looks upa UIDesktop within the 'screens' namespace. A registration mechanic would be better.
        We cannot define an absolute list in the core code, to cover both Eve and Wod.
        """
        component = UIDesktopComponent()
        if 'uiDesktopName' in state:
            component.uiDesktopName = str(state['uiDesktopName'])
            component.renderTarget = blue.resMan.GetResource(
                'dynamic:/%s' % component.uiDesktopName)
            if component.renderTarget is None:
                log.LogError(
                    'Failed to acquire a render target texture for %s' %
                    component.uiDesktopName)
            try:
                import screens
                component.width, component.height, component.format, component.liveUpdates, component.autoMipMap, component.updateFunction = getattr(
                    screens, component.uiDesktopName)
            except (AttributeError, ImportError):
                log.LogException()

            if not component.liveUpdates:
                component.active = False
                component.renderJob = trinity.CreateRenderJob()
        else:
            log.LogError('No uiDesktopName set')
        self.uiDesktops.append(component)
        return component
def csaaScreenshot(useNVidiaAA, width, height, scene):
    """
    Create a renderjob that will render the scene into a buffer using CSAA, if available.
    Returns ( job, buffer ) (which can be None if you ask for CSAA and it doesn't work).
    Use Tr2HostBitmap(buffer).Save or whatever to get to the data, after doing WaitForFinish if needed
    """
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
Example #7
0
 def TakeSnapShot_Render(self, scene, size, view, projection, transparentBackground = False, bgColor = None):
     self.LogInfo('TakeSnapShot_Render')
     if transparentBackground:
         bbFormat = trinity.PIXEL_FORMAT.B8G8R8A8_UNORM
         clearColor = bgColor or (0.0, 0.0, 0.0, 0.0)
     else:
         bbFormat = trinity.PIXEL_FORMAT.B8G8R8X8_UNORM
         clearColor = bgColor or (0.0, 0.0, 0.0, 1.0)
     dsFormat = trinity.DEPTH_STENCIL_FORMAT.AUTO
     renderTarget = trinity.Tr2RenderTarget(size, size, 1, bbFormat)
     depthStencil = trinity.Tr2DepthStencil(size, size, dsFormat)
     self.LogInfo('TakeSnapShot_Render_After_Resource_Creation')
     renderJob = trinity.CreateRenderJob('TakeSnapShot')
     renderJob.PushRenderTarget(renderTarget)
     renderJob.SetProjection(projection)
     renderJob.SetView(view)
     renderJob.PushDepthStencil(depthStencil)
     renderJob.Clear(clearColor, 1.0)
     renderJob.Update(scene)
     renderJob.RenderScene(scene)
     renderJob.PopDepthStencil()
     renderJob.PopRenderTarget()
     trinity.WaitForResourceLoads()
     renderJob.ScheduleOnce()
     renderJob.WaitForFinish()
     hostCopy = trinity.Tr2HostBitmap(renderTarget)
     hostCopy.name = 'TakeSnapeShot_Render'
     return hostCopy
Example #8
0
 def Run(self, ms):
     service.Service.Run(self, ms)
     self.registeredScenes = {}
     self.registeredCameras = {}
     self.sceneLoadedEvents = {}
     self.registeredJobs = []
     self.cameraOffsetOverride = None
     self.uiBackdropScene = None
     self.ProcessImportsAndCreateScenes()
     self.primaryJob = SceneContext()
     self.secondaryJob = None
     self.loadingClearJob = trinity.CreateRenderJob()
     self.loadingClearJob.name = 'loadingClear'
     self.loadingClearJob.Clear((0, 0, 0, 1))
     self.loadingClearJob.enabled = False
     self.overlaySceneKeys = [
         ViewState.StarMap, ViewState.SystemMap, ViewState.Planet,
         ViewState.ShipTree, ViewState.DockPanel
     ]
     self._sharedResources = {}
     self.routeVisualizer = None
     self.podDeathScene = None
     self._persistedSpaceObjects = {}
     self._updateCameras = []
     if '/skiprun' not in blue.pyos.GetArg():
         self._EnableLoadingClear()
     limit = gfxsettings.Get(gfxsettings.GFX_LOD_QUALITY) * 30
     self.explosionManager = util.ExplosionManager(limit)
Example #9
0
    def PrepareBlurredBackBuffer(self):
        if self.blurredBackBufferRenderJob:
            renderJob = self.blurredBackBufferRenderJob
            renderJob.enabled = True
            for step in renderJob.steps[:]:
                renderJob.steps.remove(step)

        else:
            renderJob = trinity.CreateRenderJob()
            renderJob.name = 'Blurred Back Buffer'
            renderJob.ScheduleRecurring(insertFront=True)
            self.blurredBackBufferRenderJob = renderJob
        if not settings.char.windows.Get('enableWindowBlur', True):
            if self.blurredBackBufferRenderJob:
                self.blurredBackBufferRenderJob.enabled = False
            return
        backbuffer = trinity.device.GetRenderContext().GetDefaultBackBuffer()
        self.spaceSceneBackBufferCopy = trinity.Tr2RenderTarget()
        self.spaceSceneBackBufferCopy.Create(trinity.app.width,
                                             trinity.app.height, 1,
                                             backbuffer.format)
        self.spaceSceneBackBufferDownSizedCopy = trinity.Tr2RenderTarget()
        self.spaceSceneBackBufferDownSizedCopy.name = 'spaceSceneBackBufferDownSizedCopy'
        self.spaceSceneBackBufferDownSizedCopy.Create(trinity.app.width / 4,
                                                      trinity.app.height / 4,
                                                      1, backbuffer.format)
        step = trinity.TriStepResolve(self.spaceSceneBackBufferCopy,
                                      backbuffer)
        step.name = 'Resolve back buffer'
        renderJob.steps.append(step)
        if self.desktopBlurredBg:
            self.RemoveRootObject(self.desktopBlurredBg)
            self.desktopBlurredBg.Close()
        self.desktopBlurredBg = self.CreateRootObject(
            name='desktopBlurred',
            renderTarget=self.spaceSceneBackBufferCopy,
            renderJob=renderJob,
            isFullscreen=True)
        self.desktopBlurredBg.renderObject.clearBackground = False
        renderJob.PushDepthStencil().pushCurrent = False
        renderJob.SetVariableStore(
            'BlitCurrent',
            self.spaceSceneBackBufferCopy).name = 'Set BlitCurrent variable'
        value = (1.0 / trinity.app.width, 1.0 / trinity.app.height,
                 trinity.app.width, trinity.app.height)
        renderJob.SetVariableStore('g_texelSize',
                                   value).name = 'Set g_texelSize variable'
        renderJob.PushRenderTarget(self.spaceSceneBackBufferDownSizedCopy)
        renderJob.Clear((0, 0, 0, 0))
        effect = trinity.Tr2Effect()
        effect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/PostProcess/ColorDownFilter4.fx'
        renderJob.RenderEffect(effect)
        renderJob.PopRenderTarget()
        renderJob.PopDepthStencil()
        textureRes = trinity.TriTextureRes()
        textureRes.SetFromRenderTarget(self.spaceSceneBackBufferDownSizedCopy)
        atlasTexture = trinity.Tr2AtlasTexture()
        atlasTexture.textureRes = textureRes
        self.blurredBackBufferAtlas = atlasTexture
        sm.ScatterEvent('OnBlurredBufferCreated')
Example #10
0
def csaaScreenshot(useNVidiaAA, width, height, scene):
    try:
        csaaFmt = trinity.TRIMULTISAMPLE_8_SAMPLES if useNVidiaAA else trinity.TRIMULTISAMPLE_NONE
        csaaQty = 2 if useNVidiaAA else 0
        buffer = trinity.Tr2RenderTarget(width, height, 1,
                                         trinity.PIXEL_FORMAT.B8G8R8X8_UNORM,
                                         csaaFmt, csaaQty)
        depth = trinity.Tr2DepthStencil(width, height,
                                        trinity.DEPTH_STENCIL_FORMAT.D24S8,
                                        csaaFmt, csaaQty)
        job = trinity.CreateRenderJob('CSAA screenshot')
        job.SetRenderTarget(buffer)
        job.SetDepthStencil(depth)
        vp = trinity.TriViewport()
        vp.x = 0
        vp.y = 0
        vp.width = width
        vp.height = height
        job.SetViewport(vp)
        job.Clear((0, 0, 0, 0), 1.0)
        job.RenderScene(scene)
        trinity.SetPerspectiveProjection(trinity.GetFieldOfView(),
                                         trinity.GetFrontClip(),
                                         trinity.GetBackClip(), 1.0)
        job.ScheduleOnce()
        return (job, buffer)
    except Exception:
        return None
Example #11
0
 def CreateRJ(self,
              target,
              name,
              depthClear=0.0,
              setDepthStencil=True,
              clearColor=(0.125, 0.125, 0.125, 1.0),
              isRT=False):
     """
     Helper method to create a renderjob that has a target and viewport matching the target argument.
     """
     rj = trinity.CreateRenderJob(name)
     rj.PushRenderTarget(target.wrappedRenderTarget).name = name
     if setDepthStencil:
         rj.PushDepthStencil(self.depth)
     rj.Clear(clearColor, depthClear)
     rj.SetStdRndStates(trinity.RM_FULLSCREEN)
     vp = trinity.TriViewport()
     vp.x = 0
     vp.y = 0
     if False:
         rdesc = target.GetDesc()
         vp.width = rdesc['Width']
         vp.height = rdesc['Height']
     else:
         vp.width = target.width
         vp.height = target.height
     rj.SetViewport(vp)
     return rj
    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
Example #13
0
 def DisplayScene(self,
                  addClearStep=False,
                  addBitmapStep=False,
                  addShadowStep=False,
                  backgroundImage=None):
     self.renderJob = trinity.CreateRenderJob('SceneInScene')
     self.renderJob.SetViewport(self.viewport)
     self.projection.PerspectiveFov(self.fieldOfView,
                                    self.viewport.GetAspectRatio(),
                                    self.frontClip, self.backClip)
     self.renderJob.SetProjection(self.projection)
     self.renderJob.SetView(None, self.camera, None)
     self.renderJob.Update(self.scene)
     if addShadowStep:
         paperDoll.SkinSpotLightShadows.CreateShadowStep(self.renderJob)
     if addClearStep:
         self.renderJob.Clear((0.2, 0.2, 0.2, 1.0), 1.0)
     if addBitmapStep:
         if backgroundImage is None:
             backgroundImage = 'res:/UI/Texture/preview/asset_preview_background.png'
         step = bitmapjob.makeBitmapStep(backgroundImage,
                                         scaleToFit=False,
                                         color=(1.0, 1.0, 1.0, 1.0))
         self.renderJob.steps.append(step)
     self.renderJob.RenderScene(self.scene)
     self.renderObject.renderJob = self.renderJob
Example #14
0
 def Create3DRender(self):
     self.renderTexture = trinity.TriTexture2DParameter()
     self.renderTexture.name = 'DiffuseMap'
     self.renderColor = trinity.TriVector4Parameter()
     self.renderColor.name = 'DiffuseColor'
     self.renderColor.value = (1, 1, 1, 1)
     self.renderEffect = trinity.Tr2Effect()
     self.renderEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/TextureColor.fx'
     self.renderEffect.resources.append(self.renderTexture)
     self.renderEffect.parameters.append(self.renderColor)
     self.renderArea = trinity.Tr2MeshArea()
     self.renderArea.effect = self.renderEffect
     self.renderMesh = trinity.Tr2Mesh()
     self.renderMesh.name = 'orbitalBombardmentTarget'
     self.renderMesh.geometryResPath = 'res:/Graphics/Generic/UnitPlane/UnitPlane.gr2'
     self.renderMesh.transparentAreas.append(self.renderArea)
     self.transform = trinity.EveRootTransform()
     self.transform.mesh = self.renderMesh
     self.renderScene.objects.append(self.transform)
     self.renderJob = trinity.CreateRenderJob()
     self.renderJob.Update(self.renderScene)
     self.renderObject = self.GetRenderObject()
     self.renderObject.is2dPick = False
     self.renderTarget = trinity.Tr2RenderTarget(
         self.width, self.height, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
     self.renderJob.PushRenderTarget(self.renderTarget)
     self.renderJob.RenderScene(self.renderObject)
     self.renderJob.PopRenderTarget()
     self.renderJob.ScheduleRecurring(insertFront=True)
     self.renderTexture.SetResource(trinity.TriTextureRes(
         self.renderTarget))
     self.renderSteps[-1].enabled = False
     return self.transform
Example #15
0
    def AssembleRenderJob(self):
        renderJob = trinity.CreateRenderJob('Graphs')
        for grp in self.graphGroups.values():
            renderJob.SetViewport(grp['viewport'])
            renderJob.steps.append(grp['renderer'])

        return renderJob
Example #16
0
def addBitmapRenderJob(filePath, scaleToFit = True, color = (1.0, 1.0, 1.0, 1.0), targetSize = None):
    """
    Helper for the common case where we just want a bitmap in a simple renderjob, no fuss.
    """
    rj = trinity.CreateRenderJob('Background bitmap')
    step = makeBitmapStep(filePath, scaleToFit=scaleToFit, color=color, targetSize=targetSize)
    rj.steps.append(step)
    rj.ScheduleRecurring()
Example #17
0
 def Start(self, clear = True):
     self.renderJob = trinity.CreateRenderJob('Texture Compositing')
     self.renderJob.PushRenderTarget(self.renderTarget)
     self.renderJob.PushDepthStencil(None)
     if clear:
         cl = self.renderJob.Clear((0.0, 1.0, 0.0, 0.0), 1.0)
         cl.isDepthCleared = False
     self.renderJob.SetStdRndStates(trinity.RM_FULLSCREEN)
Example #18
0
 def DisplayScene(self):
     self.renderJob = trinity.CreateRenderJob()
     self.renderJob.SetViewport(self.viewport)
     self.renderJob.SetView(None, self.camera, None)
     self.renderJob.SetProjection(self.projection)
     self.renderJob.Update(self.scene)
     self.renderJob.RenderScene(self.scene)
     self.renderObject.renderJob = self.renderJob
Example #19
0
    def DoPreProcessEffect(self, size, format, renderTarget):
        if renderTarget is None:
            self.model.resourceActionPending = False
            self.model.ready = True
            return
        vp = trinity.TriViewport()
        vp.width = 2 * size
        vp.height = size
        trinity.WaitForResourceLoads()
        if self.model is None:
            return
        if len(self.modelRes) == 0:
            if not self.LoadRedFiles():
                self.model.resourceActionPending = False
                self.model.ready = True
                return
        else:
            self.__ReloadLargeResources()
        heightMapParam1 = self.__GetBakeShaderParameter('NormalHeight1', 'trinity.TriTextureParameter')
        if heightMapParam1 is not None:
            heightMapParam1.resourcePath = self.heightMapResPath1
        heightMapParam2 = self.__GetBakeShaderParameter('NormalHeight2', 'trinity.TriTextureParameter')
        if heightMapParam2 is not None:
            heightMapParam2.resourcePath = self.heightMapResPath2
        renderTargetSizeParam = self.__GetBakeShaderParameter('TargetTextureHeight', 'trinity.TriTextureParameter')
        if renderTargetSizeParam is not None:
            renderTargetSizeParam.value = size
        trinity.WaitForResourceLoads()
        if self.model is None:
            return
        rj = trinity.CreateRenderJob('Height normal Compositing')
        rj.PushRenderTarget(renderTarget)
        rj.SetViewport(vp)
        rj.PushDepthStencil(None)
        step = rj.Clear((0.0, 0.0, 0.0, 0.0), 1.0)
        step.isDepthCleared = False
        rj.RenderEffect(self.effectHeight)
        rj.PopDepthStencil()
        rj.PopRenderTarget()
        rj.GenerateMipMaps(renderTarget)
        rj.ScheduleOnce()
        rj.WaitForFinish()
        if self.model is None:
            return
        tex = trinity.TriTextureRes()
        tex.CreateAndCopyFromRenderTargetWithSize(renderTarget, size * 2, size)
        if heightMapParam1 is not None:
            heightMapParam1.resourcePath = ''
            heightMapParam1.SetResource(None)
        if heightMapParam2 is not None:
            heightMapParam2.resourcePath = ''
            heightMapParam2.SetResource(None)
        heightMapParamList = self.__GetPlanetShaderParameters('HeightMap', 'trinity.TriTextureParameter')
        for heightMapParam in heightMapParamList:
            heightMapParam.SetResource(tex)

        self.model.ready = True
        self.model.resourceActionPending = False
Example #20
0
 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
Example #22
0
 def CreateDebugRenderer(self):
     job = getattr(self, 'DebugRenderJob', None)
     if not job:
         render_job = trinity.CreateRenderJob('DebugRender')
         self.debugRenderStep = trinity.TriStepRenderDebug()
         render_job.steps.append(self.debugRenderStep)
         render_job.ScheduleRecurring()
         GameWorld.SetDebugRenderer(self.debugRenderStep)
         render = sm.GetService('debugRenderClient')
         render.SetDebugRendering(True)
         setattr(self, 'DebugRenderJob', True)
Example #23
0
 def SetDebugRendering(self, enabled):
     self.debugRender = enabled
     if enabled and self.renderJob is None:
         self.renderJob = trinity.CreateRenderJob()
         dr = self.renderJob.RenderDebug()
         dr.name = 'DebugRendererInPlace'
         trinity.SetDebugRenderer(dr)
         self.renderJob.ScheduleRecurring()
     elif not enabled and self.renderJob is not None:
         self.renderJob.UnscheduleRecurring()
         self.renderJob = None
Example #24
0
def addBitmapRenderJob(filePath,
                       scaleToFit=True,
                       color=(1.0, 1.0, 1.0, 1.0),
                       targetSize=None):
    rj = trinity.CreateRenderJob('Background bitmap')
    step = makeBitmapStep(filePath,
                          scaleToFit=scaleToFit,
                          color=color,
                          targetSize=targetSize)
    rj.steps.append(step)
    rj.ScheduleRecurring()
Example #25
0
    def StartGhostRenderJob(self,
                            avatar,
                            fxPath,
                            rjName='Avatar Ghost',
                            meshFilter=None,
                            insertFront=True):
        self.StopGhostRenderJob()
        if avatar is None or avatar.visualModel is None or not avatar.visualModel.meshes:
            return
        rj = trinity.CreateRenderJob(rjName)
        self.ghostRJ = rj
        self.avatar = avatar.CloneTo()
        self.avatar.clothMeshes.removeAt(-1)
        self.avatar.rotation = avatar.rotation
        self.avatar.translation = avatar.translation
        self.avatar.animationUpdater = avatar.animationUpdater
        for meshIx in xrange(len(avatar.visualModel.meshes)):
            mesh = avatar.visualModel.meshes[meshIx]
            self.avatar.visualModel.meshes[meshIx].SetGeometryRes(
                mesh.geometry)

        effect = trinity.Tr2Effect()
        effect.effectFilePath = fxPath
        effect.PopulateParameters()
        effect.RebuildCachedData()
        while effect.effectResource.isLoading:
            Yield()

        fx = []
        index = 0
        while index < len(self.avatar.visualModel.meshes):
            mesh = self.avatar.visualModel.meshes[index]
            if meshFilter is not None and not meshFilter(mesh):
                self.avatar.visualModel.meshes.removeAt(index)
            else:
                index = index + 1
                areasList = [
                    mesh.opaqueAreas, mesh.decalAreas, mesh.transparentAreas
                ]
                for areas in areasList:
                    for area in areas:
                        area.effect = effect
                        fx.append(area.effect)

        self.ghostScene = trinity.WodBakingScene()
        self.ghostScene.Avatar = self.avatar
        rj.SetStdRndStates(trinity.RM_OPAQUE)
        rj.Update(self.ghostScene)
        rj.RenderScene(self.ghostScene)
        if AvatarGhost.renderStepSlot is not None and AvatarGhost.renderStepSlot.object is not None:
            AvatarGhost.renderStepSlot.object.job = rj
        else:
            rj.ScheduleRecurring(insertFront=insertFront)
        return fx
Example #26
0
 def DisplayScene(self):
     """
     Create a Render Job which renders this job on top of this window.
     """
     self.renderJob = trinity.CreateRenderJob()
     self.renderJob.SetViewport(self.viewport)
     self.renderJob.SetView(None, self.camera, None)
     self.renderJob.SetProjection(self.projection)
     self.renderJob.Update(self.scene)
     self.renderJob.RenderScene(self.scene)
     self.renderObject.renderJob = self.renderJob
    def Show(self, width=800, height=600):
        displayMode = trinity.adapters.GetCurrentDisplayMode(0)
        trinity.app.width = width
        trinity.app.height = height
        trinity.app.left = (displayMode.width - trinity.app.width) / 2
        trinity.app.top = (displayMode.height - trinity.app.height) / 2
        trinity.app.windowed = True
        trinity.app.AdjustWindowForChange(True, True)
        trinity.app.Create()
        pp = {
            'BackBufferWidth': trinity.app.width,
            'BackBufferHeight': trinity.app.height,
            'Windowed': True,
            'EnableAutoDepthStencil': True,
            'AutoDepthStencilFormat': trinity.DEPTH_STENCIL_FORMAT.D24S8,
            'BackBufferFormat': trinity.PIXEL_FORMAT.B8G8R8A8_UNORM,
            'PresentationInterval': trinity.PRESENT_INTERVAL.IMMEDIATE
        }
        trinity.app.ChangeDevice(0, 0, 0, pp)
        self.renderjob = trinity.CreateRenderJob('LoadingScreen')
        scene = trinity.Tr2Sprite2dScene()
        scene.isFullscreen = True
        scene.clearBackground = True
        scene.backgroundColor = (0, 0, 0, 0)
        self.renderjob.Update(scene)
        self.renderjob.RenderScene(scene)
        self.renderjob.ScheduleRecurring()
        sprite = trinity.Tr2Sprite2d()
        sprite.displayWidth = 32
        sprite.displayHeight = 32
        sprite.spriteEffect = trinity.TR2_SFX_FILL
        sprite.color = (1, 1, 1, 1)
        scene.children.append(sprite)

        def loading_screen():
            x = 100
            dx = 4
            y = height * 2 / 3
            while self.active:
                sprite.displayX = x
                sprite.displayY = y
                x += dx
                if x > width - 100 - sprite.displayWidth:
                    dx = -dx
                if x < 100:
                    dx = -dx
                blue.synchro.Yield()

        self.active = True
        uthread2.StartTasklet(loading_screen)
        blue.os.Pump()
        blue.os.Pump()
        blue.os.Pump()
Example #28
0
 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)
Example #29
0
def CreateCompactJob(inputUav,
                     outputTidUav,
                     outputCountUav,
                     debugging=False,
                     sumCounts=True):
    NUM_ELEM = inputUav.numElements
    NUM_THREAD_PER_BLOCK = 256
    NUM_BLOCKS_PHASE1 = max(1, (NUM_ELEM + NUM_THREAD_PER_BLOCK - 1) /
                            NUM_THREAD_PER_BLOCK)
    rj = trinity.CreateRenderJob('Compact')
    intermediate = trinity.Tr2UavBuffer(NUM_ELEM,
                                        trinity.PIXEL_FORMAT.R32_UINT)
    intermediate.name = 'intermediate'
    sumJob = trinity.gpuComputeUtils.CreatePrefixSumJob(
        inputUav, intermediate, debugging, folder='prefixSumCompaction')
    if sumJob.steps[-1].name != 'phase3':
        return None
    dispatchParams = trinity.Tr2UavBuffer()
    dispatchParams.CreateEx(3, trinity.PIXEL_FORMAT.R32_UINT,
                            trinity.EX_FLAG.DRAW_INDIRECT)
    dispatchParams.name = 'dispatchParams'
    sumJob.steps[-1].SetUavBuffer(3, dispatchParams)
    rj.RunJob(sumJob)
    if sumCounts:
        size = outputCountUav.numElements
        size = max(512, (size + 511) / 512 * 512)
        intermediateCount = trinity.Tr2UavBuffer(size,
                                                 trinity.PIXEL_FORMAT.R32_UINT)
        intermediateCount.name = 'intermediateCount'
    fxPath = 'res:/graphics/effect/compute/compaction/'
    phase1fx = trinity.Tr2Effect()
    phase1fx.effectFilePath = fxPath + 'phase1.fx'
    blue.resMan.Wait()
    phase1 = trinity.TriStepRunComputeShader(phase1fx, NUM_BLOCKS_PHASE1)
    phase1.name = 'phase1'
    if debugging:
        phase1fx.effectResource.Reload()
        phase1.logDispatchTime = True
    phase1.SetSrvBuffer(0, inputUav)
    phase1.SetSrvBuffer(1, intermediate)
    phase1.SetUavBuffer(2, outputTidUav)
    phase1.SetUavBuffer(3,
                        outputCountUav if not sumCounts else intermediateCount)
    phase1.autoClearUav = False
    rj.steps.append(phase1)
    if sumCounts:
        sumJob = trinity.gpuComputeUtils.CreatePrefixSumJob(
            intermediateCount, outputCountUav, debugging)
        sumJob.steps[0].indirectionBuffer = dispatchParams
        sumJob.steps[2].indirectionBuffer = dispatchParams
        rj.RunJob(sumJob)
    return (rj, intermediate, dispatchParams)
    def _ExpandOpaque(self, bodyPart, targetTex):
        """
        Using pre-generated masks, we bleed the opaque accross the edges defined by said masks.
        This reduces visible seams when the tattoos have been projected in object space so that 
        their pixels in UV space aren't continuous.
        """
        eoMaskPath = 'res:/graphics/character/global/tattoomask/{0}_opaque_mask_{1}.dds'.format(self._gender, bodyPart)
        eoMaskRes = blue.resMan.GetResource(eoMaskPath)
        fx = trinity.Tr2Effect()
        fx.effectFilePath = EO_SHADERRES
        while eoMaskRes.isLoading or fx.effectResource.isLoading:
            PD.Yield()

        tex = trinity.TriTexture2DParameter()
        tex.name = 'Mask'
        tex.SetResource(eoMaskRes)
        fx.resources.append(tex)
        v = trinity.Tr2Vector2Parameter()
        v.name = 'gMaskSize'
        v.value = (eoMaskRes.width, eoMaskRes.height)
        fx.parameters.append(v)
        tex = trinity.TriTexture2DParameter()
        tex.name = 'Texture'
        tex.SetResource(targetTex)
        fx.resources.append(tex)
        v = trinity.Tr2Vector2Parameter()
        v.name = 'gTextureSize'
        v.value = (targetTex.width, targetTex.height)
        fx.parameters.append(v)
        fx.RebuildCachedData()
        vp = trinity.TriViewport()
        vp.width = targetTex.width
        vp.height = targetTex.height
        expandedRT = trinity.Tr2RenderTarget(vp.width, vp.height, 1, trinity.PIXEL_FORMAT.B8G8R8A8_UNORM)
        rj = trinity.CreateRenderJob('Expanding Opaque')
        rj.PushRenderTarget(expandedRT)
        rj.SetProjection(trinity.TriProjection())
        rj.SetView(trinity.TriView())
        rj.SetViewport(vp)
        rj.PushDepthStencil(None)
        rj.Clear((0.0, 0.0, 0.0, 0.0))
        rj.SetStdRndStates(trinity.RM_FULLSCREEN)
        rj.SetRenderState(trinity.D3DRS_SEPARATEALPHABLENDENABLE, 1)
        rj.SetRenderState(trinity.D3DRS_SRCBLENDALPHA, trinity.TRIBLEND_ONE)
        rj.SetRenderState(trinity.D3DRS_DESTBLENDALPHA, trinity.TRIBLEND_ZERO)
        rj.RenderEffect(fx)
        rj.SetRenderTarget(targetTex.wrappedRenderTarget)
        rj.RenderTexture(expandedRT)
        rj.PopRenderTarget()
        rj.PopDepthStencil()
        rj.ScheduleChained()
        rj.WaitForFinish()