-
Notifications
You must be signed in to change notification settings - Fork 78
Use more intuitive sun controls; refactor code #1577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
70e5d04
4f0b301
6f52b26
0cdfd30
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,8 @@ public static SkyMode get(String name) { | |
| /** Current sky rendering mode. */ | ||
| private SkyMode mode = SkyMode.DEFAULT; | ||
|
|
||
| private boolean enableSkymapInterpolation = true; | ||
|
|
||
| /** Simulated skies. */ | ||
| public final static List<SimulatedSky> skies = new ArrayList<>(); | ||
|
|
||
|
|
@@ -254,12 +256,13 @@ public void set(Sky other) { | |
| if (simulatedSkyMode.updateSun(scene.sun, horizonOffset)) { | ||
| skyCache.precalculateSky(); | ||
| } | ||
| enableSkymapInterpolation = other.enableSkymapInterpolation; | ||
| } | ||
|
|
||
| /** | ||
| * Calculate sky color for the ray, based on sky mode. | ||
| */ | ||
| public void getSkyDiffuseColorInner(Ray ray) { | ||
| private void getSkyDiffuseColorInner(Ray ray) { | ||
| switch (mode) { | ||
| case SOLID_COLOR: { | ||
| ray.color.set(color.x, color.y, color.z, 1); | ||
|
|
@@ -360,26 +363,30 @@ public void getSkyDiffuseColorInner(Ray ray) { | |
| /** | ||
| * Panoramic skymap color. | ||
| */ | ||
| public void getSkyColor(Ray ray, boolean drawSun) { | ||
| getSkyDiffuseColorInner(ray); | ||
| ray.color.scale(skyExposure); | ||
| ray.color.scale(skyLightModifier); | ||
| if (drawSun) addSunColor(ray); | ||
| ray.color.w = 1; | ||
| } | ||
| public void getSkyColor(Ray ray, boolean isApparentColor, boolean isDiffuseSun) { | ||
| if (enableSkymapInterpolation) { | ||
| getSkyColorInterpolated(ray); | ||
| } else { | ||
| getSkyDiffuseColorInner(ray); | ||
| } | ||
|
|
||
| public void getApparentSkyColor(Ray ray, boolean drawSun) { | ||
| getSkyDiffuseColorInner(ray); | ||
| ray.color.scale(skyExposure); | ||
| ray.color.scale(apparentSkyLightModifier); | ||
| if (drawSun) addSunColor(ray); | ||
| if (isApparentColor) { | ||
| ray.color.scale(apparentSkyLightModifier); | ||
| addSunColor(ray, false); | ||
| } else { | ||
| ray.color.scale(skyLightModifier); | ||
| if (isDiffuseSun) { | ||
| addSunColor(ray, true); | ||
| } | ||
| } | ||
| ray.color.w = 1; | ||
| } | ||
|
|
||
| /** | ||
| * Bilinear interpolated panoramic skymap color. | ||
| */ | ||
| public void getSkyColorInterpolated(Ray ray) { | ||
| private void getSkyColorInterpolated(Ray ray) { | ||
| switch (mode) { | ||
| case SKYMAP_EQUIRECTANGULAR: { | ||
| double x = rotation.transformX(ray.d); | ||
|
|
@@ -449,49 +456,34 @@ public void getSkyColorInterpolated(Ray ray) { | |
| getSkyDiffuseColorInner(ray); | ||
| } | ||
| } | ||
| ray.color.scale(skyExposure); | ||
| ray.color.scale(apparentSkyLightModifier); | ||
| addSunColor(ray); | ||
|
Comment on lines
-452
to
-454
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method is public. Is it intended to not apply exposure, sky light modifier and sun here anymore?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is only accessed from within Sky.java, so it can be made private (the same goes with |
||
| ray.color.w = 1; | ||
| } | ||
|
|
||
| /** | ||
| * Add sun color contribution. This does not alpha blend the sun color | ||
| * because the Minecraft sun texture has no alpha channel. | ||
| */ | ||
| private void addSunColor(Ray ray) { | ||
| double r = ray.color.x; | ||
| double g = ray.color.y; | ||
| double b = ray.color.z; | ||
| if (scene.sun().intersect(ray)) { | ||
|
|
||
| // Blend sun color with current color. | ||
| ray.color.x = ray.color.x + r; | ||
| ray.color.y = ray.color.y + g; | ||
| ray.color.z = ray.color.z + b; | ||
| } | ||
| } | ||
|
|
||
| public void getSkyColorDiffuseSun(Ray ray, boolean diffuseSun) { | ||
| getSkyDiffuseColorInner(ray); | ||
| ray.color.scale(skyExposure); | ||
| ray.color.scale(skyLightModifier); | ||
| if (diffuseSun) addSunColorDiffuseSun(ray); | ||
| ray.color.w = 1; | ||
| } | ||
|
|
||
| public void addSunColorDiffuseSun(Ray ray) { | ||
| private void addSunColor(Ray ray, boolean isDiffuseSun) { | ||
| double r = ray.color.x; | ||
| double g = ray.color.y; | ||
| double b = ray.color.z; | ||
| if (isDiffuseSun) { | ||
| if (scene.sun().intersectDiffuse(ray)) { | ||
| double mult = scene.sun().getLuminosity(); | ||
|
|
||
| // Blend sun color with current color. | ||
| ray.color.x = ray.color.x * mult + r; | ||
| ray.color.y = ray.color.y * mult + g; | ||
| ray.color.z = ray.color.z * mult + b; | ||
| } | ||
| } else { | ||
| if (scene.sun().intersect(ray)) { | ||
|
|
||
| if (scene.sun().intersectDiffuse(ray)) { | ||
| double mult = scene.sun().getLuminosity(); | ||
|
|
||
| // Blend sun color with current color. | ||
| ray.color.x = ray.color.x * mult + r; | ||
| ray.color.y = ray.color.y * mult + g; | ||
| ray.color.z = ray.color.z * mult + b; | ||
| // Blend sun color with current color. | ||
| ray.color.x = ray.color.x + r; | ||
| ray.color.y = ray.color.y + g; | ||
| ray.color.z = ray.color.z + b; | ||
| } | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -673,6 +665,7 @@ public void setSkyCacheResolution(int resolution) { | |
| break; | ||
| } | ||
| } | ||
| sky.add("enableSkymapInterpolation", enableSkymapInterpolation); | ||
| return sky; | ||
| } | ||
|
|
||
|
|
@@ -749,6 +742,7 @@ public void importFromJson(JsonObject json) { | |
| default: | ||
| break; | ||
| } | ||
| enableSkymapInterpolation = json.get("enableSkymapInterpolation").boolValue(enableSkymapInterpolation); | ||
| } | ||
|
|
||
| private void updateTransform() { | ||
|
|
@@ -1178,4 +1172,13 @@ public void setColor(Vector3 color) { | |
| public Vector3 getColor() { | ||
| return color; | ||
| } | ||
|
|
||
| public void setEnableSkymapInterpolation(boolean value) { | ||
| enableSkymapInterpolation = value; | ||
| scene.refresh(); | ||
| } | ||
|
|
||
| public boolean getEnableSkymapInterpolation() { | ||
| return enableSkymapInterpolation; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.