public void UpdateColourOverLifetime() { if (colourOverLifetimeTexture == null) { return; } TCHelper.TextureFromGradient(ColourOverLifetime, colourOverLifetimeTexture, TintColor, -1.0f); }
public void Dispatch() { if (useBoidsFlocking) { if (m_boidsFlock == null) { CreateBoids(); } m_boidsFlock.UpdateBoids(); } if (MaxForces == 0) { return; } if (m_forcesCount[0] > 0) { m_forcesBuffer[0].SetData(m_forcesStruct[0]); ComputeShader.SetBuffer(UpdateForcesKernel, "forces", m_forcesBuffer[0]); Manager.SetPariclesToKernel(ComputeShader, UpdateForcesKernel); ComputeShader.Dispatch(UpdateForcesKernel, Manager.DispatchCount, m_forcesCount[0], 1); } if (m_forcesCount[1] > 0) { m_forcesBuffer[1].SetData(m_forcesStruct[1]); ComputeShader.SetBuffer(UpdateTurbulenceForcesKernel, "turbulenceForces", m_forcesBuffer[1]); for (int k = 0; k < m_forcesCount[1]; ++k) { TCForce force = m_forcesReference[1][k]; if (force.CurrentForceVolume == null) { continue; } ComputeShader.SetTexture(UpdateTurbulenceForcesKernel, "turbulenceTexture", force.CurrentForceVolume); Matrix4x4 rotation = Matrix4x4.TRS(Vector3.zero, force.transform.rotation, Vector3.one); TCHelper.SetMatrix3(ComputeShader, "turbulenceRotation", rotation); TCHelper.SetMatrix3(ComputeShader, "invTurbulenceRotation", rotation.inverse); ComputeShader.SetInt("turbulenceKernelOffset", k); Manager.SetPariclesToKernel(ComputeShader, UpdateTurbulenceForcesKernel); ComputeShader.Dispatch(UpdateTurbulenceForcesKernel, Manager.DispatchCount, 1, 1); } } }
void UpdateMatrix(ParticleEmitterShape emitShape, Transform trans) { var localScale = trans.localScale; Profiler.BeginSample("Set matrices"); Matrix4x4 id = Matrix4x4.identity; switch (Manager.SimulationSpace) { case Space.World: var rot = trans.rotation; if (m_lastRot != rot || m_lastScale != localScale) { m_emitMatrix = Matrix4x4.TRS(Vector3.zero, rot, localScale); m_emitRotationMatrix = Matrix4x4.TRS(Vector3.zero, rot, Vector3.one); m_lastRot = rot; m_lastScale = localScale; } TCHelper.SetMatrix4(ComputeShader, "emitterMatrix", m_emitMatrix); TCHelper.SetMatrix3(ComputeShader, "emitterRotationMatrix", m_emitRotationMatrix); break; case Space.Local: TCHelper.SetMatrix4(ComputeShader, "emitterMatrix", Matrix4x4.TRS(Vector3.zero, Quaternion.identity, localScale)); TCHelper.SetMatrix3(ComputeShader, "emitterRotationMatrix", id); break; case Space.LocalWithScale: TCHelper.SetMatrix4(ComputeShader, "emitterMatrix", id); TCHelper.SetMatrix3(ComputeShader, "emitterRotationMatrix", id); break; case Space.Parent: if (trans.parent != null) { var rot2 = trans.localRotation; TCHelper.SetMatrix4(ComputeShader, "emitterMatrix", Matrix4x4.TRS(Vector3.zero, rot2, localScale)); TCHelper.SetMatrix3(ComputeShader, "emitterRotationMatrix", Matrix4x4.TRS(Vector3.zero, rot2, Vector3.one)); } break; } if (emitShape.startDirectionType == StartDirectionType.Vector) { TCHelper.SetMatrix3(ComputeShader, "emitterStartRotationMatrix", Matrix4x4.TRS(Vector3.zero, Quaternion.FromToRotation(Vector3.forward, emitShape.startDirectionVector), Vector3.one)); } Profiler.EndSample(); }
protected override void Bind() { DistributeColliders(); if (MaxColliders == 0 || m_collidersList.Count == 0) { return; } Vector3 parentPosition = Vector3.zero; if (Transform.parent != null) { parentPosition = Transform.parent.position; } for (int c = 0; c < m_colliderCount; ++c) { TCCollider col = m_colliderReference[c]; var rc = new Collider { Position = col.Position, Radius = 0.0f, BoxSize = Vector3.zero }; float xzscale = TCHelper.TransXzScale(col.transform); float scale = TCHelper.TransScale(col.transform); float yscale = col.transform.localScale.y; Vector3 lscale = col.transform.localScale; switch (col.shape) { case ColliderShape.PhysxShape: if (col.SphereCollider != null) { rc.Radius = col.SphereCollider.radius * scale; rc.BoxSize = Vector3.zero; rc.Vtype = 0; } else if (col.CapsuleCollider != null) { rc.Radius = col.CapsuleCollider.radius * xzscale; rc.BoxSize = new Vector3(0.0f, Mathf.Max(0, col.CapsuleCollider.height / 2.0f * yscale - rc.Radius * 2.0f), 0.0f); rc.Vtype = 1; } else if (col.BoxCollider != null) { rc.Radius = 0.5f; rc.BoxSize = Vector3.Scale(col.BoxCollider.size * 0.5f, lscale); rc.BoxSize = new Vector3(Mathf.Max(0, rc.BoxSize.x - rc.Radius), Mathf.Max(0, rc.BoxSize.y - rc.Radius), Mathf.Max(0, rc.BoxSize.z - rc.Radius)); rc.Vtype = 2; } break; case ColliderShape.RoundedBox: rc.Radius = Mathf.Max(0.1f, col.rounding); rc.BoxSize = Vector3.Scale(col.boxSize * 0.5f, lscale); rc.BoxSize = new Vector3(Mathf.Max(0, rc.BoxSize.x - rc.Radius), Mathf.Max(0, rc.BoxSize.y - rc.Radius), Mathf.Max(0, rc.BoxSize.z - rc.Radius)); rc.Vtype = 2; break; case ColliderShape.Hemisphere: rc.Radius = 0.05f; rc.BoxSize = new Vector3(col.radius.Max * scale, col.radius.Max * scale, col.radius.Max * scale); rc.Vtype = 3; break; case ColliderShape.Disc: float rMin = col.radius.IsConstant ? 0.0f : col.radius.Min * xzscale; float rMax = col.radius.Max * xzscale; rc.Radius = Mathf.Max(0.1f, col.rounding); rc.BoxSize = new Vector3(rMin, col.discHeight / 2.0f * yscale - col.rounding, rMax); switch (col.discType) { case DiscType.Full: rc.Vtype = 4; break; case DiscType.Half: rc.Vtype = 5; break; case DiscType.Quarter: rc.Vtype = 6; break; } break; case ColliderShape.Terrain: var terrain = col.GetComponent <Terrain>(); if (terrain == null) { rc.BoxSize = Vector3.zero; } else { Vector3 terrainScale = terrain.terrainData.heightmapScale; rc.BoxSize = new Vector3(terrainScale.x * terrain.terrainData.heightmapResolution, terrainScale.y, terrainScale.z * terrain.terrainData.heightmapResolution); } rc.Vtype = 7; break; default: rc.Vtype = 0; break; } rc.AxisX = col.transform.right; rc.AxisY = col.transform.up; rc.AxisZ = col.transform.forward; const float eps = 0.01f; float elasticity = 1.0f + eps + Mathf.Lerp(0.0f, 1.0f - eps * 2.0f, overrideBounciness ? Bounciness : col.Bounciness); rc.Bounciness = elasticity; rc.Velocity = col.Velocity * col.InheritVelocity * 0.5f; rc.LifeLoss = col.ParticleLifeLoss * PartEmitter.Energy.Max * Manager.ParticleTimeDelta; rc.IsInverse = (uint)(col.inverse ? 1 : 0); float s = overrideStickiness ? Stickiness : col.Stickiness; float deltaSticky = Mathf.Clamp01(1.0f - Mathf.Pow(s, 0.05f / Manager.ParticleTimeDelta)); rc.Stickiness = deltaSticky; switch (Manager.SimulationSpace) { case Space.Local: rc.Position = Transform.InverseTransformPoint(rc.Position); rc.AxisX = Transform.InverseTransformDirection(rc.AxisX); rc.AxisY = Transform.InverseTransformDirection(rc.AxisY); rc.AxisZ = Transform.InverseTransformDirection(rc.AxisZ); rc.Velocity = Transform.InverseTransformDirection(rc.Velocity); break; case Space.Parent: rc.Position -= parentPosition; break; } m_colliderStruct[c] = rc; } }