Exemplo n.º 1
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')
Exemplo n.º 2
0
    def SetFreeLook(self, freeLook=True):
        """
        Allows freelook to be enabled/disabled
        """
        if self._freeLook == freeLook:
            return
        self._freeLook = freeLook
        camera = self._cameraSvc.GetSpaceCamera()
        if camera is None:
            return
        if freeLook:
            cameraParent = self._cameraSvc.GetCameraParent()
            cameraParent.translationCurve = None
            self.axisLines = trinity.Tr2LineSet()
            self.axisLines.effect = trinity.Tr2Effect()
            self.axisLines.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/LinesWithZ.fx'
            self._clientToolsScene = self._GetClientToolsScene()
            self._clientToolsScene.primitives.append(self.axisLines)
            self._ChangeCamPos(cameraParent.translation)
            self._BuildGridAndAxes()
            uthread.new(self._UpdateFreelookCamera)
        else:
            self._cameraSvc.ResetCamera()
            try:
                self._clientToolsScene.primitives.remove(self.axisLines)
            except ValueError:
                pass

            self.axisLines = None
Exemplo n.º 3
0
    def SetFreeLook(self, freeLook=True):
        if self.freeLook == freeLook:
            return
        self.freeLook = freeLook
        camera = sm.GetService('sceneManager').GetRegisteredCamera(
            None, defaultOnActiveCamera=True)
        if camera is None:
            return
        if freeLook:
            cameraParent = self.GetCameraParent()
            cameraParent.translationCurve = None
            self.axisLines = trinity.Tr2LineSet()
            self.axisLines.effect = trinity.Tr2Effect()
            self.axisLines.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/LinesWithZ.fx'
            self.clientToolsScene = self.GetClientToolsScene()
            self.clientToolsScene.primitives.append(self.axisLines)
            self._ChangeCamPos(cameraParent.translation)
            self.BuildGridAndAxes()
            uthread.new(self._UpdateFreelookCamera)
        else:
            self.ResetCamera()
            try:
                self.clientToolsScene.primitives.remove(self.axisLines)
            except ValueError:
                pass

            self.axisLines = None
Exemplo n.º 4
0
def CreateLineSet(name = None):
    lineset = trinity.EveLineSet()
    if name is not None:
        lineset.name = name
    lineset.effect = trinity.Tr2Effect()
    lineset.effect.effectFilePath = LINESET_FXPATH
    return lineset
Exemplo n.º 5
0
 def InitAxisLines(self):
     self.axisLines = trinity.Tr2LineSet()
     self.axisLines.effect = trinity.Tr2Effect()
     self.axisLines.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/LinesWithZ.fx'
     self._clientToolsScene = self._GetClientToolsScene()
     self._clientToolsScene.primitives.append(self.axisLines)
     self._BuildGridAndAxes()
Exemplo n.º 6
0
 def MakeEffect(self, effectName):
     effect = trinity.Tr2Effect()
     effect.effectFilePath = '{0}/{1}.fx'.format(EFFECT_LOCATION,
                                                 effectName)
     if effect.effectResource.isLoading:
         self.resourcesToLoad.append(effect.effectResource)
     return effect
    def SetShader_t(self, avatar, targetsToIgnore, shaderres, allTargets = False):
        try:
            effect = trinity.Tr2Effect()
            effect.effectFilePath = shaderres
            while effect.effectResource.isLoading:
                PD.Yield()

            for mesh in avatar.visualModel.meshes:
                areasList = [mesh.opaqueAreas, mesh.decalAreas, mesh.transparentAreas]
                if allTargets or mesh.name not in targetsToIgnore:
                    for areas in areasList:
                        for area in areas:
                            transformUV = None
                            for p in area.effect.parameters:
                                if p.name == 'TransformUV0':
                                    transformUV = p.value
                                    break

                            area.effect.effectFilePath = shaderres
                            area.effect.PopulateParameters()
                            area.effect.RebuildCachedData()
                            for p in area.effect.parameters:
                                if p.name == 'TransformUV0':
                                    p.value = transformUV
                                    break

        except TaskletExit:
            raise
