-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSEGI_NKLI.cs
1728 lines (1407 loc) · 82.3 KB
/
SEGI_NKLI.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System.Runtime.Serialization.Formatters.Binary;
using UnityEngine.Rendering.PostProcessing;
using System.Runtime.Serialization;
using System.Collections.Generic;
using UnityEngine.Rendering;
using System.Collections;
using Unity.Collections;
using UnityEngine;
using Unity.Jobs;
using System.IO;
using System;
#if VRWORKS
using NVIDIA;
#endif
namespace UnityEngine.Rendering.PostProcessing
{
[Serializable]
public sealed class SEGISun : ParameterOverride<Light> { }
[Serializable]
public sealed class VoxelResolution : ParameterOverride<VoxelResolutionEnum> { }
[Serializable]
public enum VoxelResolutionEnum
{
Low = 64,
Medium = 128,
High = 256//,
//VeryHigh = 512,
//Extreme = 756
}
[Serializable]
public sealed class SEGILayerMask : ParameterOverride<LayerMask> { }
[Serializable]
public sealed class SEGITransform : ParameterOverride<Transform> { }
[Serializable]
[PostProcess(typeof(SEGIRenderer), PostProcessEvent.AfterStack, "NKLI/SEGI")]
public sealed class SEGI_NKLI : PostProcessEffectSettings
{
public VoxelResolution voxelResolution = new VoxelResolution { value = VoxelResolutionEnum.High };
public FloatParameter voxelSpaceSize = new FloatParameter { value = 25.0f };
public BoolParameter updateVoxelsAfterX = new BoolParameter { value = false };
public IntParameter updateVoxelsAfterXInterval = new IntParameter { value = 1 };
public BoolParameter voxelAA = new BoolParameter { value = false };
[Range(0, 2)]
public IntParameter innerOcclusionLayers = new IntParameter { value = 1 };
public BoolParameter infiniteBounces = new BoolParameter { value = true };
public BoolParameter useReflectionProbes = new BoolParameter { value = true };
[Range(0, 2)]
public FloatParameter reflectionProbeIntensity = new FloatParameter { value = 0.5f };
//[Range(0, 2)]
//public FloatParameter reflectionProbeAttribution = new FloatParameter { value = 1f };
public BoolParameter doReflections = new BoolParameter { value = true };
[Range(0.01f, 1.0f)]
public FloatParameter temporalBlendWeight = new FloatParameter { value = 1.0f };
public BoolParameter useBilateralFiltering = new BoolParameter { value = true };// Actually used?
[Range(1, 16)]
public IntParameter GIResolution = new IntParameter { value = 1 };
public BoolParameter stochasticSampling = new BoolParameter { value = true };
public BoolParameter updateGI = new BoolParameter { value = true };
[Range(1, 128)]
public IntParameter cones = new IntParameter { value = 4 };
[Range(1, 32)]
public IntParameter coneTraceSteps = new IntParameter { value = 10 };
[Range(0.1f, 2.0f)]
public FloatParameter coneLength = new FloatParameter { value = 1.0f };
[Range(0.5f, 12.0f)]
public FloatParameter coneWidth = new FloatParameter { value = 3.9f };
[Range(0.0f, 4.0f)]
public FloatParameter coneTraceBias = new FloatParameter { value = 2.8f };
[Range(0.0f, 4.0f)]
public FloatParameter occlusionStrength = new FloatParameter { value = 0.15f };
[Range(0.0f, 4.0f)]
public FloatParameter nearOcclusionStrength = new FloatParameter { value = 0.5f };
[Range(0.001f, 4.0f)]
public FloatParameter occlusionPower = new FloatParameter { value = 0.65f };
[Range(0.0f, 4.0f)]
public FloatParameter nearLightGain = new FloatParameter { value = 0.36f };
[Range(0.0f, 4.0f)]
public FloatParameter giGain = new FloatParameter { value = 1.0f };
[Range(0.0f, 2.0f)]
public FloatParameter secondaryBounceGain = new FloatParameter { value = 0.9f };
[Range(6, 128)]
public IntParameter reflectionSteps = new IntParameter { value = 12 };
[Range(0.001f, 4.0f)]
public FloatParameter reflectionOcclusionPower = new FloatParameter { value = 1.0f };
[Range(0.0f, 1.0f)]
public FloatParameter skyReflectionIntensity = new FloatParameter { value = 1.0f };
public BoolParameter gaussianMipFilter = new BoolParameter { value = false };
[Range(0.1f, 4.0f)]
public FloatParameter farOcclusionStrength = new FloatParameter { value = 1.0f };
[Range(0.1f, 4.0f)]
public FloatParameter farthestOcclusionStrength = new FloatParameter { value = 1.0f };
[Range(3, 16)]
public IntParameter secondaryCones = new IntParameter { value = 6 };
[Range(0.1f, 4.0f)]
public FloatParameter secondaryOcclusionStrength = new FloatParameter { value = 0.27f };
public BoolParameter useFXAA = new BoolParameter { value = false };
public BoolParameter visualizeGI = new BoolParameter { value = false };
public BoolParameter visualizeVoxels = new BoolParameter { value = false };
public BoolParameter visualizeSunDepthTexture = new BoolParameter { value = false };
//public SEGISun Sun = new SEGISun { value = null };
public static Light Sun;
public SEGILayerMask giCullingMask = new SEGILayerMask { value = 2147483647 };
public SEGILayerMask reflectionProbeLayerMask = new SEGILayerMask { value = 2147483647 };
//public SEGITransform followTransform = new SEGITransform { value = null };
public static Transform followTransform;
[Range(0.0f, 16.0f)]
public FloatParameter softSunlight = new FloatParameter { value = 0.0f };
public ColorParameter skyColor = new ColorParameter { value = Color.black };
public BoolParameter MatchAmbiantColor = new BoolParameter { value = false };
[Range(0.0f, 8.0f)]
public FloatParameter skyIntensity = new FloatParameter { value = 1.0f };
public BoolParameter sphericalSkylight = new BoolParameter { value = false };
//VR
public BoolParameter NVIDIAVRWorksEnable = new BoolParameter { value = false };
}
[ExecuteInEditMode]
[ImageEffectAllowedInSceneView]
public sealed class SEGIRenderer : PostProcessEffectRenderer<SEGI_NKLI>
{
public bool initChecker = false;
public Material material;
public Camera attachedCamera;
public Transform shadowCamTransform;
public Camera shadowCam;
public GameObject shadowCamGameObject;
public Texture2D[] blueNoise;
//public ReflectionProbe reflectionProbe;
public Camera reflectionCamera;
public GameObject reflectionProbeGameObject;
public float shadowSpaceSize = 50.0f;
struct Pass
{
public static int DiffuseTrace = 0;
public static int BilateralBlur = 1;
public static int BlendWithScene = 2;
public static int TemporalBlend = 3;
public static int SpecularTrace = 4;
public static int GetCameraDepthTexture = 5;
public static int GetWorldNormals = 6;
public static int VisualizeGI = 7;
public static int WriteBlack = 8;
public static int VisualizeVoxels = 10;
public static int BilateralUpsample = 11;
}
public static RenderTexture RT_FXAART;
public static RenderTexture RT_gi1;
public static RenderTexture RT_gi2;
public static RenderTexture RT_reflections;
public static RenderTexture RT_gi3;
public static RenderTexture RT_gi4;
public static RenderTexture RT_blur0;
public static RenderTexture RT_blur1;
public static RenderTexture RT_FXAARTluminance;
public static RenderTexture RT_Albedo;
public static RenderTexture RT_AlbedoX2;
public static int SEGIRenderWidth;
public static int SEGIRenderHeight;
public struct SystemSupported
{
public bool hdrTextures;
public bool rIntTextures;
public bool dx11;
public bool volumeTextures;
public bool postShader;
public bool sunDepthShader;
public bool voxelizationShader;
public bool tracingShader;
public bool fullFunctionality
{
get
{
return hdrTextures && rIntTextures && dx11 && volumeTextures && postShader && sunDepthShader && voxelizationShader && tracingShader;
}
}
}
/// <summary>
/// Contains info on system compatibility of required hardware functionality
/// </summary>
public SystemSupported systemSupported;
public FilterMode filterMode = FilterMode.Point;
public RenderTextureFormat renderTextureFormat = RenderTextureFormat.ARGBHalf;
//public bool gaussianMipFilter = false;
int mipFilterKernel
{
get
{
return settings.gaussianMipFilter.value ? 1 : 0;
}
}
//public bool voxelAA = false;
int DummyVoxelResolution
{
get
{
return (int)settings.voxelResolution.value * (settings.voxelAA.value ? 2 : 1);
}
}
int sunShadowResolution = 256;
int prevSunShadowResolution;
public Shader sunDepthShader;
float shadowSpaceDepthRatio = 10.0f;
int frameSwitch = 0;
///<summary>This is a volume texture that is immediately written to in the voxelization shader. The RInt format enables atomic writes to avoid issues where multiple fragments are trying to write to the same voxel in the volume.</summary>
RenderTexture integerVolume;
///<summary>An array of volume textures where each element is a mip/LOD level. Each volume is half the resolution of the previous volume. Separate textures for each mip level are required for manual mip-mapping of the main GI volume texture.</summary>
//RenderTexture[] volumeTextures;
///<summary>The secondary volume texture that holds irradiance calculated during the in-volume GI tracing that occurs when Infinite Bounces is enabled. </summary>
//RenderTexture secondaryIrradianceVolume;
///<summary>The alternate mip level 0 main volume texture needed to avoid simultaneous read/write errors while performing temporal stabilization on the main voxel volume.</summary>
//RenderTexture volumeTextureB;
///<summary>The current active volume texture that holds GI information to be read during GI tracing.</summary>
//RenderTexture activeVolume;
///<summary>The volume texture that holds GI information to be read during GI tracing that was used in the previous frame.</summary>
//RenderTexture previousActiveVolume;
///<summary>A 2D texture with the size of [voxel resolution, voxel resolution] that must be used as the active render texture when rendering the scene for voxelization. This texture scales depending on whether Voxel AA is enabled to ensure correct voxelization.</summary>
RenderTexture dummyVoxelTextureAAScaled;
///<summary>A 2D texture with the size of [voxel resolution, voxel resolution] that must be used as the active render texture when rendering the scene for voxelization. This texture is always the same size whether Voxel AA is enabled or not.</summary>
RenderTexture dummyVoxelTextureFixed;
///<summary>The main GI data clipmaps that hold GI data referenced during GI tracing</summary>
Clipmap[] clipmaps;
///<summary>The secondary clipmaps that hold irradiance data for infinite bounces</summary>
Clipmap[] irradianceClipmaps;
public static RenderTexture tracedTexture0;
public static RenderTexture tracedTexture1;
public static RenderTexture tracedTextureA0;
public int tracedTexture1UpdateCount;
public static RenderTexture sunDepthTexture;
public static RenderTexture previousGIResult;
public static RenderTexture previousDepth;
public bool notReadyToRender = false;
public Shader voxelizationShader;
public Shader voxelTracingShader;
public ComputeShader clearCompute;
public ComputeShader clearComputeCache;
public ComputeShader transferIntsCompute;
public ComputeShader transferIntsTraceCacheCompute;
public ComputeShader mipFilterCompute;
const int numClipmaps = 6;
int clipmapCounter = 0;
int currentClipmapIndex = 0;
const int numMipLevels = 6;
public Camera voxelCamera;
public GameObject voxelCameraGO;
public GameObject leftViewPoint;
public GameObject topViewPoint;
float voxelScaleFactor
{
get
{
return (float)settings.voxelResolution.value / 256.0f;
}
}
public Vector3 voxelSpaceOrigin;
public Vector3 previousVoxelSpaceOrigin;
public Vector3 voxelSpaceOriginDelta;
public Quaternion rotationFront = new Quaternion(0.0f, 0.0f, 0.0f, 1.0f);
public Quaternion rotationLeft = new Quaternion(0.0f, 0.7f, 0.0f, 0.7f);
public Quaternion rotationTop = new Quaternion(0.7f, 0.0f, 0.0f, 0.7f);
public int voxelFlipFlop = 0;
public enum RenderState
{
Voxelize,
Bounce
}
public RenderState renderState = RenderState.Voxelize;
//CommandBuffer refactor
public CommandBuffer SEGIBuffer;
//Gaussian Filter
private Shader Gaussian_Shader;
private Material Gaussian_Material;
//FXAA
//public bool useFXAA;
private Shader FXAA_Shader;
private Material FXAA_Material;
private Shader CubeMap_Shader;
//Color Correction
//private Shader ColorCorrection_Shader;
//private Material ColorCorrection_Material;
//Forward Rendering
//public bool useReflectionProbes = true;
//[Range(0, 2)]
//public float reflectionProbeIntensity = 0.5f;
//[Range(0, 2)]
//public float reflectionProbeAttribution = 1f;
//Delayed voxelization
public bool updateVoxelsAfterXDoUpdate = false;
private double updateVoxelsAfterXPrevX = 9223372036854775807;
private double updateVoxelsAfterXPrevY = 9223372036854775807;
private double updateVoxelsAfterXPrevZ = 9223372036854775807;
public int GIResolutionPrev = 0;
//public LightShadows ShadowStateCache;
public bool VRWorksActuallyEnabled;
//[ImageEffectOpaque]
public override void Render(PostProcessRenderContext context)
{
// Update
InitCheck();
if (SEGIRenderWidth != context.width || SEGIRenderHeight != context.height || settings.GIResolution.value != GIResolutionPrev)
{
Debug.Log("<SEGI> Context != Cached Dimensions. Resizing buffers");
GIResolutionPrev = settings.GIResolution.value;
SEGIRenderWidth = context.width;
SEGIRenderHeight = context.height;
ResizeAllTextures();
}
if (SEGI_NKLI.Sun == null)
{
Debug.Log("<SEGI> Scipt 'SEGI_SunLight.cs' Must be attached to your main directional light!");
return;
}
if (notReadyToRender)
return;
if (!attachedCamera)
{
return;
}
if (previousGIResult == null)
{
Debug.Log("<SEGI> PreviousGIResult == null. Resizing Render Textures.");
ResizeAllTextures();
}
if (previousGIResult.width != context.width || previousGIResult.height != context.height)
{
Debug.Log("<SEGI> previousGIResult != Expected Dimensions. Resizing Render Textures");
ResizeAllTextures();
}
if ((int)sunShadowResolution != prevSunShadowResolution)
{
ResizeSunShadowBuffer();
}
prevSunShadowResolution = (int)sunShadowResolution;
if (clipmaps[0].resolution != (int)settings.voxelResolution.value)
{
clipmaps[0].resolution = (int)settings.voxelResolution.value;
clipmaps[0].UpdateTextures();
}
if (dummyVoxelTextureAAScaled.width != DummyVoxelResolution)
{
ResizeDummyTexture();
}
if (attachedCamera != context.camera) attachedCamera = context.camera;
if (!shadowCam)
{
Debug.Log("<SEGI> Shadow Camera not found!");
return;
}
//VRWorks
#if VRWORKS
if (settings.NVIDIAVRWorksEnable)
{
if (!VRWorksActuallyEnabled)
{
VRWorks VRWorksComponent = context.camera.GetComponent<VRWorks>();
if (!VRWorksComponent)
{
VRWorksComponent = context.camera.gameObject.AddComponent<VRWorks>();
context.camera.gameObject.AddComponent<VRWorksPresent>();
}
if (VRWorksComponent.IsFeatureAvailable(VRWorks.Feature.SinglePassStereo))
{
VRWorksComponent.SetActiveFeature(VRWorks.Feature.SinglePassStereo);
}
material.EnableKeyword("VRWORKS");
VRWorksActuallyEnabled = true;
}
NVIDIA.VRWorks.SetKeywords(material);
}
else
{
if (VRWorksActuallyEnabled)
{
VRWorks VRWorksComponent = context.camera.GetComponent<VRWorks>();
if (VRWorksComponent)
{
VRWorksComponent.SetActiveFeature(VRWorks.Feature.None);
}
material.DisableKeyword("VRWORKS");
VRWorksActuallyEnabled = false;
}
}
#endif
//END VRWorks
// OnPreRender
//Force reinitialization to make sure that everything is working properly if one of the cameras was unexpectedly destroyed
//if (!voxelCamera || !false;
if (context.camera.renderingPath == RenderingPath.Forward)
{
//reflectionProbe.refreshMode = ReflectionProbeRefreshMode.EveryFrame;
//reflectionProbe.intensity = settings.reflectionProbeIntensity.value;
reflectionCamera.cullingMask = settings.reflectionProbeLayerMask.GetValue<LayerMask>();
reflectionCamera.farClipPlane = context.camera.farClipPlane;
//Cache Shadow State
LightShadows ShadowStateCache = SEGI_NKLI.Sun.shadows;
Color ambientColorCache = RenderSettings.ambientLight;
AmbientMode ambientModeCache = RenderSettings.ambientMode;
float IntensityCache = SEGI_NKLI.Sun.intensity;
float ambientCache = RenderSettings.ambientIntensity;
//SEGI_NKLI.Sun.shadows = LightShadows.None;
RenderSettings.ambientMode = AmbientMode.Flat;
RenderSettings.ambientLight = Color.white;//SEGI_NKLI.Sun == null ? Color.black : new Color(Mathf.Pow(SEGI_NKLI.Sun.color.r, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.color.g, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.color.b, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.intensity, 2.2f));
RenderSettings.ambientIntensity = 1;
SEGI_NKLI.Sun.intensity = 1;
var faceToRender = Time.frameCount % 6;
var faceMask = 1 << faceToRender;
//reflectionProbe.RenderProbe();
//reflectionProbe.enabled = false;
reflectionCamera.SetReplacementShader(CubeMap_Shader, "");
reflectionCamera.RenderToCubemap(RT_Albedo, faceMask, Camera.MonoOrStereoscopicEye.Mono);
//reflectionProbe.enabled = true;
//Restore Shadow State
SEGI_NKLI.Sun.shadows = ShadowStateCache;
RenderSettings.ambientLight = ambientColorCache;
RenderSettings.ambientMode = ambientModeCache;
RenderSettings.ambientIntensity = ambientCache;
SEGI_NKLI.Sun.intensity = IntensityCache;
}
/*else
{
reflectionProbe.refreshMode = ReflectionProbeRefreshMode.ViaScripting;
}*/
// only use main camera for voxel simulations
/*if (attachedCamera != Camera.main)
{
Debug.Log("<SEGI> Instance not attached to Main Camera. Please ensure the attached camera has the 'MainCamera' tag.");
return;
}*/
//Update SkyColor
if (settings.MatchAmbiantColor)
{
settings.skyColor.value = RenderSettings.ambientLight;
settings.skyIntensity.value = RenderSettings.ambientIntensity;
}
//Cache the previous active render texture to avoid issues with other Unity rendering going on
RenderTexture previousActive = RenderTexture.active;
Shader.SetGlobalInt("SEGIVoxelAA", settings.voxelAA.value ? 1 : 0);
//Temporarily disable rendering of shadows on the directional light during voxelization pass. Cache the result to set it back to what it was after voxelization is done
LightShadows prevSunShadowSetting = LightShadows.None;
if (SEGI_NKLI.Sun != null)
{
prevSunShadowSetting = SEGI_NKLI.Sun.shadows;
SEGI_NKLI.Sun.shadows = LightShadows.None;
}
if (!settings.updateVoxelsAfterX.value) updateVoxelsAfterXDoUpdate = true;
if (attachedCamera.transform.position.x - updateVoxelsAfterXPrevX >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (updateVoxelsAfterXPrevX - attachedCamera.transform.position.x >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (attachedCamera.transform.position.y - updateVoxelsAfterXPrevY >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (updateVoxelsAfterXPrevY - attachedCamera.transform.position.y >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (attachedCamera.transform.position.z - updateVoxelsAfterXPrevZ >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (updateVoxelsAfterXPrevZ - attachedCamera.transform.position.z >= settings.updateVoxelsAfterXInterval.value) updateVoxelsAfterXDoUpdate = true;
if (settings.updateGI.value)
{
//Main voxelization work
if (renderState == RenderState.Voxelize)
{
currentClipmapIndex = SelectCascadeBinary(clipmapCounter); //Determine which clipmap to update during this frame
Clipmap activeClipmap = clipmaps[currentClipmapIndex]; //Set the active clipmap based on which one is determined to render this frame
//If we're not updating the base level 0 clipmap, get the previous clipmap
Clipmap prevClipmap = null;
if (currentClipmapIndex != 0)
{
prevClipmap = clipmaps[currentClipmapIndex - 1];
}
float clipmapShadowSize = shadowSpaceSize * activeClipmap.localScale;
float clipmapSize = settings.voxelSpaceSize * activeClipmap.localScale; //Determine the current clipmap's size in world units based on its scale
//float voxelTexel = (1.0f * clipmapSize) / activeClipmap.resolution * 0.5f; //Calculate the size of a voxel texel in world-space units
//Setup the voxel volume origin position
float interval = (clipmapSize) / 8.0f; //The interval at which the voxel volume will be "locked" in world-space
Vector3 origin;
if (SEGI_NKLI.followTransform)
{
origin = SEGI_NKLI.followTransform.position;
}
else
{
//GI is still flickering a bit when the scene view and the game view are opened at the same time
origin = context.camera.transform.position + context.camera.transform.forward * clipmapSize / 4.0f;
}
//Lock the voxel volume origin based on the interval
activeClipmap.previousOrigin = activeClipmap.origin;
activeClipmap.origin = new Vector3(Mathf.Round(origin.x / interval) * interval, Mathf.Round(origin.y / interval) * interval, Mathf.Round(origin.z / interval) * interval);
//Clipmap delta movement for scrolling secondary bounce irradiance volume when this clipmap has changed origin
activeClipmap.originDelta = activeClipmap.origin - activeClipmap.previousOrigin;
Shader.SetGlobalVector("SEGIVoxelSpaceOriginDelta", activeClipmap.originDelta / (settings.voxelSpaceSize * activeClipmap.localScale));
//Calculate the relative origin and overlap/size of the previous cascade as compared to the active cascade. This is used to avoid voxelizing areas that have already been voxelized by previous (smaller) cascades
Vector3 prevClipmapRelativeOrigin = Vector3.zero;
float prevClipmapOccupance = 0.0f;
if (currentClipmapIndex != 0)
{
prevClipmapRelativeOrigin = (prevClipmap.origin - activeClipmap.origin) / clipmapSize;
prevClipmapOccupance = prevClipmap.localScale / activeClipmap.localScale;
}
Shader.SetGlobalVector("SEGIClipmapOverlap", new Vector4(prevClipmapRelativeOrigin.x, prevClipmapRelativeOrigin.y, prevClipmapRelativeOrigin.z, prevClipmapOccupance));
//Calculate the relative origin and scale of this cascade as compared to the first (level 0) cascade. This is used during GI tracing/data lookup to ensure tracing is done in the correct space
for (int i = 1; i < numClipmaps; i++)
{
Vector3 clipPosFromMaster = Vector3.zero;
float clipScaleFromMaster = 1.0f;
clipPosFromMaster = (clipmaps[i].origin - clipmaps[0].origin) / (settings.voxelSpaceSize.value * clipmaps[i].localScale);
clipScaleFromMaster = clipmaps[0].localScale / clipmaps[i].localScale;
Shader.SetGlobalVector("SEGIClipTransform" + i.ToString(), new Vector4(clipPosFromMaster.x, clipPosFromMaster.y, clipPosFromMaster.z, clipScaleFromMaster));
}
//Set the voxel camera (proxy camera used to render the scene for voxelization) parameters
voxelCamera.enabled = false;
voxelCamera.orthographic = true;
voxelCamera.orthographicSize = clipmapSize * 0.5f;
voxelCamera.nearClipPlane = 0.0f;
voxelCamera.farClipPlane = clipmapSize;
voxelCamera.depth = -2;
voxelCamera.renderingPath = RenderingPath.Forward;
voxelCamera.clearFlags = CameraClearFlags.Color;
voxelCamera.backgroundColor = Color.black;
voxelCamera.cullingMask = settings.giCullingMask.GetValue<LayerMask>();
//Move the voxel camera game object and other related objects to the above calculated voxel space origin
voxelCameraGO.transform.position = activeClipmap.origin - Vector3.forward * clipmapSize * 0.5f;
voxelCameraGO.transform.rotation = rotationFront;
leftViewPoint.transform.position = activeClipmap.origin + Vector3.left * clipmapSize * 0.5f;
leftViewPoint.transform.rotation = rotationLeft;
topViewPoint.transform.position = activeClipmap.origin + Vector3.up * clipmapSize * 0.5f;
topViewPoint.transform.rotation = rotationTop;
//Set matrices needed for voxelization
//Shader.SetGlobalMatrix("WorldToGI", shadowCam.worldToCameraMatrix);
//Shader.SetGlobalMatrix("GIToWorld", shadowCam.cameraToWorldMatrix);
//Shader.SetGlobalMatrix("GIProjection", shadowCam.projectionMatrix);
//Shader.SetGlobalMatrix("GIProjectionInverse", shadowCam.projectionMatrix.inverse);
Shader.SetGlobalMatrix("WorldToCamera", attachedCamera.worldToCameraMatrix);
Shader.SetGlobalFloat("GIDepthRatio", shadowSpaceDepthRatio);
Matrix4x4 frontViewMatrix = TransformViewMatrix(voxelCamera.transform.worldToLocalMatrix);
Matrix4x4 leftViewMatrix = TransformViewMatrix(leftViewPoint.transform.worldToLocalMatrix);
Matrix4x4 topViewMatrix = TransformViewMatrix(topViewPoint.transform.worldToLocalMatrix);
Shader.SetGlobalMatrix("SEGIVoxelViewFront", frontViewMatrix);
Shader.SetGlobalMatrix("SEGIVoxelViewLeft", leftViewMatrix);
Shader.SetGlobalMatrix("SEGIVoxelViewTop", topViewMatrix);
Shader.SetGlobalMatrix("SEGIWorldToVoxel", voxelCamera.worldToCameraMatrix);
Shader.SetGlobalMatrix("SEGIVoxelProjection", voxelCamera.projectionMatrix);
Shader.SetGlobalMatrix("SEGIVoxelProjectionInverse", voxelCamera.projectionMatrix.inverse);
Shader.SetGlobalMatrix("SEGIVoxelVPFront", GL.GetGPUProjectionMatrix(voxelCamera.projectionMatrix, true) * frontViewMatrix);
Shader.SetGlobalMatrix("SEGIVoxelVPLeft", GL.GetGPUProjectionMatrix(voxelCamera.projectionMatrix, true) * leftViewMatrix);
Shader.SetGlobalMatrix("SEGIVoxelVPTop", GL.GetGPUProjectionMatrix(voxelCamera.projectionMatrix, true) * topViewMatrix);
Shader.SetGlobalMatrix("SEGIWorldToVoxel" + currentClipmapIndex.ToString(), voxelCamera.worldToCameraMatrix);
Shader.SetGlobalMatrix("SEGIVoxelProjection" + currentClipmapIndex.ToString(), voxelCamera.projectionMatrix);
Matrix4x4 voxelToGIProjection = shadowCam.projectionMatrix * shadowCam.worldToCameraMatrix * voxelCamera.cameraToWorldMatrix;
Shader.SetGlobalMatrix("SEGIVoxelToGIProjection", voxelToGIProjection);
Shader.SetGlobalVector("SEGISunlightVector", SEGI_NKLI.Sun ? Vector3.Normalize(SEGI_NKLI.Sun.transform.forward) : Vector3.up);
//Set paramteters
Shader.SetGlobalInt("SEGIVoxelResolution", (int)settings.voxelResolution.value);
Shader.SetGlobalColor("GISunColor", SEGI_NKLI.Sun == null ? Color.black : new Color(Mathf.Pow(SEGI_NKLI.Sun.color.r, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.color.g, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.color.b, 2.2f), Mathf.Pow(SEGI_NKLI.Sun.intensity, 2.2f)));
Shader.SetGlobalColor("SEGISkyColor", new Color(Mathf.Pow(settings.skyColor.value.r * settings.skyIntensity * 0.5f, 2.2f), Mathf.Pow(settings.skyColor.value.g * settings.skyIntensity * 0.5f, 2.2f), Mathf.Pow(settings.skyColor.value.b * settings.skyIntensity * 0.5f, 2.2f), Mathf.Pow(settings.skyColor.value.a, 2.2f)));
Shader.SetGlobalFloat("GIGain", settings.giGain);
Shader.SetGlobalFloat("SEGISecondaryBounceGain", settings.infiniteBounces ? settings.secondaryBounceGain : 0.0f);
Shader.SetGlobalFloat("SEGISoftSunlight", settings.softSunlight);
Shader.SetGlobalInt("SEGISphericalSkylight", settings.sphericalSkylight ? 1 : 0);
Shader.SetGlobalInt("SEGIInnerOcclusionLayers", settings.innerOcclusionLayers);
//Render the depth texture from the sun's perspective in order to inject sunlight with shadows during voxelization
if (SEGI_NKLI.Sun != null)
{
shadowCam.cullingMask = settings.giCullingMask.GetValue<LayerMask>();
Vector3 shadowCamPosition = activeClipmap.origin + Vector3.Normalize(-SEGI_NKLI.Sun.transform.forward) * clipmapShadowSize * 0.5f * shadowSpaceDepthRatio;
shadowCamTransform.position = shadowCamPosition;
shadowCamTransform.LookAt(activeClipmap.origin, Vector3.up);
shadowCam.renderingPath = RenderingPath.Forward;
shadowCam.depthTextureMode |= DepthTextureMode.None;
shadowCam.orthographicSize = clipmapShadowSize;
shadowCam.farClipPlane = clipmapShadowSize * 2.0f * shadowSpaceDepthRatio;
//Shader.SetGlobalMatrix("WorldToGI", shadowCam.worldToCameraMatrix);
//Shader.SetGlobalMatrix("GIToWorld", shadowCam.cameraToWorldMatrix);
//Shader.SetGlobalMatrix("GIProjection", shadowCam.projectionMatrix);
//Shader.SetGlobalMatrix("GIProjectionInverse", shadowCam.projectionMatrix.inverse);
voxelToGIProjection = shadowCam.projectionMatrix * shadowCam.worldToCameraMatrix * voxelCamera.cameraToWorldMatrix;
Shader.SetGlobalMatrix("SEGIVoxelToGIProjection", voxelToGIProjection);
Graphics.SetRenderTarget(sunDepthTexture);
//shadowCam.SetTargetBuffers(sunDepthTexture.colorBuffer, sunDepthTexture.depthBuffer);
shadowCam.RenderWithShader(sunDepthShader, "");
Shader.SetGlobalTexture("SEGISunDepth", sunDepthTexture);
}
//Clear the volume texture that is immediately written to in the voxelization scene shader
clearCompute.SetTexture(0, "RG0", integerVolume);
clearCompute.SetInt("Resolution", activeClipmap.resolution);
clearCompute.Dispatch(0, activeClipmap.resolution / 16, activeClipmap.resolution / 16, 1);
//Set irradiance "secondary bounce" texture
Shader.SetGlobalTexture("SEGICurrentIrradianceVolume", irradianceClipmaps[currentClipmapIndex].volumeTexture0);
Graphics.SetRandomWriteTarget(1, integerVolume);
voxelCamera.targetTexture = dummyVoxelTextureAAScaled;
voxelCamera.RenderWithShader(voxelizationShader, "");
Graphics.ClearRandomWriteTargets();
//Transfer the data from the volume integer texture to the main volume texture used for GI tracing.
transferIntsCompute.SetTexture(0, "Result", activeClipmap.volumeTexture0);
transferIntsCompute.SetTexture(0, "RG0", integerVolume);
transferIntsCompute.SetInt("VoxelAA", settings.voxelAA ? 3 : 0);
transferIntsCompute.SetInt("Resolution", activeClipmap.resolution);
transferIntsCompute.Dispatch(0, activeClipmap.resolution / 16, activeClipmap.resolution / 16, 1);
//Push current voxelization result to higher levels
for (int i = 0 + 1; i < numClipmaps; i++)
{
Clipmap sourceClipmap = clipmaps[i - 1];
Clipmap targetClipmap = clipmaps[i];
Vector3 sourceRelativeOrigin = Vector3.zero;
float sourceOccupance = 0.0f;
sourceRelativeOrigin = (sourceClipmap.origin - targetClipmap.origin) / (targetClipmap.localScale * settings.voxelSpaceSize.value);
sourceOccupance = sourceClipmap.localScale / targetClipmap.localScale;
mipFilterCompute.SetTexture(0, "Source", sourceClipmap.volumeTexture0);
mipFilterCompute.SetTexture(0, "Destination", targetClipmap.volumeTexture0);
mipFilterCompute.SetVector("ClipmapOverlap", new Vector4(sourceRelativeOrigin.x, sourceRelativeOrigin.y, sourceRelativeOrigin.z, sourceOccupance));
mipFilterCompute.SetInt("destinationRes", targetClipmap.resolution);
mipFilterCompute.Dispatch(0, targetClipmap.resolution / 16, targetClipmap.resolution / 16, 1);
}
for (int i = 0; i < numClipmaps; i++)
{
Shader.SetGlobalTexture("SEGIVolumeLevel" + i.ToString(), clipmaps[i].volumeTexture0);
}
if (settings.infiniteBounces)
{
renderState = RenderState.Bounce;
}
else
{
//Increment clipmap counter
clipmapCounter++;
if (clipmapCounter >= (int)Mathf.Pow(2.0f, numClipmaps))
{
clipmapCounter = 0;
}
}
}
else if (renderState == RenderState.Bounce)
{
//Calculate the relative position and scale of the current clipmap as compared to the first (level 0) clipmap. Used to ensure tracing is performed in the correct space
Vector3 translateToZero = Vector3.zero;
translateToZero = (clipmaps[currentClipmapIndex].origin - clipmaps[0].origin) / (settings.voxelSpaceSize * clipmaps[currentClipmapIndex].localScale);
float scaleToZero = 1.0f / clipmaps[currentClipmapIndex].localScale;
Shader.SetGlobalVector("SEGICurrentClipTransform", new Vector4(translateToZero.x, translateToZero.y, translateToZero.z, scaleToZero));
//Clear the volume texture that is immediately written to in the voxelization scene shader
clearCompute.SetTexture(0, "RG0", integerVolume);
clearCompute.SetInt("Resolution", clipmaps[currentClipmapIndex].resolution);
clearCompute.Dispatch(0, (int)settings.voxelResolution.value / 16, (int)settings.voxelResolution.value / 16, 1);
//Only render infinite bounces for clipmaps 0, 1, and 2
if (currentClipmapIndex <= 2)
{
Shader.SetGlobalInt("SEGISecondaryCones", settings.secondaryCones);
Shader.SetGlobalFloat("SEGISecondaryOcclusionStrength", settings.secondaryOcclusionStrength);
Graphics.SetRandomWriteTarget(1, integerVolume);
voxelCamera.targetTexture = dummyVoxelTextureFixed;
voxelCamera.RenderWithShader(voxelTracingShader, "");
Graphics.ClearRandomWriteTargets();
transferIntsCompute.SetTexture(1, "Result", irradianceClipmaps[currentClipmapIndex].volumeTexture0);
transferIntsCompute.SetTexture(1, "RG0", integerVolume);
transferIntsCompute.SetInt("Resolution", (int)settings.voxelResolution.value);
transferIntsCompute.Dispatch(1, (int)settings.voxelResolution.value / 16, (int)settings.voxelResolution.value / 16, 1);
}
//Increment clipmap counter
clipmapCounter++;
if (clipmapCounter >= (int)Mathf.Pow(2.0f, numClipmaps))
{
clipmapCounter = 0;
}
renderState = RenderState.Voxelize;
}
}
Matrix4x4 giToVoxelProjection = voxelCamera.projectionMatrix * voxelCamera.worldToCameraMatrix * shadowCam.cameraToWorldMatrix;
Shader.SetGlobalMatrix("GIToVoxelProjection", giToVoxelProjection);
//Set the sun's shadow setting back to what it was before voxelization
if (SEGI_NKLI.Sun != null)
{
SEGI_NKLI.Sun.shadows = prevSunShadowSetting;
}
//Fix stereo rendering matrix
if (attachedCamera.stereoEnabled)
{
// Left and Right Eye inverse View Matrices
Matrix4x4 leftToWorld = attachedCamera.GetStereoViewMatrix(Camera.StereoscopicEye.Left).inverse;
Matrix4x4 rightToWorld = attachedCamera.GetStereoViewMatrix(Camera.StereoscopicEye.Right).inverse;
context.command.SetGlobalMatrix("_LeftEyeToWorld", leftToWorld);
context.command.SetGlobalMatrix("_RightEyeToWorld", rightToWorld);
Matrix4x4 leftEye = attachedCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Left);
Matrix4x4 rightEye = attachedCamera.GetStereoProjectionMatrix(Camera.StereoscopicEye.Right);
// Compensate for RenderTexture...
leftEye = GL.GetGPUProjectionMatrix(leftEye, true).inverse;
rightEye = GL.GetGPUProjectionMatrix(rightEye, true).inverse;
// Negate [1,1] to reflect Unity's CBuffer state
leftEye[1, 1] *= -1;
rightEye[1, 1] *= -1;
context.command.SetGlobalMatrix("_LeftEyeProjection", leftEye);
context.command.SetGlobalMatrix("_RightEyeProjection", rightEye);
}
//Fix stereo rendering matrix/
// OnRenderImage #################################################################
if (notReadyToRender)
{
context.command.Blit(context.source, context.destination);
return;
}
if (settings.visualizeSunDepthTexture.value && sunDepthTexture != null && sunDepthTexture != null)
{
context.command.Blit(sunDepthTexture, context.destination, material, 13);
return;
}
if (tracedTexture1UpdateCount == 160)
{
context.command.SetComputeIntParam(clearCompute, "Resolution", 1);
context.command.SetComputeTextureParam(clearCompute, 0, "RG0", tracedTextureA0);
context.command.DispatchCompute(clearCompute, 0, SEGIRenderWidth / 16, SEGIRenderHeight / 16, 1);
}
else if (tracedTexture1UpdateCount > 128)
{
context.command.SetComputeTextureParam(transferIntsCompute, 3, "Result", tracedTexture0);
context.command.SetComputeTextureParam(transferIntsCompute, 3, "RG1", tracedTexture1);
context.command.SetComputeIntParam(transferIntsCompute, "zStagger", tracedTexture1UpdateCount - 128);
context.command.SetComputeIntParam(transferIntsCompute, "Resolution", 256);
context.command.DispatchCompute(transferIntsCompute, 3, 512 / 16, 512 / 16, 1);
context.command.SetComputeIntParam(clearComputeCache, "Resolution", 256);
context.command.SetComputeTextureParam(clearComputeCache, 1, "RG1", tracedTexture1);
context.command.SetComputeIntParam(clearComputeCache, "zStagger", tracedTexture1UpdateCount - 128);
context.command.DispatchCompute(clearComputeCache, 1, 512 / 16, 512 / 16, 1);
}
tracedTexture1UpdateCount = (tracedTexture1UpdateCount + 1) % (161);
context.command.SetGlobalFloat("SEGIVoxelScaleFactor", voxelScaleFactor);
context.command.SetGlobalMatrix("CameraToWorld", context.camera.cameraToWorldMatrix);
context.command.SetGlobalMatrix("WorldToCamera", context.camera.worldToCameraMatrix);
context.command.SetGlobalMatrix("ProjectionMatrixInverse", context.camera.projectionMatrix.inverse);
context.command.SetGlobalMatrix("ProjectionMatrix", context.camera.projectionMatrix);
context.command.SetGlobalInt("FrameSwitch", frameSwitch);
context.command.SetGlobalInt("SEGIFrameSwitch", frameSwitch);
context.command.SetGlobalVector("CameraPosition", context.camera.transform.position);
context.command.SetGlobalFloat("DeltaTime", Time.deltaTime);
context.command.SetGlobalInt("StochasticSampling", settings.stochasticSampling.value ? 1 : 0);
context.command.SetGlobalInt("TraceDirections", settings.cones);
context.command.SetGlobalInt("TraceSteps", settings.coneTraceSteps);
context.command.SetGlobalFloat("TraceLength", settings.coneLength);
context.command.SetGlobalFloat("ConeSize", settings.coneWidth);
context.command.SetGlobalFloat("OcclusionStrength", settings.occlusionStrength);
context.command.SetGlobalFloat("OcclusionPower", settings.occlusionPower);
context.command.SetGlobalFloat("ConeTraceBias", settings.coneTraceBias);
context.command.SetGlobalFloat("GIGain", settings.giGain);
context.command.SetGlobalFloat("NearLightGain", settings.nearLightGain);
context.command.SetGlobalFloat("NearOcclusionStrength", settings.nearOcclusionStrength);
context.command.SetGlobalInt("DoReflections", settings.doReflections ? 1 : 0);
context.command.SetGlobalInt("GIResolution", settings.GIResolution);
context.command.SetGlobalInt("ReflectionSteps", settings.reflectionSteps);
context.command.SetGlobalFloat("ReflectionOcclusionPower", settings.reflectionOcclusionPower);
context.command.SetGlobalFloat("SkyReflectionIntensity", settings.skyReflectionIntensity);
context.command.SetGlobalFloat("FarOcclusionStrength", settings.farOcclusionStrength);
context.command.SetGlobalFloat("FarthestOcclusionStrength", settings.farthestOcclusionStrength);
context.command.SetGlobalTexture("NoiseTexture", blueNoise[frameSwitch % 64]);
context.command.SetGlobalFloat("BlendWeight", settings.temporalBlendWeight);
//context.command.SetGlobalInt("useReflectionProbes", settings.useReflectionProbes ? 1 : 0);
//context.command.SetGlobalFloat("reflectionProbeIntensity", settings.reflectionProbeIntensity);
//material.SetFloat("reflectionProbeAttribution", settings.reflectionProbeAttribution.value);
context.command.SetGlobalInt("StereoEnabled", context.stereoActive ? 1 : 0);
context.command.SetGlobalInt("SEGIRenderWidth", SEGIRenderWidth);
context.command.SetGlobalInt("SEGIRenderHeight", SEGIRenderHeight);
context.command.SetGlobalFloat("voxelSpaceSize", settings.voxelSpaceSize);
//context.command.SetGlobalInt("tracedTexture1UpdateCount", (int)tracedTexture1.updateCount - (int)tracedTexture1UpdateCount);
//Blit once to downsample if required
context.command.Blit(context.source, RT_gi1);
if (context.camera.renderingPath == RenderingPath.Forward)
{
//context.command.Blit(context.source, RT_Albedo, ColorCorrection_Material, 0);
//context.command.Blit(RT_Albedo, RT_AlbedoX2, material, Pass.BilateralUpsample);
context.command.SetGlobalTexture("_SEGICube", RT_Albedo);
//context.command.SetGlobalTexture("_SEGICubeX2", RT_AlbedoX2);
//context.command.SetGlobalTexture("_SEGIReflectCube", reflectionProbe.texture);
context.command.SetGlobalInt("ForwardPath", 1);
}
else context.command.SetGlobalInt("ForwardPath", 0);
//If Visualize Voxels is enabled, just render the voxel visualization shader pass and return
if (settings.visualizeVoxels.value)
{
context.command.Blit(context.source, context.destination, material, Pass.VisualizeVoxels);
return;
}
//Set the previous GI result and camera depth textures to access them in the shader
context.command.SetGlobalTexture("PreviousGITexture", previousGIResult);
context.command.SetGlobalTexture("PreviousDepth", previousDepth);
//Render diffuse GI tracing result
context.command.SetRandomWriteTarget(1, tracedTexture0);
context.command.SetRandomWriteTarget(2, tracedTexture1);
context.command.SetRandomWriteTarget(3, tracedTextureA0);
context.command.Blit(RT_gi1, RT_gi2, material, Pass.DiffuseTrace);
//Render GI reflections result
if (settings.doReflections.value)
{
context.command.Blit(RT_gi1, RT_reflections, material, Pass.SpecularTrace);
context.command.SetGlobalTexture("Reflections", RT_reflections);
}
//If Half Resolution tracing is enabled