@@ -13,7 +13,8 @@ public class CloudRenderer : MonoBehaviour
13
13
public ParticleSystem ps ;
14
14
15
15
private NativeArray < ParticleSystem . Particle > particles ;
16
- private ParticleSystem . Particle [ ] parts ;
16
+ //private ParticleSystem.Particle[] parts;
17
+ private MaterialPropertyBlock [ ] mpbs ;
17
18
18
19
private void OnEnable ( )
19
20
{
@@ -22,7 +23,12 @@ private void OnEnable()
22
23
23
24
var main = ps . main ;
24
25
particles = new NativeArray < ParticleSystem . Particle > ( main . maxParticles , Allocator . Persistent ) ;
25
- parts = new ParticleSystem . Particle [ main . maxParticles ] ;
26
+ //parts = new ParticleSystem.Particle[main.maxParticles];
27
+ mpbs = new MaterialPropertyBlock [ main . maxParticles ] ;
28
+ for ( var index = 0 ; index < mpbs . Length ; index ++ )
29
+ {
30
+ mpbs [ index ] = new MaterialPropertyBlock ( ) ;
31
+ }
26
32
}
27
33
28
34
private void OnDisable ( )
@@ -43,13 +49,14 @@ public void DrawClouds(Camera camera)
43
49
if ( ! cloudMaterial || cloudMeshes == null || cloudMeshes . Length == 0 ) return ;
44
50
45
51
var camPos = camera . transform . position ;
46
- var aliveCount = ps . GetParticles ( parts ) ;
47
- var l = parts . ToList ( ) . OrderByDescending ( x => Vector3 . Distance ( x . position , camPos ) ) ;
48
- parts = l . ToArray ( ) ;
52
+ var aliveCount = ps . GetParticles ( particles ) ;
53
+ particles . OrderByDescending ( x => Vector3 . Distance ( x . position , camPos ) ) ;
54
+
55
+ var scale = Vector3 . zero ;
49
56
50
57
for ( var index = 0 ; index < aliveCount ; index ++ )
51
58
{
52
- var particle = parts [ index ] ;
59
+ var particle = particles [ index ] ;
53
60
if ( particle . remainingLifetime <= 0.001f ) continue ;
54
61
55
62
var pos = particle . position * SkyboxSystem . SkyboxScale + camPos * ( 1 - SkyboxSystem . SkyboxScale ) ;
@@ -58,14 +65,13 @@ public void DrawClouds(Camera camera)
58
65
Random . InitState ( ( int ) particle . randomSeed ) ;
59
66
var mesh = cloudMeshes [ Random . Range ( 0 , cloudMeshes . Length ) ] ;
60
67
61
- var scale = particle . startSize3D ;
68
+ scale = particle . startSize3D ;
62
69
scale . x *= Random . value > 0.5f ? 1f : - 1f ;
63
70
64
- MaterialPropertyBlock mpb = new MaterialPropertyBlock ( ) ;
65
- mpb . SetVector ( "_BA_CloudData" , new Vector4 ( scale . x , 0f , 0f , particle . GetCurrentColor ( ps ) . a / 255f ) ) ;
71
+ mpbs [ index ] . SetVector ( "_BA_CloudData" , new Vector4 ( scale . x , 0f , 0f , particle . GetCurrentColor ( ps ) . a / 255f ) ) ;
66
72
67
73
Graphics . DrawMesh ( mesh , Matrix4x4 . TRS ( pos , q , scale * SkyboxSystem . SkyboxScale ) ,
68
- cloudMaterial , LayerMask . NameToLayer ( "3DSkybox" ) , camera , 0 , mpb , false , false , false ) ;
74
+ cloudMaterial , LayerMask . NameToLayer ( "3DSkybox" ) , camera , 0 , mpbs [ index ] , false , false , false ) ;
69
75
}
70
76
}
71
77
}
0 commit comments