Exemplo n.º 8
0
 def __init__(self, text, parent, size=72, shadow=0, hspace=8, font=None):
     self.transform = trinity.EveTransform()
     self.transform.mesh = trinity.Tr2Mesh()
     self.transform.mesh.geometryResPath = 'res:/Model/Global/zsprite.gr2'
     self.transform.modifier = 1
     self.measurer = trinity.Tr2FontMeasurer()
     self.measurer.limit = 0
     if font is None:
         font = _GetDefaultFont()
     self.measurer.font = font
     self.measurer.fontSize = size
     self.measurer.letterSpace = hspace
     area = trinity.Tr2MeshArea()
     self.transform.mesh.transparentAreas.append(area)
     area.effect = self.effect = trinity.Tr2Effect()
     sampler = list(self.effect.samplerOverrides.GetDefaultValue())
     sampler[0] = 'DiffuseMapSampler'
     sampler[1] = trinity.TRITADDRESS_CLAMP
     sampler[2] = trinity.TRITADDRESS_CLAMP
     self.effect.samplerOverrides.append(tuple(sampler))
     self.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/TextureColor.fx'
     diffuseColor = trinity.Tr2Vector4Parameter()
     diffuseColor.name = 'DiffuseColor'
     self.effect.parameters.append(diffuseColor)
     self.diffuseColor = diffuseColor
     self.diffuseMap = trinity.TriTextureParameter()
     self.diffuseMap.name = 'DiffuseMap'
     self.effect.resources.append(self.diffuseMap)
     parent.children.append(self.transform)
     trinity.device.RegisterResource(self)
     self.SetText(text)
Exemplo n.º 9
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
Exemplo n.º 10
0
 def CreatePlanet(self, planetPosition):
     scaling = 0.01 / mapViewConst.SOLARSYSTEM_SCALE
     planetTransform = trinity.EveTransform()
     planetTransform.name = 'planetTransform'
     planetTransform.scaling = (scaling, scaling, scaling)
     planetTransform.translation = planetPosition
     self.systemMapTransform.children.append(planetTransform)
     planetTransform.useDistanceBasedScale = True
     planetTransform.distanceBasedScaleArg1 = 1.0
     planetTransform.distanceBasedScaleArg2 = 0.0
     planetTransform.mesh = trinity.Tr2Mesh()
     planetTransform.mesh.geometryResPath = 'res:/Model/Global/zsprite.gr2'
     planetTransform.modifier = 1
     area = trinity.Tr2MeshArea()
     planetTransform.mesh.additiveAreas.append(area)
     effect = trinity.Tr2Effect()
     effect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/TextureColor.fx'
     area.effect = effect
     diffuseColor = trinity.Tr2Vector4Parameter()
     diffuseColor.name = 'DiffuseColor'
     effect.parameters.append(diffuseColor)
     diffuseMap = trinity.TriTextureParameter()
     diffuseMap.name = 'DiffuseMap'
     diffuseMap.resourcePath = 'res:/UI/Texture/Classes/MapView/spotSprite.dds'
     effect.resources.append(diffuseMap)
Exemplo n.º 11
0
def CreateParticles():
    particleTransform = trinity.EveTransform()
    particleTransform.name = 'particleTransform'
    tex = trinity.TriTextureParameter()
    tex.name = 'TexMap'
    tex.resourcePath = PARTICLE_SPRITE_TEXTURE
    heattex = trinity.TriTextureParameter()
    heattex.name = 'HeatTexture'
    heattex.resourcePath = PARTICLE_SPRITE_HEAT_TEXTURE
    distanceFadeControl = trinity.Tr2Vector4Parameter()
    distanceFadeControl.name = DISTANCE_RANGE
    distanceFadeControl.value = (0, 1, 0, 0)
    particles = trinity.Tr2RuntimeInstanceData()
    particles.SetElementLayout([(trinity.PARTICLE_ELEMENT_TYPE.POSITION, 0, 3),
     (trinity.PARTICLE_ELEMENT_TYPE.POSITION, 1, 3),
     (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 0, 1),
     (trinity.PARTICLE_ELEMENT_TYPE.CUSTOM, 1, 4)])
    mesh = trinity.Tr2InstancedMesh()
    mesh.geometryResPath = 'res:/Graphics/Generic/UnitPlane/UnitPlane.gr2'
    mesh.instanceGeometryResource = particles
    particleTransform.mesh = mesh
    area = trinity.Tr2MeshArea()
    area.effect = trinity.Tr2Effect()
    area.effect.effectFilePath = PARTICLE_EFFECT
    area.effect.resources.append(tex)
    area.effect.resources.append(heattex)
    area.effect.parameters.append(distanceFadeControl)
    mesh.additiveAreas.append(area)
    return (particleTransform, particles, distanceFadeControl)
