@@ -82,26 +82,17 @@ public static float scale(float x, float y, float z){
82
82
83
83
/** Fade out based on distance to viewport. */
84
84
public static float alpha (float x , float y , float z ){
85
- float cx = camera .position .x , cy = camera .position .y ;
86
- float cz = cameraZ ;
87
-
88
- x -= cx ;
89
- y -= cy ;
90
- float zz = cz - z ;
91
-
92
- float vx = x / zz * viewportOffset , //Position scaled to near plane.
93
- vy = y / zz * viewportOffset ;
94
85
float vz = viewportZ ();
95
86
96
- float dst = Math3D . dst (x , y , z , vx , vy , vz ); //Distance between viewport and pos
97
- float fade = Math .min (fadeDst , cz - viewportOffset );
87
+ float dst = dstToViewport (x , y , z );
88
+ float fade = Math .min (fadeDst , vz );
98
89
99
90
if (dst > fade ){
100
91
return 1f ;
101
92
}else if (z > vz ){ //Behind viewport, should be 0
102
93
return 0f ;
103
94
}else {
104
- return Mathf .clamp (dst / fade );
95
+ return Interp . pow2In . apply ( Mathf .clamp (dst / fade ) );
105
96
}
106
97
}
107
98
@@ -131,6 +122,21 @@ public static void viewportSize(){
131
122
}
132
123
}
133
124
125
+ public static float dstToViewport (float x , float y , float z ){
126
+ float cx = camera .position .x , cy = camera .position .y ;
127
+ float cz = cameraZ ;
128
+
129
+ x -= cx ;
130
+ y -= cy ;
131
+ float zz = cz - z ;
132
+
133
+ float vx = x / zz * viewportOffset , //Position scaled to near plane.
134
+ vy = y / zz * viewportOffset ;
135
+ float vz = viewportZ ();
136
+
137
+ return Math3D .dst (x , y , z , vx , vy , vz ); //Distance between viewport and pos
138
+ }
139
+
134
140
/**
135
141
* Calculates the camera z coordinate based on FOV and the size of the vanilla camera.
136
142
* @return camera z coordinate
0 commit comments