amdFidelityFx.py (6122B)
1 #Embedded file name: C:\BuildAgent\work\20d73f1b24eed06e\eve\release\V24.01\eve\devtools\script\amdFidelityFx.py 2 from __future__ import print_function 3 import trinity 4 from carbonui.control.singlelineedits.singleLineEditFloat import SingleLineEditFloat 5 from carbonui.primitives.containerAutoSize import ContainerAutoSize 6 import carbonui.const as uiconst 7 from carbonui.control.window import Window 8 from carbonui.control.button import Button 9 from eve.client.script.ui.control.eveLabel import EveHeaderSmall 10 from carbonui.control.checkbox import Checkbox 11 12 class FidelityFXWindow(Window): 13 default_caption = 'FidelityFX' 14 default_windowID = 'FidelityFXWindow' 15 default_width = 260 16 default_height = 220 17 default_minSize = (260, 220) 18 default_maxSize = (260, 220) 19 __notifyevents__ = ['OnSessionChanged'] 20 21 def __init__(self, **kw): 22 self.cachedFidelityFx = None 23 self.fsrEnabled = False 24 self.useRcas = False 25 self.slowFSR = False 26 self.fsrSharpness = 0.0 27 self.upsamplingFactor = 1.0 28 self.enabledCheckbox = None 29 self.rcasCheckbox = None 30 self.slowCheckbox = None 31 self.sharpnessInput = None 32 self.upsamplingInput = None 33 super(FidelityFXWindow, self).__init__(**kw) 34 self.MakeUnResizeable() 35 sm.RegisterNotify(self) 36 37 def ApplyAttributes(self, attributes): 38 Window.ApplyAttributes(self, attributes) 39 self.CacheFidelityFX() 40 self.GetValuesFromEffect(self.cachedFidelityFx) 41 self.Layout() 42 43 def GetValuesFromEffect(self, fx): 44 self.fsrEnabled = getattr(fx, 'fsrEnabled', False) 45 self.useRcas = getattr(fx, 'useRcas', False) 46 self.slowFSR = getattr(fx, 'slowFSR', False) 47 self.fsrSharpness = getattr(fx, 'sharpness', 0.0) 48 self.upsamplingFactor = getattr(fx, 'upsamplingFactor', 1.0) 49 if self.enabledCheckbox: 50 self.enabledCheckbox.SetValue(self.fsrEnabled) 51 self.rcasCheckbox.SetValue(self.useRcas) 52 self.slowCheckbox.SetValue(self.slowFSR) 53 self.sharpnessInput.SetValue(self.fsrSharpness) 54 self.upsamplingInput.SetValue(self.upsamplingFactor) 55 56 def CacheFidelityFX(self): 57 scene = self.GetScene() 58 self.cachedFidelityFx = getattr(scene.postprocess, 'fidelityFX', None) 59 newfx = trinity.Tr2PPFidelityFXEffect() 60 newfx.fsrEnabled = self.fsrEnabled 61 newfx.useRcas = self.useRcas 62 newfx.slowFSR = self.slowFSR 63 newfx.sharpness = self.fsrSharpness 64 newfx.upsamplingFactor = self.upsamplingFactor 65 scene.postprocess.fidelityFX = newfx 66 67 def OnSessionChanged(self, isRemote, sess, change): 68 self.CacheFidelityFX() 69 self.ApplyToScene(True) 70 71 def GetScene(self): 72 return sm.GetService('sceneManager').GetActiveScene() 73 74 def ApplyToScene(self, resetBackbuffers = False): 75 scene = self.GetScene() 76 if not scene: 77 print('No scene...') 78 return 79 if not scene.postprocess: 80 scene.postprocess = trinity.Tr2PostProcess2() 81 fidelityFx = scene.postprocess.fidelityFX 82 fidelityFx.fsrEnabled = self.fsrEnabled 83 fidelityFx.useRcas = self.useRcas 84 fidelityFx.slowFSR = self.slowFSR 85 fidelityFx.sharpness = self.fsrSharpness 86 fidelityFx.upsamplingFactor = self.upsamplingFactor 87 fidelityFx.hdr = False 88 if resetBackbuffers: 89 rj = sm.GetService('sceneManager').fisRenderJob 90 rj.SetSettingsBasedOnPerformancePreferences() 91 92 def Layout(self): 93 self.SetMinSize([260, 370]) 94 self.main_container = ContainerAutoSize(parent=self.content, align=uiconst.TOTOP) 95 self.enabledCheckbox = Checkbox(parent=self.main_container, text=u'FSR Enabled', align=uiconst.TOTOP, checked=self.fsrEnabled, callback=self.OnToggled) 96 self.rcasCheckbox = Checkbox(parent=self.main_container, text=u'RCAS Enabled', align=uiconst.TOTOP, checked=self.useRcas, callback=self.OnRcasToggled) 97 self.slowCheckbox = Checkbox(parent=self.main_container, text=u'Slow Mode', align=uiconst.TOTOP, checked=self.slowFSR, callback=self.OnSlowToggled) 98 self.sharpnessInput = SingleLineEditFloat(name='sharpness', parent=self.main_container, align=uiconst.TOTOP, padTop=24, setvalue='%s' % self.fsrSharpness, minValue=0.0, maxValue=float(1.0), decimalPlaces=2, OnChange=self.OnSharpnessChanged, OnReturn=self.OnSharpnessReturn, label='Sharpness') 99 self.upsamplingInput = SingleLineEditFloat(name='upsampling', parent=self.main_container, align=uiconst.TOTOP, padTop=24, setvalue='%s' % self.upsamplingFactor, minValue=1.0, maxValue=float(4.0), decimalPlaces=2, OnChange=self.OnUpsamplingChanged, OnReturn=self.OnUpsamplingReturn, label='Upsampling') 100 Button(parent=self.content, label='Reset', align=uiconst.CENTERBOTTOM, func=self.OnResetClicked) 101 102 def OnToggled(self, cb): 103 self.fsrEnabled = bool(cb.GetValue()) 104 self.ApplyToScene(resetBackbuffers=True) 105 106 def OnRcasToggled(self, cb): 107 self.useRcas = bool(cb.GetValue()) 108 self.ApplyToScene() 109 110 def OnSlowToggled(self, cb): 111 self.slowFSR = cb.GetValue() 112 self.ApplyToScene() 113 114 def OnSharpnessChanged(self, input): 115 self.fsrSharpness = float(self.sharpnessInput.GetValue()) 116 self.ApplyToScene() 117 118 def OnSharpnessReturn(self, *args): 119 self.fsrSharpness = float(self.sharpnessInput.GetValue()) 120 self.ApplyToScene() 121 122 def OnUpsamplingChanged(self, input): 123 self.upsamplingFactor = float(self.upsamplingInput.GetValue()) 124 self.ApplyToScene(resetBackbuffers=True) 125 126 def OnUpsamplingReturn(self, *args): 127 self.upsamplingFactor = float(self.upsamplingInput.GetValue()) 128 self.ApplyToScene(resetBackbuffers=True) 129 130 def OnResetClicked(self, _): 131 self.GetValuesFromEffect(self.cachedFidelityFx) 132 self.ApplyToScene(resetBackbuffers=True) 133 134 def _AddHeader(self, text): 135 return EveHeaderSmall(parent=self.main_container, text=text, align=uiconst.TOTOP, padding=(0, 0, 0, 0))