def CopyAreaForPrePassShadows(area, sourceAreaType=SOURCE_AREA_TYPE_OPAQUE):
    originalEffect = area.effect
    if originalEffect is None or not hasattr(originalEffect, 'effectFilePath'):
        return
    newArea = trinity.Tr2MeshArea()
    newArea.name = area.name
    newArea.index = area.index
    newArea.count = area.count
    newEffect = trinity.Tr2Effect()
    if originalEffect.effectFilePath.lower().find('avatar') == -1:
        if sourceAreaType == SOURCE_AREA_TYPE_DECAL and originalEffect.effectFilePath.lower(
        ).find('alphatest') == -1:
            return
    elif originalEffect.effectFilePath.lower().find('cloth') == -1:
        if sourceAreaType == SOURCE_AREA_TYPE_DECAL:
            newEffect.effectFilePath = SHADOW_ALPHATEST_EFFECT_PATH
        else:
            newEffect.effectFilePath = SHADOW_OPAQUE_EFFECT_PATH
    elif sourceAreaType == SOURCE_AREA_TYPE_DECAL:
        newEffect.effectFilePath = SHADOW_CLOTH_ALPHATEST_EFFECT_PATH
    else:
        newEffect.effectFilePath = SHADOW_CLOTH_OPAQUE_EFFECT_PATH
    newEffect.name = originalEffect.name
    CopyResources(originalEffect, newEffect, {'DiffuseMap', 'CutMaskMap'})
    CopyParameters(
        originalEffect, newEffect, {
            'TransformUV0', 'MaterialDiffuseColor', 'CutMaskInfluence',
            'ArrayOfCutMaskInfluence'
        })
    newArea.effect = newEffect
    return newArea
Exemplo n.º 13
0
    def MakeEffect(self):
        """
        Creates an instance of AuraEffect and configures its resources.
        MakeEffect is always called in the context of a tasklet.
        """
        self.effect = trinity.Tr2Effect()
        self.effect.effectFilePath = AURA_EFFECT_RES_PATH
        while self.effect.effectResource.isLoading:
            PD.Yield()

        self.effect.PopulateParameters()
        blurMask = blue.resMan.GetResource(
            'res:/Graphics/Decals/caustics4.dds')
        auraTexture = blue.resMan.GetResource(
            'res:/Graphics/Decals/caustics4.dds')
        setCount = 0
        for resource in self.effect.resources:
            if resource.name == 'BlurMask':
                resource.SetResource(blurMask)
                setCount += 1
            elif resource.name == 'AuraTexture':
                resource.SetResource(auraTexture)
                setCount += 1
            if setCount == 2:
                break

        self.effect.RebuildCachedData()
Exemplo n.º 14
0
    def __CreateBakeEffect(self):
        """
        Create and setup a planet's effect file for heightmap baking
        """
        self.effectHeight = trinity.Tr2Effect()
        if self.effectHeight is None:
            self.LogError('Could not create effect for planet with id',
                          self.itemID)
            return
        mainMesh = self.model.highDetail.children[0].meshLod
        if mainMesh is None:
            mainMesh = self.model.highDetail.children[0].mesh
            errorMsg = 'No LODs found on planet.\n'
            modelPath = 'modelPath=' + self.modelPath + '\n'
            presetPath = 'presetPath=' + self.presetPath + '\n'
            shaderPreset = 'shaderPreset=' + str(
                self.attributes.shaderPreset) + '\n'
            self.LogError(errorMsg, modelPath, presetPath, shaderPreset)
        if len(mainMesh.transparentAreas) > 0:
            resPath = mainMesh.transparentAreas[0].effect.effectFilePath
        elif len(mainMesh.opaqueAreas) > 0:
            resPath = mainMesh.opaqueAreas[0].effect.effectFilePath
        else:
            self.LogError('Unexpected program flow! Loading fallback shader.')
            resPath = 'res:/Graphics/Effect/Managed/Space/Planet/EarthlikePlanet.fx'
        resPath = resPath.replace('.fx', 'BlitHeight.fx')
        self.effectHeight.effectFilePath = resPath
        if self.__GetHeightMap1() is not None and self.__GetHeightMap2(
        ) is not None:
            param1 = trinity.TriTexture2DParameter()
            param1.name = 'NormalHeight1'
            self.heightMapResPath1 = util.GraphicFile(self.__GetHeightMap1())
            self.effectHeight.resources.append(param1)
            param2 = trinity.TriTexture2DParameter()
            param2.name = 'NormalHeight2'
            self.heightMapResPath2 = util.GraphicFile(self.__GetHeightMap2())
            self.effectHeight.resources.append(param2)
            param3 = trinity.Tr2FloatParameter()
            param3.name = 'Random'
            param3.value = float(self.itemID % 100)
            self.effectHeight.parameters.append(param3)
            param4 = trinity.Tr2FloatParameter()
            param4.name = 'TargetTextureHeight'
            param4.value = 2048
            self.effectHeight.parameters.append(param4)
        paramList = self.__GetPlanetShaderParameters(
            '', 'trinity.Tr2Vector4Parameter')
        for param in paramList:
            self.effectHeight.parameters.append(param)

        paramList = self.__GetPlanetShaderParameters(
            '', 'trinity.Tr2FloatParameter')
        for param in paramList:
            self.effectHeight.parameters.append(param)

        resList = self.__GetPlanetShaderParameters(
            '', 'trinity.TriTexture2DParameter')
        for res in resList:
            self.effectHeight.resources.append(res)
