@@ -19,6 +19,7 @@ public class LightboxViewerGenerator
1919 private GameObject _animatedRoot ;
2020 private Camera _camera ;
2121 private Material _material ;
22+ private bool _needsCounterRoll ;
2223
2324 public void Begin ( GameObject animatedRoot , float customRoll , bool counterRotate , Camera cameraOptional , bool usePostProcessing )
2425 {
@@ -29,6 +30,7 @@ public void Begin(GameObject animatedRoot, float customRoll, bool counterRotate,
2930 _material = new Material ( Shader . Find ( "Hai/LightboxViewerCounterRoll" ) ) ;
3031 _material . SetFloat ( "_CounterRoll" , - customRoll / 180f ) ;
3132 }
33+ _needsCounterRoll = isCustomRollSlanted && counterRotate ;
3234
3335 Profiler . BeginSample ( "LightboxViewer.Generator.Begin.AddCameraComponent" ) ;
3436 _camera = cameraOptional != null ? Object . Instantiate ( cameraOptional ) : new GameObject ( ) . AddComponent < Camera > ( ) ;
@@ -65,7 +67,7 @@ public void Terminate()
6567 Object . DestroyImmediate ( _camera . gameObject ) ;
6668 }
6769
68- public void RenderNoAnimator ( Texture2D element , GameObject currentLightbox , RenderTexture renderTexture , Vector3 referentialVector , Quaternion referentialQuaternion , float verticalDisplacement )
70+ public void RenderNoAnimator ( Texture element , GameObject currentLightbox , RenderTexture renderTexture , Vector3 referentialVector , Quaternion referentialQuaternion , float verticalDisplacement )
6971 {
7072 var rootTransform = _animatedRoot . transform ;
7173 var camTransform = _camera . transform ;
@@ -83,16 +85,34 @@ public void RenderNoAnimator(Texture2D element, GameObject currentLightbox, Rend
8385 camTransform . rotation = currentLightbox . transform . rotation * referentialQuaternion * camTransform . rotation ;
8486 rootTransform . rotation = currentLightbox . transform . rotation * referentialQuaternion * rootTransform . rotation ;
8587
86- renderTexture . wrapMode = TextureWrapMode . Clamp ;
87-
88- RenderCamera ( renderTexture , _camera ) ;
89- if ( SystemInfo . supportsAsyncGPUReadback && ! DoNotUseAsyncReadback )
88+ if ( element is RenderTexture rt )
9089 {
91- AsyncRenderTextureTo ( renderTexture , element ) ;
90+ RenderCamera ( rt , _camera ) ;
91+ if ( _needsCounterRoll && _material != null )
92+ {
93+ var diff = RenderTexture . GetTemporary ( rt . width , rt . height , 24 ) ;
94+ Graphics . Blit ( rt , diff ) ;
95+
96+ _material . SetTexture ( "_MainTex" , diff ) ;
97+ var ratio = rt . width / ( float ) rt . height ;
98+ _material . SetFloat ( "_Ratio" , ratio ) ;
99+ Graphics . Blit ( diff , rt , _material ) ;
100+
101+ RenderTexture . ReleaseTemporary ( diff ) ;
102+ }
92103 }
93- else
104+ else if ( false )
94105 {
95- SyncRenderTextureTo ( renderTexture , element ) ;
106+ renderTexture . wrapMode = TextureWrapMode . Clamp ;
107+ RenderCamera ( renderTexture , _camera ) ;
108+ if ( SystemInfo . supportsAsyncGPUReadback && ! DoNotUseAsyncReadback )
109+ {
110+ AsyncRenderTextureTo ( renderTexture , element as Texture2D ) ;
111+ }
112+ else
113+ {
114+ SyncRenderTextureTo ( renderTexture , element as Texture2D ) ;
115+ }
96116 }
97117 }
98118 finally
0 commit comments