Skip to content

Commit

Permalink
added the sun so that we have a sun
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSunCat committed Jun 21, 2020
1 parent 9102a2d commit 91414a8
Showing 1 changed file with 29 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/minecraft4k/Minecraft4k.java
Original file line number Diff line number Diff line change
Expand Up @@ -599,9 +599,10 @@ else if (d < 4)
sinPitch = (float)Math.sin(cameraPitch);
cosPitch = (float)Math.cos(cameraPitch);

lightDirection.x = 0;
lightDirection.y = (float) Math.sin(time / 1000.0d);
lightDirection.z = (float) Math.cos(time / 1000.0d);
lightDirection.y = (float) Math.sin(time / 10000.0d);

lightDirection.x = 0; //lightDirection.y * 0.5f;
lightDirection.z = (float) Math.cos(time / 10000.0d);


if(lightDirection.y < 0f)
Expand Down Expand Up @@ -1061,7 +1062,9 @@ public void run()
float temp = cosPitch + frustumRayY * sinPitch;

Vec3 rayDir = new Vec3(frustumRayX * cosYaw + temp * sinYaw, frustumRayY * cosPitch - sinPitch, temp * cosYaw - frustumRayX * sinYaw);
Vec3.normalize(rayDir, rayDir);

float sunDot = Vec3.dot(rayDir, lightDirection);

Vec3 pixelColor = classic ? new Vec3() : Vec3.fromRGB(0x86, 0xB2, 0xFE); // sky color (default)
float fogIntensity = 0.0f;
Expand Down Expand Up @@ -1296,7 +1299,10 @@ else if(!classic) { // shadows
Vec3.mult(pixelColor, lightColor, pixelColor);
}
} else {
pixelColor = new Vec3(skyColor);
if(sunDot > 0.99f)
pixelColor = new Vec3(sunColor);
else
pixelColor = new Vec3(skyColor);
}

Vec3.mult(pixelColor, 0xFF, pixelColor);
Expand Down Expand Up @@ -1391,6 +1397,25 @@ static void mult(Vec3 a, float b, Vec3 out)
out.z = a.z * b;
}

static void normalize(Vec3 vec, Vec3 out)
{
float length = length(vec);

out.x = vec.x / length;
out.y = vec.y / length;
out.z = vec.z / length;
}

static float length(Vec3 vec)
{
return (float) Math.sqrt(vec.x * vec.x + vec.y * vec.y + vec.z * vec.z);
}

static float length2(Vec3 vec)
{
return vec.x * vec.x + vec.y * vec.y + vec.z * vec.z;
}

static void lerp(Vec3 start, Vec3 end, float t, Vec3 out)
{
out.x = start.x + (end.x - start.x) * t;
Expand Down

0 comments on commit 91414a8

Please sign in to comment.