Exemplo n.º 15
0
    def PreloadEffect(path):
        effect = trinity.Tr2Effect()
        effect.effectFilePath = path
        while effect.effectResource.isLoading:
            pdCf.Yield()

        effect.RebuildCachedData()
        return effect
Exemplo n.º 16
0
def GetEffectsToCache():
    effects = []
    for each in COMPOSITE_SHADER_PATHS:
        effect = trinity.Tr2Effect()
        effect.effectFilePath = EFFECT_LOCATION + '/' + each
        effects.append(effect)

    return effects
Exemplo n.º 17
0
 def SetSkyboxTexture(self, texturePath):
     self.backgroundEffect = trinity.Tr2Effect()
     texture = trinity.TriTextureCubeParameter()
     texture.name = 'EnvMap1'
     texture.resourcePath = texturePath
     self.backgroundEffect.resources.append(texture)
     self.backgroundEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Interior/Static/EnvironmentCubemap.fx'
     self.backgroundCubemapPath = str(texturePath)
Exemplo n.º 18
0
def makeBitmapStep(filePath, scaleToFit = True, color = (1.0, 1.0, 1.0, 1.0), targetSize = None):
    """
    Helper function to create a renderstep that shows a bitmap without stretching, by scaling it or adding black.
    http://carbon/wiki/Core_Graphics_Snippets
    """
    tex = trinity.TriTexture2DParameter()
    tex.name = 'Texture'
    tex.resourcePath = filePath
    if targetSize is None:
        bb = trinity.device.GetRenderContext().GetDefaultBackBuffer()
        targetSize = (bb.width, bb.height)
    fx = trinity.Tr2Effect()
    fx.effectFilePath = 'res:/Graphics/Effect/Managed/Space/System/ColoredBlit.fx'
    fx.resources.append(tex)
    while tex.resource.isLoading:
        blue.synchro.Yield()

    sw = float(tex.resource.width)
    sh = float(tex.resource.height)
    tw = float(targetSize[0])
    th = float(targetSize[1])
    v = trinity.Tr2Vector4Parameter()
    v.name = 'Color'
    v.value = color
    fx.parameters.append(v)
    v = trinity.Tr2Vector4Parameter()
    v.name = 'SourceUVs'
    fx.parameters.append(v)
    sourceAspect = sw / sh
    targetAspect = tw / th
    if scaleToFit:
        if targetAspect > sourceAspect:
            span = targetAspect / sourceAspect
            v.value = (0.5 - 0.5 * span,
             0.0,
             0.5 + 0.5 * span,
             1.0)
        else:
            span = sourceAspect / targetAspect
            v.value = (0,
             0.5 - 0.5 * span,
             1.0,
             0.5 + 0.5 * span)
    elif targetAspect > sourceAspect:
        d = 1.0 - sw * th / (sh * tw)
        d *= 0.5
        v.value = (0.0,
         d,
         1.0,
         1.0 - d)
    else:
        d = 1.0 - tw * sh / (th * sw)
        d *= 0.5
        v.value = (d,
         0.0,
         1.0 - d,
         1.0)
    return trinity.TriStepRenderEffect(fx)
