@@ -34,11 +34,17 @@ public CamSettings(Vector2 aspect, float zoomLevel, float fieldOfView, bool isOr
34
34
35
35
public bool Equals ( CamSettings other )
36
36
{
37
- bool isEqual = other . screenSize [ 0 ] == screenSize [ 0 ] &&
38
- other . screenSize [ 1 ] == screenSize [ 1 ] &&
39
- other . aspect != aspect &&
40
- Math . Abs ( other . fieldOfView - fieldOfView ) < float . Epsilon &&
41
- Math . Abs ( other . zoomLevel - zoomLevel ) < float . Epsilon ;
37
+ bool equalScreen = other . screenSize [ 0 ] == screenSize [ 0 ] &&
38
+ other . screenSize [ 1 ] == screenSize [ 1 ] ;
39
+ bool equalAspect = other . aspect == aspect ;
40
+ bool equalFoV = Math . Abs ( other . fieldOfView - fieldOfView ) <= float . Epsilon ;
41
+ bool equalZoom = Math . Abs ( other . zoomLevel - zoomLevel ) <= float . Epsilon ;
42
+ bool isEqual = equalScreen && equalAspect && equalFoV && equalZoom ;
43
+ //if (!isEqual)
44
+ //{
45
+ // Debug.LogFormat("scr {0}, asp {1}, fov {2}, zoom {3}", equalScreen, equalAspect, equalFoV, equalZoom);
46
+ // Debug.LogFormat("Aspect: {0}, Other: {1}", aspect, other.aspect);
47
+ //}
42
48
return isEqual ;
43
49
}
44
50
}
@@ -204,11 +210,9 @@ protected Vector2 GetScreenRenderSize()
204
210
// in terms of fustrum distance, converted to pixels
205
211
if ( cam . orthographic == false )
206
212
{
207
- // Reasonable fakery to use half of far clip as distance
208
- // if advanced settings doesn't exist yet
209
- float zDistance = cam . farClipPlane * 0.5f ;
210
- if ( advancedSettings != null )
211
- zDistance = advancedSettings . perspectiveZ ;
213
+ cam . aspect = ( float ) Screen . width / Screen . height ;
214
+
215
+ float zDistance = PerspectiveZ ;
212
216
213
217
var frustumHeight = 2.0f * zDistance * Mathf . Tan ( cam . fieldOfView * 0.5f * Mathf . Deg2Rad ) ;
214
218
var frustumWidth = frustumHeight * cam . aspect ;
@@ -226,13 +230,14 @@ protected void SetupCamera()
226
230
var aspect = AspectStretch ;
227
231
228
232
zoomLevel = Mathf . Max ( 0.05f , Mathf . Abs ( zoomLevel ) ) * Math . Sign ( zoomLevel ) ;
229
- // "Physical" render size
233
+ // "Physical" pixel render size
230
234
Vector2 screenRenderSize = GetScreenRenderSize ( ) ;
231
235
// Pixel render size
232
236
int [ ] pixelRenderSize = GetRenderTextureSize ( screenRenderSize , aspect ) ;
233
237
234
- // Find the settings to be used for drawing the GL quad
235
- Vector2 pixelSize = new Vector2 ( pixelRenderSize [ 0 ] , pixelRenderSize [ 1 ] ) * zoomLevel ;
238
+ float targetAspect = ( float ) pixelRenderSize [ 0 ] / ( float ) pixelRenderSize [ 1 ] ;
239
+ cam . aspect = targetAspect ;
240
+
236
241
if ( cam . orthographic )
237
242
{
238
243
// Orthographic camera needs to use screen size when calculating quad offset
@@ -247,15 +252,13 @@ protected void SetupCamera()
247
252
cam . orthographicSize = targetHeight ;
248
253
}
249
254
255
+ // Find the settings to be used for drawing the GL quad
256
+ Vector2 pixelSize = new Vector2 ( pixelRenderSize [ 0 ] , pixelRenderSize [ 1 ] ) * zoomLevel ;
250
257
quadOffset = pixelSize - screenRenderSize ;
251
258
quadOffset /= 2 ;
252
259
quadOffset . x /= Screen . width ;
253
260
quadOffset . y /= Screen . height ;
254
261
255
- // Set camera aspect ratio, since pixel aspect ratio will be different from current aspect
256
- float targetAspect = ( float ) pixelRenderSize [ 0 ] / ( float ) pixelRenderSize [ 1 ] ;
257
- cam . aspect = targetAspect ;
258
-
259
262
// Important to release current render texture
260
263
cam . targetTexture = null ;
261
264
fallbackMaterial . SetTexture ( "_MainTex" , null ) ;
0 commit comments