@@ -37,6 +37,8 @@ public class ReflectionManager : MonoBehaviour
37
37
/// </summary>
38
38
public int skyboxLayer = 26 ;
39
39
40
+ public int sphereLayer = 27 ;
41
+
40
42
#endregion
41
43
42
44
#region DEBUG FIELDS
@@ -47,6 +49,7 @@ public class ReflectionManager : MonoBehaviour
47
49
public bool renderScaled = true ;
48
50
public bool renderAtmo = true ;
49
51
public bool renderScenery = true ;
52
+ public bool alternateRender = false ;
50
53
51
54
public bool reflectionsEnabled = true ;
52
55
@@ -75,6 +78,11 @@ public class ReflectionManager : MonoBehaviour
75
78
private ReflectionDebugGUI gui ;
76
79
private GameObject debugSphere ;
77
80
81
+ //debug/prototype stuff
82
+
83
+ private RenderTexture galaxyTex ;
84
+ private GameObject galaxySphere ;
85
+ private Material galaxyMat ;
78
86
79
87
private static ReflectionManager instance ;
80
88
@@ -104,6 +112,7 @@ public void Awake()
104
112
ConfigNode node = nodes [ 0 ] ;
105
113
MonoBehaviour . print ( "SSTUReflectionManager - Loading reflection configuration: \n " + node . ToString ( ) ) ;
106
114
reflectionsEnabled = node . GetBoolValue ( "enabled" , false ) ;
115
+ alternateRender = node . GetBoolValue ( "directXFix" , false ) ;
107
116
envMapSize = node . GetIntValue ( "resolution" , envMapSize ) ;
108
117
mapUpdateSpacing = node . GetIntValue ( "interval" , mapUpdateSpacing ) ;
109
118
eveInstalled = node . GetBoolValue ( "eveInstalled" , false ) ;
@@ -219,6 +228,27 @@ private void init()
219
228
MonoBehaviour . print ( "ERROR: SSTUReflectionManager - Could not find skybox shader." ) ;
220
229
}
221
230
}
231
+ if ( galaxySphere == null )
232
+ {
233
+ galaxySphere = GameObject . CreatePrimitive ( PrimitiveType . Sphere ) ;
234
+ GameObject . DestroyImmediate ( galaxySphere . GetComponent < Collider > ( ) ) ;
235
+ galaxySphere . layer = sphereLayer ;
236
+ galaxySphere . transform . localScale = new Vector3 ( 10 , 10 , 10 ) ;
237
+ galaxyMat = new Material ( skyboxShader ) ;
238
+ galaxyMat . renderQueue = 1 ;
239
+ MeshRenderer r = galaxySphere . GetComponent < MeshRenderer > ( ) ;
240
+ r . material = galaxyMat ;
241
+ galaxySphere . SetActive ( false ) ;
242
+ }
243
+ if ( galaxyTex == null )
244
+ {
245
+ galaxyTex = new RenderTexture ( envMapSize , envMapSize , 24 ) ;
246
+ galaxyTex . dimension = UnityEngine . Rendering . TextureDimension . Cube ;
247
+ galaxyTex . format = RenderTextureFormat . ARGB32 ;
248
+ galaxyTex . wrapMode = TextureWrapMode . Clamp ;
249
+ galaxyTex . filterMode = FilterMode . Trilinear ;
250
+ galaxyTex . autoGenerateMips = false ;
251
+ }
222
252
probeData = createProbe ( ) ;
223
253
if ( HighLogic . LoadedSceneIsEditor )
224
254
{
@@ -266,7 +296,14 @@ public void updateReflections()
266
296
if ( probeData . updateTime >= mapUpdateSpacing )
267
297
{
268
298
reflectionCamera . gameObject . SetActive ( true ) ;
269
- renderFace ( probeData . renderedCube , probeData . updateFace , vessel . transform . position , probeData . updatePass ) ;
299
+ if ( alternateRender )
300
+ {
301
+ renderFaceAlt ( probeData . renderedCube , probeData . updateFace , vessel . transform . position , probeData . updatePass ) ;
302
+ }
303
+ else
304
+ {
305
+ renderFace ( probeData . renderedCube , probeData . updateFace , vessel . transform . position , probeData . updatePass ) ;
306
+ }
270
307
reflectionCamera . gameObject . SetActive ( false ) ;
271
308
probeData . updatePass ++ ;
272
309
if ( probeData . updatePass >= 3 )
@@ -318,6 +355,47 @@ private void renderFullCube(RenderTexture envMap, Vector3 partPos)
318
355
}
319
356
}
320
357
358
+ private void renderFaceAlt ( RenderTexture envMap , int face , Vector3 partPos , int pass )
359
+ {
360
+ int faceMask = 1 << face ;
361
+ if ( renderGalaxy && pass == 0 )
362
+ {
363
+ //render galaxy to galaxy sphere texture, the galaxy
364
+ reflectionCamera . clearFlags = CameraClearFlags . Color ;
365
+ reflectionCamera . backgroundColor = new Color ( 0 , 0 , 0 , 1 ) ;
366
+ reflectionCamera . cullingMask = galaxyMask ;
367
+ reflectionCamera . nearClipPlane = 0.1f ;
368
+ reflectionCamera . farClipPlane = 20f ;
369
+ reflectionCamera . transform . position = GalaxyCubeControl . Instance . transform . position ;
370
+ reflectionCamera . RenderToCubemap ( galaxyTex , faceMask ) ;
371
+ }
372
+ if ( renderScaled && pass == 0 )
373
+ {
374
+ //render to galaxy sphere texture, the atmosphere
375
+ //clear flags handle bug in unity where re-uses the same buffer before x-fer to the target face
376
+ reflectionCamera . clearFlags = renderGalaxy ? CameraClearFlags . Depth : CameraClearFlags . Color ;
377
+ reflectionCamera . backgroundColor = new Color ( 0 , 0 , 0 , 1 ) ;
378
+ reflectionCamera . cullingMask = scaledSpaceMask | atmosphereMask ;
379
+ reflectionCamera . nearClipPlane = 1f ;
380
+ reflectionCamera . farClipPlane = 3.0e7f ;
381
+ reflectionCamera . transform . position = ScaledSpace . Instance . transform . position ;
382
+ reflectionCamera . RenderToCubemap ( galaxyTex , faceMask ) ;
383
+ }
384
+ if ( pass == 2 )
385
+ {
386
+ galaxySphere . SetActive ( true ) ;
387
+ galaxyMat . SetTexture ( "_Tex" , galaxyTex ) ;
388
+ eveCameraFix . overwriteAlpha = eveInstalled ;
389
+ reflectionCamera . cullingMask = renderScenery ? ( sceneryMask | ( 1 << sphereLayer ) ) : ( 1 << sphereLayer ) ;
390
+ reflectionCamera . nearClipPlane = 0.5f ;
391
+ reflectionCamera . farClipPlane = 750000f ;
392
+ reflectionCamera . transform . position = partPos ;
393
+ reflectionCamera . RenderToCubemap ( probeData . renderedCube , faceMask ) ;
394
+ eveCameraFix . overwriteAlpha = false ;
395
+ galaxySphere . SetActive ( false ) ;
396
+ }
397
+ }
398
+
321
399
private void renderFace ( RenderTexture envMap , int face , Vector3 partPos , int pass )
322
400
{
323
401
int faceMask = 1 << face ;
0 commit comments