Exemplo n.º 19
0
def CreateLineSet(name=None):
    """Creates and returns an `EveLineSet` with the standard lineset effect.
    """
    lineset = trinity.EveLineSet()
    if name is not None:
        lineset.name = name
    lineset.effect = trinity.Tr2Effect()
    lineset.effect.effectFilePath = LINESET_FXPATH
    return lineset
 def MakeEffect(self, effectName):
     """
     Creates a trinity.Tr2Effect based on the given 'effectName'
     """
     effect = trinity.Tr2Effect()
     effect.effectFilePath = '{0}/{1}.fx'.format(EFFECT_LOCATION,
                                                 effectName)
     if effect.effectResource.isLoading:
         self.resourcesToLoad.append(effect.effectResource)
     return effect
Exemplo n.º 21
0
 def SetupStencilBlitEffect(self):
     self.stencilBlitEffect = trinity.Tr2Effect()
     self.stencilBlitEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/system/BlitStencil.fx'
     stencilMap = trinity.TriTexture2DParameter()
     stencilMap.name = 'StencilMap'
     stencilMap.resourcePath = self.stencilPath
     self.stencilBlitEffect.resources.append(stencilMap)
     self.blitMapParameter = trinity.TriTexture2DParameter()
     self.blitMapParameter.name = 'BlitSource'
     self.stencilBlitEffect.resources.append(self.blitMapParameter)
Exemplo n.º 22
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
Exemplo n.º 23
0
    def PreloadEffect(path):
        """
        Helper for preloading effect: create it, wait on blue, rebuild it.
        """
        effect = trinity.Tr2Effect()
        effect.effectFilePath = path
        while effect.effectResource.isLoading:
            pdCf.Yield()

        effect.RebuildCachedData()
        return effect
Exemplo n.º 24
0
    def DuplicateEffect(fx, newPath, dupResources = True):
        newEffect = trinity.Tr2Effect()
        newEffect.effectFilePath = newPath
        newEffect.parameters = fx.parameters
        newEffect.name = fx.name
        if dupResources:
            for r in fx.resources:
                SkinLightmapRenderer.DuplicateResource(newEffect, fx, r.name)

        newEffect.PopulateParameters()
        newEffect.RebuildCachedData()
        return newEffect
Exemplo n.º 25
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()
Exemplo n.º 27
0
def CreatePlanarLineSet(pickEnabled = False, texturePath = None):
    lineSet = trinity.EveCurveLineSet()
    lineSet.lineEffect = trinity.Tr2Effect()
    lineSet.lineEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Lines/Lines3DPlanar.fx'
    tex2D = trinity.TriTextureParameter()
    tex2D.name = 'TexMap'
    tex2D.resourcePath = texturePath or 'res:/dx9/texture/ui/linePlanarBase.dds'
    lineSet.lineEffect.resources.append(tex2D)
    if pickEnabled:
        lineSet.pickEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Space/SpecialFX/Lines/Lines3DPlanarPicking.fx'
    else:
        lineSet.pickEffect = None
    return lineSet
Exemplo n.º 28
0
    def AddMesh(self, mesh):
        if mesh is None or self.lightmap is None:
            return

        def SetupSkinMap():
            for a in itertools.chain(mesh.opaqueAreas, mesh.decalAreas):
                if a.effect is not None and a.effect.resources is not None:
                    for e in a.effect.resources:
                        if e.name == 'SkinMap':
                            self.skinMapPath = e.resourcePath
                            self.paramSkinMap.resourcePath = self.skinMapPath
                            return

        if self.skinMapPath is None:
            SetupSkinMap()
        m = self.Mesh()
        if not m.ExtractOrigEffect(mesh):
            return
        for areaRef, fx in m.origEffect.iteritems():
            if areaRef.object is None:
                continue
            if pdCcf.IsBeard(areaRef.object):
                pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, None)
                pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, fx)
                pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, None)
                continue
            wasDouble = 'double' in fx.effectFilePath.lower()
            singleApply = self.LIGHTMAP_APPLICATION_EFFECT
            doubleApply = self.LIGHTMAP_APPLICATION_DOUBLE_EFFECT
            lightmapRenderEffect = SkinLightmapRenderer.DuplicateEffect(fx, self.LIGHTMAP_RENDERER_DOUBLE_EFFECT if wasDouble else self.LIGHTMAP_RENDERER_EFFECT)
            lightmapApplyEffect = SkinLightmapRenderer.DuplicateEffect(fx, doubleApply if wasDouble else singleApply)
            pdCcf.AddWeakBlue(m, 'lightmapRenderEffect', areaRef.object, lightmapRenderEffect)
            pdCcf.AddWeakBlue(m, 'lightmapApplyEffect', areaRef.object, lightmapApplyEffect)
            stretchmapRenderEffect = trinity.Tr2Effect()
            stretchmapRenderEffect.effectFilePath = self.STRETCHMAP_RENDERER_EFFECT
            stretchmapRenderEffect.parameters = fx.parameters
            pdCcf.AddWeakBlue(m, 'stretchmapRenderEffect', areaRef.object, stretchmapRenderEffect)
            m.liveParameters.append(filter(lambda r: r[0].name.startswith('WrinkleNormalStrength') or r[0].name.startswith('spotLight'), zip(fx.parameters, lightmapRenderEffect.parameters, lightmapApplyEffect.parameters)))
            self.CreateExtraMaps(lightmapApplyEffect)
            stretchmapRenderEffect.PopulateParameters()
            stretchmapRenderEffect.RebuildCachedData()
            if False:
                self.DebugPrint('lightmapRenderEffect resources:')
                for p in lightmapRenderEffect.resources:
                    self.DebugPrint(p.name)

                self.DebugPrint('lightmapApplyEffect resources:')
                for p in lightmapApplyEffect.resources:
                    self.DebugPrint(p.name)

        pdCcf.AddWeakBlue(self, 'meshes', mesh, m)
