@@ -81,11 +81,9 @@ public static void LoadBundle()
8181 using ( WWW www = new WWW ( "file://" + KSPUtil . ApplicationRootPath + "GameData/KerbalVisualEnhancements/Shaders/" + bundlePath ) )
8282 {
8383 Log ( "Bundle '" + bundlePath + "' loaded." ) ;
84-
85- Log ( "Bundle '" + bundlePath + "' loaded." ) ;
84+ BundleLoaded = true ;
8685
8786 AssetBundle bundle = www . assetBundle ;
88-
8987 Shader [ ] shaders = bundle . LoadAllAssets < Shader > ( ) ;
9088
9189 foreach ( Shader shader in shaders )
@@ -96,8 +94,6 @@ public static void LoadBundle()
9694
9795 bundle . Unload ( false ) ;
9896 www . Dispose ( ) ;
99-
100- BundleLoaded = true ;
10197 }
10298 }
10399
@@ -168,7 +164,11 @@ public static void Init()
168164
169165 protected void Start ( )
170166 {
171-
167+ if ( HighLogic . LoadedScene == GameScenes . SPACECENTER || HighLogic . LoadedScene == GameScenes . FLIGHT )
168+ {
169+ SetTerrainShadows ( ) ;
170+ }
171+
172172 if ( HighLogic . LoadedScene == GameScenes . MAINMENU )
173173 {
174174 EnableMainOverlay ( ) ;
@@ -179,6 +179,37 @@ protected void Start()
179179 }
180180 }
181181
182+ private void SetTerrainShadows ( )
183+ {
184+ bool terrainShadows = false ;
185+
186+ ConfigNode volumeConfig = GameDatabase . Instance . GetConfigNodes ( "KERBAL_VISUAL_ENHANCEMENTS" ) [ 0 ] ;
187+ bool . TryParse ( volumeConfig . GetValue ( "terrainShadows" ) , out terrainShadows ) ;
188+
189+ if ( terrainShadows )
190+ {
191+ foreach ( CelestialBody body in FindObjectsOfType ( typeof ( CelestialBody ) ) )
192+ {
193+ if ( body . pqsController )
194+ {
195+ body . pqsController . meshCastShadows = true ;
196+ body . pqsController . meshRecieveShadows = true ;
197+
198+ QualitySettings . shadowDistance = 100000 ;
199+
200+ foreach ( Light light in FindObjectsOfType ( typeof ( Light ) ) )
201+ {
202+ if ( ( light . gameObject . name == "Scaledspace SunLight" ) || ( light . gameObject . name == "SunLight" ) )
203+ {
204+ // light.shadowNormalBias = 0.4f;
205+ // light.shadowBias = 0.125f;
206+ }
207+ }
208+ }
209+ }
210+ }
211+ }
212+
182213 private void OnDominantBodyChangeCallback ( GameEvents . FromToAction < CelestialBody , CelestialBody > data )
183214 {
184215 UpdateCurrentBody ( data . to . bodyName ) ;
@@ -394,7 +425,7 @@ public Overlay(string planet, float altitude, Material scaledMaterial, Material
394425 var mr = OverlayGameObject . AddComponent < MeshRenderer > ( ) ;
395426 mr . sharedMaterial = scaledMaterial ;
396427 mr . shadowCastingMode = UnityEngine . Rendering . ShadowCastingMode . Off ;
397- mr . receiveShadows = false ;
428+ mr . receiveShadows = true ;
398429 //mr.enabled = mainMenu;
399430 mr . enabled = true ;
400431
@@ -437,6 +468,7 @@ public static Overlay GeneratePlanetOverlay(string planet, float altitude, Mater
437468 Rotation . x += .25f ;
438469
439470 Transform celestialTransform = PSystemManager . Instance . scaledBodies . Single ( t => t . name == planet ) . transform ;
471+
440472 Overlay overlay = new Overlay ( planet , altitude , scaledMaterial , macroMaterial , Rotation , OverlayMgr . MAP_LAYER , celestialTransform , mainMenu , matchTerrain ) ;
441473 if ( ! mainMenu )
442474 {
0 commit comments