From 1234027329bcaad8dca9d2f16a54b7201961cb71 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 21 May 2020 23:09:18 -0400 Subject: [PATCH] Remove old intersection code --- Source/Scene/SkyAtmosphere.js | 27 +++----- Source/Shaders/SkyAtmosphereCommon.glsl | 84 +++++-------------------- Specs/Scene/SkyAtmosphereSpec.js | 6 +- 3 files changed, 27 insertions(+), 90 deletions(-) diff --git a/Source/Scene/SkyAtmosphere.js b/Source/Scene/SkyAtmosphere.js index 327dd0715ce0..71dc233b0322 100644 --- a/Source/Scene/SkyAtmosphere.js +++ b/Source/Scene/SkyAtmosphere.js @@ -1,5 +1,4 @@ import Cartesian3 from "../Core/Cartesian3.js"; -import Cartesian4 from "../Core/Cartesian4.js"; import defaultValue from "../Core/defaultValue.js"; import defined from "../Core/defined.js"; import destroyObject from "../Core/destroyObject.js"; @@ -7,7 +6,6 @@ import Ellipsoid from "../Core/Ellipsoid.js"; import EllipsoidGeometry from "../Core/EllipsoidGeometry.js"; import GeometryPipeline from "../Core/GeometryPipeline.js"; import CesiumMath from "../Core/Math.js"; -import Matrix3 from "../Core/Matrix3.js"; import Matrix4 from "../Core/Matrix4.js"; import VertexFormat from "../Core/VertexFormat.js"; import BufferUsage from "../Renderer/BufferUsage.js"; @@ -109,27 +107,22 @@ function SkyAtmosphere(ellipsoid) { this._hueSaturationBrightness = new Cartesian3(); - // outer radius, inner radius, dynamic atmosphere color flag, inverse scale - var radiiAndDynamicAtmosphereColorAndInverseScale = new Cartesian4(); + // outer radius, inner radius, dynamic atmosphere color flag + var radiiAndDynamicAtmosphereColor = new Cartesian3(); - radiiAndDynamicAtmosphereColorAndInverseScale.x = - ellipsoid.maximumRadius * 1.025; - radiiAndDynamicAtmosphereColorAndInverseScale.y = ellipsoid.maximumRadius; + radiiAndDynamicAtmosphereColor.x = ellipsoid.maximumRadius * 1.025; + radiiAndDynamicAtmosphereColor.y = ellipsoid.maximumRadius; // Toggles whether the sun position is used. 0 treats the sun as always directly overhead. - radiiAndDynamicAtmosphereColorAndInverseScale.z = 0; + radiiAndDynamicAtmosphereColor.z = 0; - // Controls the distance below the horizon at which atmosphere transitions from its brightest to a more neutral blue color - // Higher values push the transition point further below the horizon - radiiAndDynamicAtmosphereColorAndInverseScale.w = 1.003; - - this._radiiAndDynamicAtmosphereColorAndInverseScale = radiiAndDynamicAtmosphereColorAndInverseScale; + this._radiiAndDynamicAtmosphereColor = radiiAndDynamicAtmosphereColor; var that = this; this._command.uniformMap = { - u_radiiAndDynamicAtmosphereColorAndInverseScale: function () { - return that._radiiAndDynamicAtmosphereColorAndInverseScale; + u_radiiAndDynamicAtmosphereColor: function () { + return that._radiiAndDynamicAtmosphereColor; }, u_hsbShift: function () { that._hueSaturationBrightness.x = that.hueShift; @@ -163,7 +156,7 @@ SkyAtmosphere.prototype.setDynamicAtmosphereColor = function ( useSunDirection ) { var lightEnum = enableLighting ? (useSunDirection ? 2.0 : 1.0) : 0.0; - this._radiiAndDynamicAtmosphereColorAndInverseScale.z = lightEnum; + this._radiiAndDynamicAtmosphereColor.z = lightEnum; }; var scratchModelMatrix = new Matrix4(); @@ -288,7 +281,7 @@ SkyAtmosphere.prototype.update = function (frameState) { var cameraPosition = frameState.camera.positionWC; var cameraHeight = Cartesian3.magnitude(cameraPosition); - if (cameraHeight > this._radiiAndDynamicAtmosphereColorAndInverseScale.x) { + if (cameraHeight > this._radiiAndDynamicAtmosphereColor.x) { // Camera in space command.shaderProgram = this._spSkyFromSpace; } else { diff --git a/Source/Shaders/SkyAtmosphereCommon.glsl b/Source/Shaders/SkyAtmosphereCommon.glsl index cecadc2146f0..b5a591e5557c 100644 --- a/Source/Shaders/SkyAtmosphereCommon.glsl +++ b/Source/Shaders/SkyAtmosphereCommon.glsl @@ -56,7 +56,7 @@ const float g2 = g * g; uniform vec3 u_hsbShift; // Hue, saturation, brightness #endif -uniform vec4 u_radiiAndDynamicAtmosphereColorAndInverseScale; // outer radius, inner radius, dynamic atmosphere color flag, inverse scale +uniform vec3 u_radiiAndDynamicAtmosphereColor; // outer radius, inner radius, dynamic atmosphere color flag float scale(float cosAngle) { @@ -66,7 +66,7 @@ float scale(float cosAngle) vec3 getLightDirection(vec3 positionWC) { - float lightEnum = u_radiiAndDynamicAtmosphereColorAndInverseScale.z; + float lightEnum = u_radiiAndDynamicAtmosphereColor.z; vec3 lightDirection = positionWC * float(lightEnum == 0.0) + czm_lightDirectionWC * float(lightEnum == 1.0) + @@ -104,64 +104,18 @@ void calculateRayScatteringFromGround(in vec3 positionWC, in vec3 ray, in float startOffset = depth*scale(startAngle); } -czm_raySegment rayEllipsoidIntersection(czm_ray ray, vec3 ellipsoid_center, vec3 ellipsoid_inverseRadii) -{ - vec3 o = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.origin, 1.0)).xyz; - vec3 d = ellipsoid_inverseRadii * (czm_inverseModelView * vec4(ray.direction, 0.0)).xyz; - - float a = dot(d, d); - float b = dot(d, o); - float c = dot(o, o) - 1.0; - float discriminant = b * b - a * c; - if (discriminant < 0.0) - { - return czm_emptyRaySegment; - } - discriminant = sqrt(discriminant); - float t1 = (-b - discriminant) / a; - float t2 = (-b + discriminant) / a; - - if (t1 < 0.0 && t2 < 0.0) - { - return czm_emptyRaySegment; - } - - if (t1 < 0.0 && t2 >= 0.0) - { - t1 = 0.0; - } - - return czm_raySegment(t1, t2); -} - void calculateMieColorAndRayleighColor(vec3 outerPositionWC, out vec3 mieColor, out vec3 rayleighColor) { // Unpack attributes - float outerRadius = u_radiiAndDynamicAtmosphereColorAndInverseScale.x; - float innerRadius = u_radiiAndDynamicAtmosphereColorAndInverseScale.y; - float inverseScale = u_radiiAndDynamicAtmosphereColorAndInverseScale.w; - - vec3 directionWC = normalize(outerPositionWC - czm_viewerPositionWC); - vec3 directionEC = czm_viewRotation * directionWC; - czm_ray viewRay = czm_ray(vec3(0.0), directionEC); - czm_raySegment raySegment = rayEllipsoidIntersection(viewRay, vec3(czm_view[3]), czm_ellipsoidInverseRadii * inverseScale); - bool intersectsEllipsoid = false;//raySegment.start >= 0.0; - - vec3 startPositionWC = czm_viewerPositionWC; - if (intersectsEllipsoid) - { - startPositionWC = czm_viewerPositionWC + raySegment.stop * directionWC; - } + float outerRadius = u_radiiAndDynamicAtmosphereColor.x; + float innerRadius = u_radiiAndDynamicAtmosphereColor.y; - vec3 lightDirection = getLightDirection(startPositionWC); + vec3 lightDirection = getLightDirection(czm_viewerPositionWC); // Get the ray from the start position to the outer position and its length (which is the far point of the ray passing through the atmosphere) - vec3 ray = outerPositionWC - startPositionWC; - float distance = length(ray); - ray /= distance; - - float maxDistance = intersectsEllipsoid ? innerRadius * 0.1 : distance; - float far = min(distance, maxDistance); + vec3 ray = outerPositionWC - czm_viewerPositionWC; + float far = length(ray); + ray /= far; float atmosphereScale = 1.0 / (outerRadius - innerRadius); @@ -169,16 +123,9 @@ void calculateMieColorAndRayleighColor(vec3 outerPositionWC, out vec3 mieColor, float startOffset; #ifdef SKY_FROM_SPACE - if (intersectsEllipsoid) - { - calculateRayScatteringFromGround(startPositionWC, ray, atmosphereScale, innerRadius, start, startOffset); - } - else - { - calculateRayScatteringFromSpace(startPositionWC, ray, innerRadius, outerRadius, far, start, startOffset); - } + calculateRayScatteringFromSpace(czm_viewerPositionWC, ray, innerRadius, outerRadius, far, start, startOffset); #else - calculateRayScatteringFromGround(startPositionWC, ray, atmosphereScale, innerRadius, start, startOffset); + calculateRayScatteringFromGround(czm_viewerPositionWC, ray, atmosphereScale, innerRadius, start, startOffset); #endif // Initialize the scattering loop variables @@ -209,7 +156,6 @@ void calculateMieColorAndRayleighColor(vec3 outerPositionWC, out vec3 mieColor, // Cap mie and rayleigh colors to prevent NaNs when vertex interpolation happens mieColor = min(mieColor, vec3(10000000.0)); rayleighColor = min(rayleighColor, vec3(10000000.0)); - } vec4 calculateFinalColor(vec3 positionWC, vec3 toCamera, vec3 lightDirection, vec3 mieColor, vec3 rayleighColor) @@ -219,9 +165,7 @@ vec4 calculateFinalColor(vec3 positionWC, vec3 toCamera, vec3 lightDirection, ve float rayleighPhase = 0.75 * (1.0 + cosAngle * cosAngle); float miePhase = 1.5 * ((1.0 - g2) / (2.0 + g2)) * (1.0 + cosAngle * cosAngle) / pow(1.0 + g2 - 2.0 * g * cosAngle, 1.5); - vec3 rayleighFinal = rayleighPhase * rayleighColor; - vec3 mieFinal = miePhase * mieColor; - vec3 rgb = rayleighFinal + mieFinal; + vec3 rgb = rayleighPhase * rayleighColor + miePhase * mieColor; const float exposure = 2.0; vec3 rgbExposure = vec3(1.0) - exp(-exposure * rgb); @@ -241,9 +185,9 @@ vec4 calculateFinalColor(vec3 positionWC, vec3 toCamera, vec3 lightDirection, ve rgb = czm_HSBToRGB(hsb); #endif - float outerRadius = u_radiiAndDynamicAtmosphereColorAndInverseScale.x; - float innerRadius = u_radiiAndDynamicAtmosphereColorAndInverseScale.y; - float lightEnum = u_radiiAndDynamicAtmosphereColorAndInverseScale.z; + float outerRadius = u_radiiAndDynamicAtmosphereColor.x; + float innerRadius = u_radiiAndDynamicAtmosphereColor.y; + float lightEnum = u_radiiAndDynamicAtmosphereColor.z; float cameraHeight = czm_eyeHeight + innerRadius; diff --git a/Specs/Scene/SkyAtmosphereSpec.js b/Specs/Scene/SkyAtmosphereSpec.js index df930a233d78..016f32779427 100644 --- a/Specs/Scene/SkyAtmosphereSpec.js +++ b/Specs/Scene/SkyAtmosphereSpec.js @@ -57,7 +57,7 @@ describe( var command = s.update(scene.frameState); expect(command).toBeDefined(); - expect(s._radiiAndDynamicAtmosphereColorAndInverseScale.z).toBe(1); + expect(s._radiiAndDynamicAtmosphereColor.z).toBe(1); command.execute(scene.context); // Not reliable enough across browsers to test pixels s.destroy(); @@ -72,7 +72,7 @@ describe( var command = s.update(scene.frameState); expect(command).toBeDefined(); - expect(s._radiiAndDynamicAtmosphereColorAndInverseScale.z).toBe(2); + expect(s._radiiAndDynamicAtmosphereColor.z).toBe(2); command.execute(scene.context); // Not reliable enough across browsers to test pixels s.destroy(); @@ -87,7 +87,7 @@ describe( var command = s.update(scene.frameState); expect(command).toBeDefined(); - expect(s._radiiAndDynamicAtmosphereColorAndInverseScale.z).toBe(0); + expect(s._radiiAndDynamicAtmosphereColor.z).toBe(0); command.execute(scene.context); // Not reliable enough across browsers to test pixels s.destroy();