Exemplo n.º 29
0
def makeCubemapStep(filePath, scaleToFit = True, color = (1.0, 1.0, 1.0, 1.0), cubeFace = 0, targetSize = None):
    """
    Helper function to create a renderstep that shows a cubemap.
    http://carbon/wiki/Core_Graphics_Snippets
    """
    tex = trinity.TriTextureCubeParameter()
    tex.name = 'BlitSource'
    tex.resourcePath = filePath
    if targetSize is None:
        bb = trinity.device.GetRenderContext().GetDefaultBackBuffer()
        targetSize = (bb.width, bb.height)
    targetAspect = float(targetSize[0]) / float(targetSize[1])
    fx = trinity.Tr2Effect()
    fx.effectFilePath = 'res:/Graphics/Effect/Managed/Space/System/ColoredBlitCube.fx'
    fx.effectResource.Reload()
    fx.resources.append(tex)
    v = trinity.Tr2Vector4Parameter()
    v.name = 'Color'
    v.value = color
    fx.parameters.append(v)
    v = trinity.Tr2FloatParameter()
    v.name = 'cubeFace'
    v.value = cubeFace
    fx.parameters.append(v)
    v = trinity.Tr2Vector4Parameter()
    v.name = 'ScaleXY'
    fx.parameters.append(v)
    if scaleToFit:
        if targetAspect >= 1.0:
            v.value = (targetAspect,
             1.0,
             1.0,
             1.0)
        else:
            v.value = (1.0,
             1.0 / targetAspect,
             1.0,
             1.0)
    elif targetAspect < 1.0:
        v.value = (targetAspect,
         1.0,
         1.0,
         1.0)
    else:
        v.value = (1.0,
         1.0 / targetAspect,
         1.0,
         1.0)
    return trinity.TriStepRenderEffect(fx)
Exemplo n.º 30
0
 def __init__(self,
              name,
              color=(0.0, 0.0, 0.0, 1.0),
              scaleByDistance=True,
              viewOriented=False,
              primitiveScene=None):
     basearea.__init__(self, name, color, primitiveScene)
     self._lineset = trinity.Tr2LineSet()
     self._lineset.scaleByDistanceToView = scaleByDistance
     self._lineset.viewOriented = viewOriented
     self._lineset.name = name
     self._lineset.effect = trinity.Tr2Effect()
     self._lineset.pickEffect = trinity.Tr2Effect()
     self._lineset.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/LinesNoZ.fx'
     self._lineset.pickEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/PrimitivePicking.fx'
     self._solidset = trinity.Tr2SolidSet()
     self._solidset.scaleByDistanceToView = scaleByDistance
     self._solidset.name = name
     self._solidset.effect = trinity.Tr2Effect()
     self._solidset.pickEffect = trinity.Tr2Effect()
     self._solidset.effect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/SolidsNoZ.fx'
     self._solidset.pickEffect.effectFilePath = 'res:/Graphics/Effect/Managed/Utility/PrimitivePicking.fx'
     self.primitives.append(self._solidset)
     self.primitives.append(self._lineset)