Skip to content

Commit

Permalink
Do not allocate a new Ray for every sky cache usage.
Browse files Browse the repository at this point in the history
  • Loading branch information
leMaik committed Nov 1, 2023
1 parent deecc36 commit 45b2a00
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,10 @@ public String getDescription() {
}

@Override
public Vector3 calcIncidentLight(Ray ray) {
public Vector3 calcIncidentLight(Vector3 d) {
// Render from just above the surface of "earth"
Vector3 origin = new Vector3(0, ray.o.y + EARTH_RADIUS + 1, 0);
Vector3 direction = ray.d;
Vector3 origin = new Vector3(0, EARTH_RADIUS + 1, 0);
Vector3 direction = d;
direction.y += horizonOffset;
direction.normalize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,12 @@ public String getDescription() {
}

@Override
public Vector3 calcIncidentLight(Ray ray) {
double cosTheta = ray.d.y;
public Vector3 calcIncidentLight(Vector3 d) {
double cosTheta = d.y;
cosTheta += horizonOffset;
if (cosTheta < 0)
cosTheta = 0;
double cosGamma = ray.d.dot(sw);
double cosGamma = d.dot(sw);
double gamma = FastMath.acos(cosGamma);
double cos2Gamma = cosGamma * cosGamma;
double x = zenith_x * perezF(cosTheta, gamma, cos2Gamma, A.x, B.x, C.x, D.x, E.x) * f0_x;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public interface SimulatedSky {
/**
* Calculate the sky color for a given ray.
*/
Vector3 calcIncidentLight(Ray ray);
Vector3 calcIncidentLight(Vector3 d);

/**
* Get the friendly name.
Expand Down
5 changes: 1 addition & 4 deletions chunky/src/java/se/llbit/chunky/renderer/scene/SkyCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -168,14 +168,11 @@ private Vector3 getColorInterpolated(double normX, double normY) {
* Calculate the sky color for a pixel on the cache.
*/
private Vector3 getSkyColorAt(int x, int y) {
Ray ray = new Ray();

double theta = ((double) x / skyResolution) * 2 * PI;
double phi = ((double) y / skyResolution) * PI - PI / 2;
double r = FastMath.cos(phi);
ray.d.set(FastMath.cos(theta) * r, FastMath.sin(phi), FastMath.sin(theta) * r);

Vector3 color = simSky.calcIncidentLight(ray);
Vector3 color = simSky.calcIncidentLight(new Vector3(FastMath.cos(theta) * r, FastMath.sin(phi), FastMath.sin(theta) * r));
ColorUtil.RGBtoHSL(color, color.x, color.y, color.z);
return color;
}
Expand Down

0 comments on commit 45b2a00

Please sign in to comment.