//-------------------------------------------------------------------- // CheckDraw // Checks if the given mesh should be drawn. private void CheckDraw(GameObject flareMesh, MeshRenderer flareMR, Vector3d position, CelestialBody referenceBody, Vector4 hslColor, double objRadius, FlareType flareType, CelestialBody referenceStarBody) { Vector3d targetVectorToSun = referenceStarBody.position - position; Vector3d targetVectorToRef = referenceBody.position - position; double targetRelAngle = Vector3d.Angle(targetVectorToSun, targetVectorToRef); double targetDist = Vector3d.Distance(position, camPos); double targetSize; if (flareType == FlareType.Celestial) { targetSize = objRadius; } else { targetSize = Math.Atan2(objRadius, targetDist) * Mathf.Rad2Deg; } double targetRefDist = Vector3d.Distance(position, referenceBody.position); double targetRefSize = Math.Acos(Math.Sqrt(Math.Pow(targetRefDist, 2.0) - Math.Pow(referenceBody.Radius, 2.0)) / targetRefDist) * Mathf.Rad2Deg; bool inShadow = false; if (referenceBody != referenceStarBody && targetRelAngle < targetRefSize) { inShadow = true; } bool isVisible; if (inShadow) { isVisible = false; } else { isVisible = true; // See if the sun obscures our target if (sunDistanceFromCamera < targetDist && sunSizeInDegrees > targetSize && Vector3d.Angle(cameraToSunUnitVector, position - camPos) < sunSizeInDegrees) { isVisible = false; } if (isVisible) { for (int i = 0; i < bodyFlares.Count; ++i) { if (bodyFlares[i].body.bodyName != flareMesh.name && bodyFlares[i].distanceFromCamera <targetDist && bodyFlares[i].sizeInDegrees> targetSize && Vector3d.Angle(bodyFlares[i].cameraToBodyUnitVector, position - camPos) < bodyFlares[i].sizeInDegrees) { isVisible = false; break; } } } } if (targetSize < (camFOV / 500.0f) && isVisible && !MapView.MapIsEnabled) { // Work in HSL space. That allows us to do dimming of color // by adjusting the lightness value without any hue shifting. // We apply atmospheric dimming using alpha. Although maybe // I don't need to - it could be done by dimming, too. float alpha = hslColor.w; float dimming = 1.0f; alpha *= atmosphereFactor; dimming *= dimFactor; if (targetSize > (camFOV / 1000.0f)) { dimming *= (float)(((camFOV / targetSize) / 500.0) - 1.0); } if (flareType == FlareType.Debris && DistantObjectSettings.DistantFlare.debrisBrightness < 1.0f) { dimming *= DistantObjectSettings.DistantFlare.debrisBrightness; } // Uncomment this to help with debugging //alpha = 1.0f; //dimming = 1.0f; flareMR.material.color = ResourceUtilities.HSL2RGB(hslColor.x, hslColor.y, hslColor.z * dimming, alpha); } else { flareMesh.SetActive(false); } }