// Use this for initialization void Start() { p = MiscPSystemControls.inst; inputty = this.gameObject.GetComponent <InputField>(); inputty.onEndEdit.AddListener(OnEndEdit); inputty.onValueChanged.AddListener(OnValChange); placeholder = inputty.placeholder.GetComponent <Text>(); }
void Start() { psystem = MiscPSystemControls.inst; Application.targetFrameRate = -1; BufferHandlerPS1.inst = this; ParticleCountItterator.Init(this); int sqrtCount = (int)Mathf.Sqrt(count); PosBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); VelBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); PosBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); VelBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); IdAgeBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default); IdAgeBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default); DeadBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Append); LiveBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Counter); Vector3[] points = new Vector3[count]; Vector3[] velocities = new Vector3[count]; Vector2[] idAges = new Vector2[count]; int[] indecies = new int[count]; argBuffer = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments); deadBuffArgBuff = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments); Random.InitState(0); for (int i = 0; i < count; i++) { indecies[i] = i; points[i] = new Vector3(-3f + (float)((int)(i / 1000)) * 0.3f, (i % 1000) / 100f, -5); velocities[i] = Vector3.one * 0.01f; idAges[i] = new Vector2(0, -1.0f); } PosBuffer[READ].SetData(points); PosBuffer[WRITE].SetData(points); VelBuffer[READ].SetData(velocities); VelBuffer[WRITE].SetData(velocities); IdAgeBuffer[READ].SetData(idAges); IdAgeBuffer[WRITE].SetData(idAges); DeadBuffer.SetData(indecies); DeadBuffer.SetCounterValue((uint)(count)); lastVelMod = IsPlaying; }
// Use this for initialization void Start() { MiscPSystemControls.inst = this; }
// Update is called once per frame void Update() { MiscPSystemControls.inst = this; }
void DoUpdate() { if (psystem == null) { psystem = MiscPSystemControls.inst; } Vector2 screnpont = Input.mousePosition; Vector3 singularity = Camera.main.ScreenToWorldPoint(new Vector3(screnpont.x, screnpont.y, singularityStickDistance)); if (gravityObject != null) { singularity = gravityObject.position; } cShade.SetVector("_SingularityPosANDdt", new Vector4(singularity.x, singularity.y, singularity.z, Time.deltaTime * Mathf.Abs(simSpeed))); cShade.SetFloat("_Time", Time.time); Vector4 gravDirAndStr = new Vector4(psystem.GravityDir.x, psystem.GravityDir.y, psystem.GravityDir.z, psystem.GravityStrength); cShade.SetVector("_GravityDirAndStr", gravDirAndStr); cShade.SetVector("_PartBounceFricDrag", psystem.BounceFricDrag); cShade.SetVector("_SuckstrInOutdistInOut", psystem.suckInnerOuter); cShade.SetVector("_EmitVelRotXYapertureXY", psystem.emitVelDirData); cShade.SetVector("_SuckDampSphereMousedown", new Vector4(psystem.SuckCaptureDampening, downDampening, 000000, IsPlaying));//ISDOWN cShade.SetVector("_EmitVelPosVariance", psystem.emitVelspeedrangePosoffrange); cShade.SetVector("_EmitPosRotXYapertureXY", psystem.emitPosRotAperature); cShade.SetVector("_EmitPos", psystem.emitPosBase); cShade.SetVector("_PartAgeVariance", psystem.ageMinVar); cShade.SetVector("_WindDats", psystem.windData); //resets the livebuffer, basically emptying it out. LiveBuffer.SetCounterValue(0); Shader.SetGlobalVector("_MaxAge", new Vector4(psystem.ParticleAgeMin, psystem.ParticleAgeVariation, psystem.ParticleAgeVariation + psystem.ParticleAgeMin, 0.0f)); DoSpawning(); DoSimming(); if (debugframe) { debugframe = false; /* ComputeBuffer argBuffer = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments); * int[] args = new int[]{ 0, 1, 0, 0 }; * * argBuffer.SetData(args); * * ComputeBuffer.CopyCount(LiveBuffer, argBuffer, 0); * * argBuffer.GetData(args); * * string toDebug = ""; * toDebug += "\nvertex count " + args[0]; * toDebug += "\ninstance count " + args[1]; * toDebug += "\nstart vertex " + args[2]; * toDebug += "\nstart instance " + args[3]; * * Debug.Log("TODEBUG" + toDebug); */ } Swap(PosBuffer); Swap(VelBuffer); Swap(IdAgeBuffer); if (!Input.GetKey(KeyCode.LeftShift)) { this.singularityStickDistance -= Input.mouseScrollDelta.y; // Debug.Log(-Input.mouseScrollDelta.y +" singularity: " + this.singularityStickDistance); } particleCountDisplayerTextObj.GetComponent <Text>().text = "Simulated Particles:\t\t\t" + this.liveParticles + "\nMax Particles in System:\t" + this.count; }
void Start() { psystem = MiscPSystemControls.inst; Application.targetFrameRate = -1; BufferHandlerPS1.inst = this; ParticleCountItterator.Init(this); int sqrtCount = (int)Mathf.Sqrt(count); ColBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 4, ComputeBufferType.Default); ColBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 4, ComputeBufferType.Default); PosBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); VelBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); PosBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); VelBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 3, ComputeBufferType.Default); IdAgeBuffer[WRITE] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default); IdAgeBuffer[READ] = new ComputeBuffer(count, sizeof(float) * 2, ComputeBufferType.Default); DeadBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Append); LiveBuffer = new ComputeBuffer(count, sizeof(int), ComputeBufferType.Counter); Vector3[] points = new Vector3[count]; Vector3[] velocities = new Vector3[count]; Vector2[] idAges = new Vector2[count]; int[] indecies = new int[count]; Vector4[] colorz = new Vector4[count]; argBuffer = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments); deadBuffArgBuff = new ComputeBuffer(4, sizeof(int), ComputeBufferType.IndirectArguments); Random.InitState(0); for (int i = 0; i < count; i++) { indecies[i] = i; points[i] = new Vector3(-3f + (float)((int)(i / 1000)) * 0.3f, (i % 1000) / 100f, -5); velocities[i] = Vector3.one * 0.01f; idAges[i] = new Vector2(0, -1.0f); colorz[i] = new Vector4(0, 0, 0, 0); } PosBuffer[READ].SetData(points); PosBuffer[WRITE].SetData(points); VelBuffer[READ].SetData(velocities); VelBuffer[WRITE].SetData(velocities); IdAgeBuffer[READ].SetData(idAges); IdAgeBuffer[WRITE].SetData(idAges); ColBuffer[READ].SetData(colorz); ColBuffer[WRITE].SetData(colorz); DeadBuffer.SetData(indecies); DeadBuffer.SetCounterValue((uint)(count)); lastVelMod = IsPlaying; cubeCountSide = Mathf.ClosestPowerOfTwo(Mathf.Abs(cubeCountSide)); cubeCountTotal = (int)Mathf.Pow(cubeCountSide, 2); CubeDimBuffer[WRITE] = new ComputeBuffer(cubeCountTotal, sizeof(float) * 4, ComputeBufferType.Default); CubeDimBuffer[READ] = new ComputeBuffer(cubeCountTotal, sizeof(float) * 4, ComputeBufferType.Default); cShade.SetInt("_CubeCount", cubeCountTotal); CubeDats[] cubdat = new CubeDats[cubeCountTotal]; Vector2 WLdims = new Vector2(1.5f, 1.5f); for (int i = 0; i < cubeCountTotal; i++) { int xcoord = (int)(i / cubeCountSide); int ycoord = (int)(i % cubeCountSide); float truheight = Mathf.Abs((float)xcoord - cubeCountSide * 0.5f) + Mathf.Abs((float)ycoord - cubeCountSide * 0.5f); CubeDats newdat = new CubeDats(new Vector2(xcoord, ycoord), WLdims, truheight * 0.2f, 0f, new Vector3(-cubeCountSide * 0.5f * WLdims.x, 0f, -cubeCountSide * 0.5f * WLdims.y)); newdat.dims *= 0.5f; cubdat[i] = newdat; } GameObject papa = new GameObject(); for (int i = 0; i < cubeCountTotal; i++) { GameObject newcub = GameObject.CreatePrimitive(PrimitiveType.Cube); newcub.GetComponent <MeshRenderer>().material = this.cubeMat; newcub.transform.position = cubdat[i].center; newcub.transform.localScale = cubdat[i].dims * 2f; newcub.transform.SetParent(papa.transform); } CubeDimBuffer[READ].SetData(cubdat); CubeDimBuffer[WRITE].SetData(cubdat); }