2020
2121import java .util .concurrent .ExecutionException ;
2222import java .util .stream .IntStream ;
23+
2324import org .apache .commons .math3 .util .FastMath ;
2425import se .llbit .chunky .main .Chunky ;
2526import se .llbit .log .Log ;
26- import se .llbit .math .ColorUtil ;
27- import se .llbit .math .QuickMath ;
28- import se .llbit .math .Ray ;
29- import se .llbit .math .Vector3 ;
27+ import se .llbit .math .*;
3028
3129/**
3230 * A sky cache. Precalculates sky colors and them uses cached values with bilinear interpolation.
@@ -128,15 +126,14 @@ public void setSimulatedSkyMode(SimulatedSky skyMode) {
128126 * @param ray Ray to calculate the incident light for
129127 * @return Incident light color (RGB)
130128 */
131- public Vector3 calcIncidentLight (Ray ray ) {
129+ public void calcIncidentLight (Ray ray ) {
132130 double theta = FastMath .atan2 (ray .d .z , ray .d .x );
133131 theta /= PI * 2 ;
134132 theta = ((theta % 1 ) + 1 ) % 1 ;
135133 double phi = (FastMath .asin (QuickMath .clamp (ray .d .y , -1 , 1 )) + PI / 2 ) / PI ;
136134
137- Vector3 color = getColorInterpolated (theta , phi );
138- ColorUtil .RGBfromHSL (color , color .x , color .y , color .z );
139- return color ;
135+ getColorInterpolated (theta , phi , ray .color );
136+ ColorUtil .RGBfromHSL (ray .color , ray .color .x , ray .color .y , ray .color .z );
140137 }
141138
142139 // Linear interpolation between 2 points in 1 dimension
@@ -147,21 +144,27 @@ private static double interp1D(double x, double x0, double x1, double y0, double
147144 /**
148145 * Calculate the bilinearly interpolated value from the cache.
149146 */
150- private Vector3 getColorInterpolated (double normX , double normY ) {
147+ private void getColorInterpolated (double normX , double normY , Vector4 out ) {
151148 double x = normX * skyResolution ;
152149 double y = normY * skyResolution ;
153150 int floorX = (int ) QuickMath .clamp (x , 0 , skyResolution - 1 );
154151 int floorY = (int ) QuickMath .clamp (y , 0 , skyResolution - 1 );
155152
156- double [] color = new double [3 ];
157153 for (int i = 0 ; i < 3 ; i ++) {
158154 double y0 = interp1D (x , floorX , floorX + 1 , skyTexture [floorX ][floorY ][i ],
159- skyTexture [floorX + 1 ][floorY ][i ]);
155+ skyTexture [floorX + 1 ][floorY ][i ]);
160156 double y1 = interp1D (x , floorX , floorX + 1 , skyTexture [floorX ][floorY + 1 ][i ],
161- skyTexture [floorX + 1 ][floorY + 1 ][i ]);
162- color [i ] = interp1D (y , floorY , floorY + 1 , y0 , y1 );
157+ skyTexture [floorX + 1 ][floorY + 1 ][i ]);
158+ double c = interp1D (y , floorY , floorY + 1 , y0 , y1 );
159+ if (i == 0 ) {
160+ out .x = c ;
161+ } else if (i == 1 ) {
162+ out .y = c ;
163+ } else if (i == 2 ) {
164+ out .z = c ;
165+ }
166+ out .w = 1 ;
163167 }
164- return new Vector3 (color [0 ], color [1 ], color [2 ]);
165168 }
166169
167170 /**
0 commit comments