@@ -13,7 +13,7 @@ public class ReflectiveShaderModule : PartModule
1313 [ KSPField ( isPersistant = false ) ]
1414 public int CubeMapSize = 128 ;
1515 [ KSPField ( isPersistant = false ) ]
16- public float FarClipPlane = 100f ;
16+ public float FarClipPlane = 1000000000f ;
1717 [ KSPField ( isPersistant = false ) ]
1818 public float NearClipPlane = - 1f ;
1919 [ KSPField ( isPersistant = false ) ]
@@ -61,6 +61,7 @@ public class ReflectiveShaderModule : PartModule
6161 public override void OnStart ( PartModule . StartState state )
6262 {
6363 Debug . Log ( ( object ) "RP: Starting ReflectionPlugin .. " ) ;
64+ GameEvents . onVesselGoOffRails . Add ( RefreshReflection ) ;
6465 if ( this . ShaderName == string . Empty )
6566 {
6667 Debug . Log ( ( object ) "RP: Defaulting shader to \" Reflective/VertexLit\" " ) ;
@@ -130,24 +131,34 @@ public override void OnStart(PartModule.StartState state)
130131
131132 private void ReplaceShader ( UnityEngine . Renderer pRenderer )
132133 {
133- if ( ( UnityEngine . Object ) pRenderer != ( UnityEngine . Object ) null )
134+ if ( ( object ) pRenderer != null )
134135 {
135136 Debug . Log ( ( object ) string . Format ( "RP: Renderer found: {0}" , ( object ) this . _rShader ) ) ;
136137 Material material ;
137138 string shaderName = this . ShaderName ;
139+ string resourceNamesString = "EMBEDDED RESOURCE NAMES\n " ;
138140
139- shaderName . Replace ( " " , "_" ) ;
140- shaderName . Replace ( "/" , "." ) ;
141+ shaderName = shaderName . Replace ( " " , "_" ) ;
142+ shaderName = shaderName . Replace ( "/" , "." ) ;
141143
142144 if ( this . _rShader == null )
143145 {
144- Debug . Log ( ( object ) ( "RP: null shader. Trying to retrieve ReflectionPlugin.Shaders." + this . ShaderName ) ) ;
146+ Debug . Log ( ( object ) ( "RP: null shader. Trying to retrieve ReflectionPlugin.Shaders." + shaderName ) ) ;
145147 Assembly assembly = Assembly . GetExecutingAssembly ( ) ;
148+
149+ string [ ] resourceNamesList = assembly . GetManifestResourceNames ( ) ;
150+ foreach ( string resourceName in resourceNamesList )
151+ {
152+ resourceNamesString += resourceName + "\n " ;
153+ }
154+
155+ Debug . Log ( resourceNamesString ) ;
156+
146157 try
147158 {
148159 Debug . Log ( "[ReflectionPlugin] Looking for resource " + shaderName ) ;
149160
150- StreamReader shaderStreamReader = new StreamReader ( assembly . GetManifestResourceStream ( /*"ReflectionPlugin.Shaders." + */ shaderName ) ) ;
161+ StreamReader shaderStreamReader = new StreamReader ( assembly . GetManifestResourceStream ( /*"ReflectionPlugin.Shaders." + */ "ReflectionPlugin.Resources." + shaderName + ".shader" ) ) ;
151162
152163 Debug . Log ( "[ReflectionPlugin] Got " + shaderName ) ;
153164
@@ -159,11 +170,20 @@ private void ReplaceShader(UnityEngine.Renderer pRenderer)
159170 catch ( Exception e )
160171 {
161172 Debug . Log ( "ReflectionPlugin caught exception " + e . ToString ( ) + " (" + e . Message + ")" ) ;
162- material = new Material ( Shader . Find ( "Reflective/VertexList" ) )
173+
174+ shaderName = "Reflective.VertexLit" ;
175+ Debug . Log ( "[ReflectionPlugin] Looking for fallback resource " + shaderName ) ;
176+
177+ StreamReader shaderStreamReader = new StreamReader ( assembly . GetManifestResourceStream ( "ReflectionPlugin.Resources." + shaderName + ".shader" ) ) ;
178+
179+ Debug . Log ( "[ReflectionPlugin] Got " + shaderName ) ;
180+
181+ material = new Material ( shaderStreamReader . ReadToEnd ( ) )
163182 {
164183 mainTexture = pRenderer . material . mainTexture
165184 } ;
166185 }
186+ Debug . Log ( "[ReflectionPlugin] Initialized Material: " + material . ToString ( ) ) ;
167187 }
168188 else
169189 {
@@ -174,13 +194,13 @@ private void ReplaceShader(UnityEngine.Renderer pRenderer)
174194 }
175195 Texture texture1 = pRenderer . material . GetTexture ( "_BumpMap" ) ;
176196 Texture texture2 = pRenderer . material . GetTexture ( "_Emissive" ) ;
177- if ( ( UnityEngine . Object ) texture1 != ( UnityEngine . Object ) null )
197+ if ( ( object ) texture1 != null )
178198 {
179199 Debug . LogWarning ( ( object ) "RP: Found bumpmap texture, applying.." ) ;
180200 material . SetTexture ( "_BumpMap" , texture1 ) ;
181201 material . SetTextureScale ( "_BumpMap" , pRenderer . material . GetTextureScale ( "_BumpMap" ) ) ;
182202 }
183- if ( ( UnityEngine . Object ) texture2 != ( UnityEngine . Object ) null )
203+ if ( ( object ) texture2 != null )
184204 {
185205 Debug . LogWarning ( ( object ) "RP: Found heightmap texture, applying.." ) ;
186206 material . SetTexture ( "_ParallaxMap" , texture2 ) ;
@@ -236,6 +256,10 @@ private void ReplaceShader(UnityEngine.Renderer pRenderer)
236256 else
237257 Debug . LogError ( ( object ) ( "RP: Unable to find a Renderer component on the part. Part: " + this . part . partName ) ) ;
238258 }
259+ public void RefreshReflection ( Vessel v )
260+ {
261+ this . reflectiveScript . dirty = 7 ;
262+ }
239263 public void FixedUpdate ( )
240264 {
241265 scriptStatus = this . reflectiveScript . status ;
0 commit comments