private void CameraPreRender(Camera camera) { if (model != null) { model.Restore(camera); } // Write camera-dependant shader values if (innerMaterial != null && outerMaterial != null) { var cameraPosition = camera.transform.position; var localCameraPosition = transform.InverseTransformPoint(cameraPosition); var localDistance = localCameraPosition.magnitude; var clampedSky = Mathf.InverseLerp(OuterRadius, InnerMeshRadius, localDistance); var innerAtmosphereDepth = default(float); var outerAtmosphereDepth = default(float); var radiusRatio = SgtHelper.Divide(InnerMeshRadius, OuterRadius); var scaleDistance = SgtHelper.Divide(localDistance, OuterRadius); var innerDensity = 1.0f - InnerFog; var outerDensity = 1.0f - OuterFog; SgtHelper.CalculateAtmosphereThicknessAtHorizon(radiusRatio, 1.0f, scaleDistance, out innerAtmosphereDepth, out outerAtmosphereDepth); SgtHelper.SetTempMaterial(innerMaterial, outerMaterial); if (scaleDistance > 1.0f) { SgtHelper.EnableKeyword("SGT_A"); // Outside } else { SgtHelper.DisableKeyword("SGT_A"); // Outside } innerMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(innerAtmosphereDepth * innerDensity)); outerMaterial.SetFloat("_HorizonLengthRecip", SgtHelper.Reciprocal(outerAtmosphereDepth * outerDensity)); if (OuterDepthTex != null) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(OuterDepthTex); #endif outerMaterial.SetFloat("_Sky", Sky * OuterDepthTex.GetPixelBilinear(clampedSky / outerDensity, 0.0f).a); } UpdateMaterialNonSerialized(); } }
private void CameraPreRender(Camera camera) { if (model != null) { model.Restore(camera); } // Write camera-dependant shader values if (innerMaterial != null && outerMaterial != null) { var localPosition = cachedTransform.InverseTransformPoint(camera.transform.position); var localDistance = localPosition.magnitude; var height01 = Mathf.InverseLerp(OuterRadius, InnerMeshRadius, localDistance); var innerThickness = default(float); var outerThickness = default(float); var innerRatio = SgtHelper.Divide(InnerMeshRadius, OuterRadius); var middleRatio = Mathf.Lerp(innerRatio, 1.0f, Middle); var distance = SgtHelper.Divide(localDistance, OuterRadius); var innerDensity = 1.0f - InnerFog; var outerDensity = 1.0f - OuterFog; SgtHelper.CalculateHorizonThickness(innerRatio, middleRatio, distance, out innerThickness, out outerThickness); innerMaterial.SetFloat(SgtShader._HorizonLengthRecip, SgtHelper.Reciprocal(innerThickness * innerDensity)); outerMaterial.SetFloat(SgtShader._HorizonLengthRecip, SgtHelper.Reciprocal(outerThickness * outerDensity)); if (OuterDepthTex != null) { #if UNITY_EDITOR SgtHelper.MakeTextureReadable(OuterDepthTex); #endif outerMaterial.SetFloat(SgtShader._Sky, Sky * OuterDepthTex.GetPixelBilinear(height01 / outerDensity, 0.0f).a); } UpdateMaterialNonSerialized(); } }