void Start() { int bufSize; Vector3[] meshVertices; system = Build(vertexCount, out bufSize, out meshVertices); system.transform.parent = transform; mrts = new MRT[3]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } // create a render texture and transfer the initial particle postions to the update shader initialPos = new RenderTexture(bufSize, bufSize, 24); initialPos.format = RenderTextureFormat.ARGBFloat; RenderTexture.active = initialPos; Texture2D tempTexture = new Texture2D(initialPos.width, initialPos.height, TextureFormat.RGBAFloat, false); tempTexture.ReadPixels(new Rect(0, 0, initialPos.width, initialPos.height), 0, 0, false); for (int c = 0, i = 0; c < initialPos.width; c++) { for (int r = 0; r < initialPos.height; r++, i++) { tempTexture.SetPixel(r, c, new Color(meshVertices[i].x, meshVertices[i].y, meshVertices[i].z, 1)); //Debug.Log(meshVertices[i].x.ToString()+" "+meshVertices[i].y.ToString()+" "+meshVertices[i].z.ToString() ); } } tempTexture.Apply(); RenderTexture.active = null; Graphics.Blit(tempTexture, initialPos); SPH_UpdateMat.SetTexture("_PosTex", initialPos); SPH_UpdateDensityMat.SetTexture("_PosTex", initialPos); mrts[2].Render(SPH_UpdateDensityMat); var pressureBuffers = mrts[2].RenderTextures; SPH_UpdateMat.SetTexture("_DensityTex", pressureBuffers[0]); SPH_UpdateMat.SetTexture("_PressureTex", pressureBuffers[1]); ReadMRT.Render(SPH_UpdateMat); var buffers = ReadMRT.RenderTextures; RenderTexture.active = pressureBuffers[0]; tempTexture = new Texture2D(buffers[1].width, buffers[1].height, TextureFormat.RGBAFloat, false); tempTexture.ReadPixels(new Rect(0, 0, buffers[1].width, buffers[1].height), 0, 0, false); for (int i = 0; i < tempTexture.width; i++) { for (int j = 0; j < tempTexture.height; j++) { //Debug.Log(tempTexture.GetPixel(j, i).r.ToString() + " " + tempTexture.GetPixel(j, i).g.ToString() + " " + tempTexture.GetPixel(j, i).b.ToString()); } } RenderTexture.active = null; }
// Use this for initialization void Start() { //******** Create water mesh ******** waterMeshFilter = GetComponent <MeshFilter>(); GenerateWaterMesh.GenerateWater(waterMeshFilter, waterWidth, gridSpacing); //Need a box collider so the mouse can interact with the water BoxCollider boxCollider = GetComponent <BoxCollider>(); boxCollider.size = new Vector3(waterWidth, 0.1f, waterWidth); //******** Precompute kernel ******** storedKernelArray = new float[2 * P + 1, 2 * P + 1]; PrecomputeKernelValues(); //Get water mesh and its vertice waterMesh = waterMeshFilter.mesh; meshVertices = new List <Vector3>(); waterMesh.GetVertices(meshVertices); verticePerRow = (int)Mathf.Sqrt(meshVertices.Count); //Initialization source = new float[verticePerRow, verticePerRow]; obstruction = new float[verticePerRow, verticePerRow]; data = new RenderTexture(verticePerRow, verticePerRow, 24); data.format = RenderTextureFormat.ARGBFloat; kernel = new RenderTexture(2 * P + 1, 2 * P + 1, 24); kernel.format = RenderTextureFormat.ARGBFloat; for (int c = 0, i = 0; c < verticePerRow; c++) { for (int r = 0; r < verticePerRow; r++, i++) { if (c == 0 || c == verticePerRow - 1 || r == 0 || r == verticePerRow - 1) { obstruction[c, r] = 0f; } else { obstruction[c, r] = 1f; } } } ApplyFloatsToRT(storedKernelArray, kernel); //Set shader parameters waterMat = GetComponent <Renderer>().material; waveUpdateMat.SetTexture("_kernel", kernel); waveUpdateMat.SetFloat("kernelSize", P); //Multiple render target mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(verticePerRow, verticePerRow); } }
// Use this for initialization void Start() { plane = GetComponent <MeshFilter>().mesh; int bufSize = Mathf.CeilToInt(Mathf.Sqrt(plane.vertexCount * 1.0f)); mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } ReadMRT.Render(particleUpdateMat, 0); // init }
void Start() { int bufSize; system = Build(vertexCount, out bufSize); system.transform.parent = transform; mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } ReadMRT.Render(particleUpdateMat, 0); // init }
// Use this for initialization void Start() { surfaceRender = this.GetComponent <Renderer>(); //******** Precompute kernel ******** storedKernelArray = new float[2 * P + 1, 2 * P + 1]; PrecomputeKernelValues(); //Get water mesh and its vertice meshVertices = new List <Vector3>(); GetComponent <MeshFilter>().mesh.GetVertices(meshVertices); verticePerRow = (int)Mathf.Sqrt(meshVertices.Count); //Initialization source = new float[verticePerRow, verticePerRow]; obstruction = new float[verticePerRow, verticePerRow]; data = new RenderTexture(verticePerRow, verticePerRow, 24); data.format = RenderTextureFormat.ARGBFloat; kernel = new RenderTexture(2 * P + 1, 2 * P + 1, 24); kernel.format = RenderTextureFormat.ARGBFloat; for (int c = 0, i = 0; c < verticePerRow; c++) { for (int r = 0; r < verticePerRow; r++, i++) { if (c == 0 || c == verticePerRow - 1 || r == 0 || r == verticePerRow - 1) { obstruction[c, r] = 0f; } else { obstruction[c, r] = 1f; } } } ApplyFloatsToRT(storedKernelArray, kernel); //Set shader parameters waveUpdateMat.SetTexture("_kernel", kernel); waveUpdateMat.SetFloat("kernelSize", P); //Multiple render target mrts = new MRT[2]; for (int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(verticePerRow, verticePerRow); } }
public ViewResult Index(MRT mrt) { if (ModelState.IsValid) { double[,] rate = { { 0.8, 1.2, 1.8, 2.0, 2.6, 2.7, 3.1, 3.3, 3.2, 3.5, 3.3, 3.4, 3.1, 3.2, 3.3, 3.4, 3.5, 3.6, 3.7, 3.9, 4.0, 4.1, 4.3, 4.5, 4.6, 4.8, 4.8, 5.0, 5.3, 5.4, 5.5 }, { 1.2, 0.8, 1.5, 1.8, 2.3, 2.7, 2.8, 3.1, 3.4, 3.3, 3.7, 3.3, 3.7, 3.8, 3.2, 3.3, 3.4, 3.5, 3.6, 3.8, 3.9, 4.0, 4.2, 4.4, 4.5, 4.6, 4.7, 4.9, 5.2, 5.2, 5.4 }, { 1.8, 1.5, 0.8, 1.1, 1.8, 2.1, 2.6, 2.6, 3.0, 3.2, 3.3, 3.5, 3.4, 3.5, 3.6, 3.7,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7, 3.6, 3.5, 3.3, 3.7, 3.6, 3.3, 3.1, 3.3, 3.0, 2.6, 2.5, 2.2, 2.0, 1.7, 0.8, 1.1, 1.4 }, { 5.4, 5.2, 5.0, 4.9, 4.6, 4.5, 4.3, 4.2, 4.0, 3.9, 3.6, 3.5, 3.2, 3.8, 3.7, 3.6, 3.4, 3.3, 3.7, 3.4, 3.3, 3.4, 3.1, 2.7, 2.7, 2.3, 2.2, 1.8, 1.1, 0.8, 1.2 }, { 5.5, 5.4, 5.1, 5.0, 4.8, 4.6, 4.4, 4.3, 4.1, 4.0, 3.7, 3.6, 3.3, 3.2, 3.2, 3.8, 3.6, 3.4, 3.3, 3.6, 3.5, 3.2, 3.4, 3.0, 2.7, 2.7, 2.5, 2.1, 1.4, 1.2, 0.8 } }; IDictionary <int, string> dictOrigin = new Dictionary <int, string>() { { 0, "Sungai Buloh" }, { 1, "Kampung Selamat" }, { 2, "Kwasa Damansara" }, { 3, "Kwasa Sentral" }, { 4, "Kota Damansara" }, { 5, "Srian" }, { 6, "Mutiara Damansara" }, { 7, "Bandar Utama" }, { 8, "Taman Dr Tun Ismail" }, { 9, "Phelio Damansara" }, { 10, "Pusat Bandar Damansara" }, { 11, "Semantan" }, { 12, "Muzium Negara" }, { 13, "Pasar Seni" }, { 14, "Merdeka" }, { 15, "Bukit Bintang" }, { 16, "Tun Razak Exchange" }, { 17, "Cochrane" }, { 18, "Maluri" }, { 19, "Taman Pertama" }, { 20, "Taman Midah" }, { 21, "Taman Mutiara" }, { 22, "Taman Connaught" }, { 23, "Taman Suntext" }, { 24, "Sri Raya" }, { 25, "Bandar Tun Hussein Onn" }, { 26, "Batu Sebelas Cheras" }, { 27, "Bukit Dukung" }, { 28, "Sungai Jernih" }, { 29, "Stadium Kajang" }, { 30, "Kajang" } }; IDictionary <int, string> dictDestination = new Dictionary <int, string>() { { 0, "Sungai Buloh" }, { 1, "Kampung Selamat" }, { 2, "Kwasa Damansara" }, { 3, "Kwasa Sentral" }, { 4, "Kota Damansara" }, { 5, "Surian" }, { 6, "Mutiara Damansara" }, { 7, "Bandar Utama" }, { 8, "Taman Dr Tun Ismail" }, { 9, "Phelio Damansara" }, { 10, "Pusat Bandar Damansara" }, { 11, "Semantan" }, { 12, "Muzium Negara" }, { 13, "Pasar Seni" }, { 14, "Merdeka" }, { 15, "Bukit Bintang" }, { 16, "Tun Razak Exchange" }, { 17, "Cochrane" }, { 18, "Maluri" }, { 19, "Taman Pertama" }, { 20, "Taman Midah" }, { 21, "Taman Mutiara" }, { 22, "Taman Connaught" }, { 23, "Taman Suntext" }, { 24, "Sri Raya" }, { 25, "Bandar Tun Hussein Onn" }, { 26, "Batu Sebelas Cheras" }, { 27, "Bukit Dukung" }, { 28, "Sungai Jernih" }, { 29, "Stadium Kajang" }, { 30, "Kajang" } }; ViewBag.Quantity = mrt.Quantity; ViewBag.Name = mrt.Name; ViewBag.Email = mrt.Email; ViewBag.Rate = rate; ViewBag.DictOrigin = dictOrigin; ViewBag.DictDestination = dictDestination; int originIndex = int.Parse(mrt.Origin); ViewBag.Origin = dictOrigin[originIndex]; int destinationIndex = int.Parse(mrt.Destination); ViewBag.Destination = dictDestination[destinationIndex]; double fare = rate[originIndex, destinationIndex]; ViewBag.Fare = fare; DateTime datetime = DateTime.Now; ViewBag.Datetime = datetime; ViewBag.TicketType = mrt.TicketType; return(View("Result", mrt)); } else { return(View()); } }
void Start() { mrt = new MRT(Screen.width, Screen.height); mat = new Material(testShader); }
void Start() { int bufSize; system = Build(vertexCount, out bufSize); system.transform.parent = transform; mrts = new MRT[2]; for(int i = 0, n = mrts.Length; i < n; i++) { mrts[i] = new MRT(bufSize, bufSize); } ReadMRT.Render(particleUpdateMat, 0); // init }