@@ -21,20 +21,6 @@ public class ReflectionManager : MonoBehaviour
21
21
22
22
#region CONFIG FIELDS
23
23
24
- /// <summary>
25
- /// Should static reflection maps be used?
26
- /// If true, reflection maps will only be rendered a single time on the scene initialization.
27
- /// If false, reflection maps will be updated at runtime with a frequency/delay specified by further config settings
28
- /// </summary>
29
- public bool useStaticMaps = false ;
30
-
31
- /// <summary>
32
- /// Should a reflection probe be added per-part?
33
- /// If true, reflections are done on a per-part basis.
34
- /// If false, reflections are done on a per-vessel basis.
35
- /// </summary>
36
- public bool perPartMaps = false ;
37
-
38
24
/// <summary>
39
25
/// Number of frames inbetween reflection map updates.
40
26
/// </summary>
@@ -44,7 +30,7 @@ public class ReflectionManager : MonoBehaviour
44
30
/// Size of the rendered reflection map. Higher resolutions result in higher fidelity reflections, but at a much higher run-time cost.
45
31
/// Must be a power-of-two size; e.g. 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048.
46
32
/// </summary>
47
- public int envMapSize = 512 ;
33
+ public int envMapSize = 256 ;
48
34
49
35
/// <summary>
50
36
/// Layer to use for skybox hack
@@ -68,45 +54,27 @@ public class ReflectionManager : MonoBehaviour
68
54
69
55
#region INTERNAL FIELDS
70
56
57
+ public ReflectionProbeData probeData ;
71
58
public GameObject cameraObject ;
72
59
public Camera reflectionCamera ;
73
-
74
- public readonly List < Vessel > toProcess = new List < Vessel > ( ) ;
75
-
76
- /// <summary>
77
- /// Map of vessels and their reflection probe data
78
- /// </summary>
79
- public readonly Dictionary < Vessel , VesselReflectionData > vesselReflectionProbeDict = new Dictionary < Vessel , VesselReflectionData > ( ) ;
80
-
81
- /// <summary>
82
- /// The reflection data for inside of the (current) editor. Should be rebuilt whenever the editor is initialized, closed, or change
83
- /// </summary>
84
- public EditorReflectionData editorReflectionData ;
60
+ private static Shader skyboxShader ;
61
+ private bool renderedEditor = false ;
62
+ private int editorDelay = 0 ;
63
+ private int editorTarget = 2 ;
85
64
86
65
//Mod interop stuff
87
66
88
- public bool eveInstalled = true ; //TODO -- load this value from config
67
+ public bool eveInstalled = true ;
89
68
public CameraAlphaFix eveCameraFix ;
90
69
91
- //internal data -- event handling, app-launcher button and debug-GUI handling
92
-
93
- private bool renderedEditor = false ;
94
- private int editorDelay = 0 ;
95
- private int editorTarget = 2 ;
70
+ //internal debug fields
96
71
private bool export = false ;
97
- private bool debug = false ;
98
-
99
- internal List < ReflectionPass > renderStack = new List < ReflectionPass > ( ) ;
100
-
101
- private EventData < Vessel > . OnEvent vesselCreateEvent ;
102
- private EventData < Vessel > . OnEvent vesselDestroyedEvent ;
103
-
104
- private ReflectionDebugGUI gui ;
72
+ private bool debug = false ;
73
+
105
74
private static ApplicationLauncherButton debugAppButton ;
106
-
75
+ private ReflectionDebugGUI gui ;
107
76
private GameObject debugSphere ;
108
77
109
- private static Shader skyboxShader ;
110
78
111
79
private static ReflectionManager instance ;
112
80
@@ -127,13 +95,6 @@ public void Awake()
127
95
MonoBehaviour . print ( "ReflectionManager Awake()" ) ;
128
96
instance = this ;
129
97
130
- if ( renderStack . Count <= 0 )
131
- {
132
- renderStack . Add ( ReflectionPass . GALAXY ) ;
133
- renderStack . Add ( ReflectionPass . SCALED ) ;
134
- renderStack . Add ( ReflectionPass . LOCAL ) ;
135
- }
136
-
137
98
ConfigNode [ ] nodes = GameDatabase . Instance . GetConfigNodes ( "REFLECTION_CONFIG" ) ;
138
99
if ( nodes == null || nodes . Length < 1 )
139
100
{
@@ -150,10 +111,6 @@ public void Awake()
150
111
export = node . GetBoolValue ( "exportDebugCubes" , false ) ;
151
112
152
113
init ( ) ;
153
- vesselCreateEvent = new EventData < Vessel > . OnEvent ( vesselCreated ) ;
154
- vesselDestroyedEvent = new EventData < Vessel > . OnEvent ( vesselDestroyed ) ;
155
- GameEvents . onVesselCreate . Add ( vesselCreateEvent ) ;
156
- GameEvents . onVesselDestroy . Add ( vesselDestroyedEvent ) ;
157
114
158
115
Texture2D tex ;
159
116
if ( debugAppButton == null && debug ) //static reference; track if the button was EVER created, as KSP keeps them even if the addon is destroyed
@@ -225,14 +182,6 @@ public void OnDestroy()
225
182
{
226
183
MonoBehaviour . print ( "SSTUReflectionManager OnDestroy()" ) ;
227
184
if ( instance == this ) { instance = null ; }
228
- if ( vesselCreateEvent != null )
229
- {
230
- GameEvents . onVesselCreate . Remove ( vesselCreateEvent ) ;
231
- }
232
- if ( vesselDestroyedEvent != null )
233
- {
234
- GameEvents . onVesselDestroy . Remove ( vesselDestroyedEvent ) ;
235
- }
236
185
if ( gui != null )
237
186
{
238
187
GameObject . Destroy ( gui ) ;
@@ -269,129 +218,80 @@ private void init()
269
218
{
270
219
MonoBehaviour . print ( "ERROR: SSTUReflectionManager - Could not find skybox shader." ) ;
271
220
}
272
- }
221
+ }
222
+ probeData = createProbe ( ) ;
273
223
if ( HighLogic . LoadedSceneIsEditor )
274
224
{
275
- ReflectionProbeData data = createProbe ( ) ;
276
- data . reflectionSphere . transform . position = new Vector3 ( 0 , 10 , 0 ) ;
277
- editorReflectionData = new EditorReflectionData ( data ) ;
278
- MonoBehaviour . print ( "SSTUReflectionManager created editor reflection data: " + data + " :: " + editorReflectionData ) ;
225
+ probeData . reflectionSphere . transform . position = new Vector3 ( 0 , 10 , 0 ) ;
279
226
}
280
227
else if ( HighLogic . LoadedSceneIsFlight )
281
228
{
282
- //vessels are added thorugh an event as they are loaded
229
+ //probe position updated during Update()
283
230
}
284
-
285
- //TODO -- replace with custom baked skybox...
286
- //use in areas where other reflection probes don't make sense (space?)
287
- //RenderSettings.customReflection = customCubemap;
288
-
289
- //TODO -- pre-bake cubemap to use as the custom skybox in the reflection probe camera; this can be higher res and updated far less often (every couple of seconds?)
290
231
}
291
232
292
- public void vesselCreated ( Vessel vessel )
293
- {
294
- toProcess . AddUnique ( vessel ) ;
233
+ public void forceReflectionUpdate ( )
234
+ {
235
+
295
236
}
296
237
297
- public void vesselDestroyed ( Vessel v )
238
+ public void updateReflections ( )
298
239
{
299
- MonoBehaviour . print ( "SSTUReflectionManager vesselDestroyed() : " + v ) ;
300
- toProcess . Remove ( v ) ;
301
- vesselReflectionProbeDict . Remove ( v ) ;
302
- }
303
-
304
- public void updateReflections ( bool force = false )
305
- {
306
- if ( toProcess . Count > 0 )
240
+ if ( HighLogic . LoadedSceneIsEditor )
307
241
{
308
- int len = toProcess . Count ;
309
- Vessel vessel ;
310
- for ( int i = 0 ; i < len ; i ++ )
311
- {
312
- vessel = toProcess [ i ] ;
313
- if ( vessel == null ) { continue ; }
314
- ReflectionProbeData data = createProbe ( ) ;
315
- data . reflectionSphere . transform . position = vessel . transform . position ;
316
- VesselReflectionData d = new VesselReflectionData ( vessel , data ) ;
317
- vesselReflectionProbeDict . Add ( vessel , d ) ;
318
- MonoBehaviour . print ( "SSTUReflectionManager vesselCreated() : " + vessel + " :: " + d ) ;
319
- }
320
- toProcess . Clear ( ) ;
321
- }
322
- reflectionCamera . enabled = true ;
323
- reflectionCamera . clearFlags = CameraClearFlags . Depth ;
324
- if ( editorReflectionData != null )
325
- {
326
- if ( ! renderedEditor || force )
242
+ if ( ! renderedEditor )
327
243
{
328
244
if ( editorDelay >= editorTarget )
329
245
{
330
246
renderedEditor = true ;
331
247
}
332
248
editorDelay ++ ;
333
- if ( force || renderedEditor )
334
- {
335
- MonoBehaviour . print ( "updating editor reflection" ) ;
336
- renderFullCube ( editorReflectionData . probeData . renderedCube , new Vector3 ( 0 , 10 , 0 ) ) ;
337
- updateProbe ( editorReflectionData . probeData ) ;
338
- }
339
- if ( force && export )
340
- {
341
- exportCubemap ( editorReflectionData . probeData . renderedCube , "editorReflect" ) ;
249
+ if ( renderedEditor )
250
+ {
251
+ reflectionCamera . gameObject . SetActive ( true ) ;
252
+ renderFullCube ( probeData . renderedCube , new Vector3 ( 0 , 10 , 0 ) ) ;
253
+ updateProbe ( probeData ) ;
254
+ reflectionCamera . gameObject . SetActive ( false ) ;
342
255
}
343
- }
256
+ }
344
257
}
345
- else
346
- {
347
- foreach ( VesselReflectionData d in vesselReflectionProbeDict . Values )
348
- {
349
- if ( d . vessel . loaded )
350
- {
351
- if ( ! d . probeData . reflectionSphere . activeSelf )
352
- {
353
- d . probeData . reflectionSphere . SetActive ( true ) ;
354
- }
355
- d . probeData . reflectionSphere . transform . position = d . vessel . transform . position ;
356
- if ( force )
357
- {
358
- renderFullCube ( d . probeData . renderedCube , d . vessel . transform . position ) ;
359
- updateProbe ( d . probeData ) ;
360
- if ( export )
361
- {
362
- exportCubemap ( d . probeData . renderedCube , "vesselReflect-" + d . vessel . name ) ;
363
- }
364
- continue ;
365
- }
366
- d . probeData . updateTime ++ ;
367
- if ( d . probeData . updateTime >= mapUpdateSpacing )
258
+ else if ( HighLogic . LoadedSceneIsFlight )
259
+ {
260
+ Vessel vessel = FlightIntegrator . ActiveVesselFI . Vessel ;
261
+ if ( vessel != null && vessel . loaded )
262
+ {
263
+ //probeData.reflectionSphere.SetActive(true);
264
+ probeData . reflectionSphere . transform . position = vessel . transform . position ;
265
+ probeData . updateTime ++ ;
266
+ if ( probeData . updateTime >= mapUpdateSpacing )
267
+ {
268
+ reflectionCamera . gameObject . SetActive ( true ) ;
269
+ renderFace ( probeData . renderedCube , probeData . updateFace , vessel . transform . position , probeData . updatePass ) ;
270
+ reflectionCamera . gameObject . SetActive ( false ) ;
271
+ probeData . updatePass ++ ;
272
+ if ( probeData . updatePass >= 3 )
368
273
{
369
- renderFace ( d . probeData . renderedCube , d . probeData . updateFace , d . vessel . transform . position , d . probeData . updatePass ) ;
370
- d . probeData . updatePass ++ ;
371
- if ( d . probeData . updatePass >= 3 )
372
- {
373
- d . probeData . updateFace ++ ;
374
- d . probeData . updatePass = 0 ;
375
- }
376
- if ( d . probeData . updateFace >= 6 )
377
- {
378
- updateProbe ( d . probeData ) ;
379
- d . probeData . updatePass = 0 ;
380
- d . probeData . updateTime = 0 ;
381
- d . probeData . updateFace = 0 ;
382
- }
383
- }
384
- }
385
- else
386
- {
387
- if ( d . probeData . reflectionSphere . activeSelf )
388
- {
389
- d . probeData . reflectionSphere . SetActive ( false ) ;
390
- }
391
- }
392
- }
274
+ probeData . updateFace ++ ;
275
+ probeData . updatePass = 0 ;
276
+ }
277
+ if ( probeData . updateFace >= 6 )
278
+ {
279
+ updateProbe ( probeData ) ;
280
+ probeData . updatePass = 0 ;
281
+ probeData . updateTime = 0 ;
282
+ probeData . updateFace = 0 ;
283
+ }
284
+ }
285
+ }
286
+ else
287
+ {
288
+ //TODO -- disable reflection probe if no vessel is active/loaded?
289
+ }
290
+ }
291
+ else //space center, main menu, others
292
+ {
293
+ //TODO -- handle reflective setups for space center, main menu, map view?
393
294
}
394
- reflectionCamera . enabled = false ;
395
295
}
396
296
397
297
#endregion
@@ -408,7 +308,7 @@ private void updateProbe(ReflectionProbeData data)
408
308
409
309
private void renderFullCube ( RenderTexture envMap , Vector3 partPos )
410
310
{
411
- int passCount = renderStack . Count ;
311
+ int passCount = 3 ;
412
312
for ( int face = 0 ; face < 6 ; face ++ )
413
313
{
414
314
for ( int pass = 0 ; pass < passCount ; pass ++ )
@@ -418,12 +318,10 @@ private void renderFullCube(RenderTexture envMap, Vector3 partPos)
418
318
}
419
319
}
420
320
421
- private void renderFace ( RenderTexture envMap , int face , Vector3 partPos , int ipass )
321
+ private void renderFace ( RenderTexture envMap , int face , Vector3 partPos , int pass )
422
322
{
423
- int faceMask = 1 << face ;
424
- int len = renderStack . Count ;
425
- ReflectionPass pass = renderStack [ ipass ] ;
426
- if ( pass == ReflectionPass . GALAXY )
323
+ int faceMask = 1 << face ;
324
+ if ( pass == 0 )
427
325
{
428
326
reflectionCamera . clearFlags = CameraClearFlags . Skybox ;
429
327
}
@@ -433,21 +331,21 @@ private void renderFace(RenderTexture envMap, int face, Vector3 partPos, int ipa
433
331
}
434
332
switch ( pass )
435
333
{
436
- case ReflectionPass . GALAXY :
334
+ case 0 :
437
335
if ( renderGalaxy )
438
336
{
439
337
//galaxy
440
338
renderCubeFace ( envMap , faceMask , GalaxyCubeControl . Instance . transform . position , galaxyMask , 0.1f , 20f ) ;
441
339
}
442
340
break ;
443
- case ReflectionPass . SCALED :
341
+ case 1 :
444
342
if ( renderScaled )
445
343
{
446
344
//scaled space
447
345
renderCubeFace ( envMap , faceMask , ScaledSpace . Instance . transform . position , scaledSpaceMask | atmosphereMask , 1 , 3.0e7f ) ;
448
346
}
449
347
break ;
450
- case ReflectionPass . LOCAL :
348
+ case 2 :
451
349
if ( renderScenery )
452
350
{
453
351
//scene
@@ -522,6 +420,7 @@ private RenderTexture createTexture(int size)
522
420
tex . wrapMode = TextureWrapMode . Clamp ;
523
421
tex . filterMode = FilterMode . Trilinear ;
524
422
tex . generateMips = false ;
423
+ //TODO -- loop through texture and set to default = black
525
424
return tex ;
526
425
}
527
426
0 commit comments