public void ResetParameters(MinMaxVec mm) { ComputeDirectionVectors(); Vector3Int box, box_center; mm.GetRenderTextureBoundingBox((int)Constants.ThreadMutiples, out box, out box_center); if (NozzleRT && NozzleRT.IsCreated()) { NozzleRT.Release(); } NozzleRT = FFT.CreateRenderTexture3D(box.x, box.y, box.z, RenderTextureFormat.RFloat); topleft = ISFUtils.IntToFloat(box_center) - ISFUtils.IntToFloat(box) / 2; if (topleft.x < 0 || topleft.y < 0 || topleft.z < 0) { Debug.LogError("The bounding box excceeds"); } nozzle_relative_center = ISFUtils.IntToFloat(box) / 2; nozzle_center_in_shader = ISFUtils.IntToFloat(box_center); SetCSData(); CS.SetTexture(kernelCreateNozzleMask, "Nozzle", NozzleRT); DispatchCS(kernelCreateNozzleMask); }
void Prepare() { InitScale(); fft = isf.fft; fft.init(); isf.hbar = HBar; isf.size = Size; isf.N = N; isf.estimate_dt = 1.0f / DtInv; NFloat = ISFUtils.IntToFloat(N); isf.InitComputeShader(); isf.InitISF(); psi1 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); psi2 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); isf.InitializePsi(ref psi1, ref psi2); InitComputeShader(); InitPsi(ref psi1, ref psi2); InitParticles(); }
void Prepare() { fft = isf.fft; fft.init(); isf.hbar = HBar; isf.estimate_dt = 1.0f / InvDt; isf.InitComputeShader(); isf.InitISF(); InitComputeShader(); var N = isf.N; psi1 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); psi2 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); psi_mask = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RFloat); isf.InitializePsi(ref psi1, ref psi2); //for(int i = 0; i < 10; ++i) //{ //UpdatePsi(ref psi1, ref psi2); //} //fft.ExportComplex3D(psi1, "test/ink.psi1.json"); InitilizeParticles(); }
// TODO: 测试支持6个自由度的nozzle public void UpdateNozzles() { nozzle_dir.Normalize(); if (nozzle_dir == Vector3.up) { nozzle_dir.x += 0.01f; } nozzle_right = Vector3.Cross(nozzle_dir, Vector3.up); nozzle_right.Normalize(); Vector3 nozzle_up = Vector3.Cross(nozzle_dir, nozzle_right); nozzle_up.Normalize(); var mm = MinMaxVec.Create(); mm.Feed(nozzle_center + nozzle_dir * nozzle_length / 2); mm.Feed(nozzle_center - nozzle_dir * nozzle_length / 2); mm.Feed(nozzle_center + nozzle_right * nozzle_radius); mm.Feed(nozzle_center - nozzle_right * nozzle_radius); mm.Feed(nozzle_center + nozzle_up * nozzle_radius); mm.Feed(nozzle_center - nozzle_up * nozzle_radius); Vector3Int box, box_center; mm.GetRenderTextureBoundingBox(8, out box, out box_center); if (NozzleRT && NozzleRT.IsCreated()) { NozzleRT.Release(); } NozzleRT = FFT.CreateRenderTexture3D(box.x, box.y, box.z, RenderTextureFormat.RFloat); var topleft = ISFUtils.IntToFloat(box_center) - ISFUtils.IntToFloat(box) / 2; if (topleft.x < 0 || topleft.y < 0 || topleft.z < 0) { Debug.LogError("The bounding box excceeds"); } nozzle_topleft = topleft; CS.SetVector("nozzle_ralative_center", ISFUtils.IntToFloat(box) / 2); CS.SetVector("nozzle_center", ISFUtils.IntToFloat(box_center)); CS.SetFloat("nozzle_radius", nozzle_radius); CS.SetVector("nozzle_dir", nozzle_dir); CS.SetVector("nozzle_topleft", topleft); CS.SetFloat("nozzle_length", nozzle_length); CS.SetVector("nozzle_velocity", nozzle_velocity / isf.hbar); CS.SetVector("nozzle_right", nozzle_right); CS.SetVector("nozzle_up", nozzle_up); ISFSync(); CS.SetTexture(kernelCreateNozzleMask, "Nozzle", NozzleRT); DispatchCS(kernelCreateNozzleMask, true); //ExportDebugMask(); }
void PrepareNozzle() { fft = isf.fft; fft.init(); isf.InitComputeShader(); isf.InitISF(); InitComputeShader(); var N = isf.N; psi1 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); psi2 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); UpdateNozzles(); isf.InitializePsi(ref psi1, ref psi2); for (int i = 0; i < 10; ++i) { InitilizeNozzlePsi(ref psi1, ref psi2); } CreateShpereObstacleMask(); InitilizeParticles(); // fft.ExportFloat4_3D(particles.GetParticlePostion(), "test/part.init.json"); }
void ExportDebugMask() { if (!DebugRT || !DebugRT.IsCreated()) { var N = isf.N; var rtf4 = FFT.CreateRenderTexture3D(N[0], N[1], N[2]); DebugRT = DebugRT = rtf4; } CS.SetTexture(kernelZeroOutDebugOutput, "DebugOutput", DebugRT); DispatchCS(kernelZeroOutDebugOutput); CS.SetTexture(kernelBlitDebugMask, "Nozzle", NozzleRT); CS.SetTexture(kernelBlitDebugMask, "DebugOutput", DebugRT); DispatchCS(kernelBlitDebugMask); fft.ExportFloat4_3D(DebugRT, "test/isf.nozzle.mask.json"); }
public void RunMyTest() { Texture3D tex_psi1; Texture3D tex_psi2; var psi1 = fft.LoadJson3D("test/psi1.json", out tex_psi1); var psi2 = fft.LoadJson3D("test/psi2.json", out tex_psi2); UpdateNozzles(); // fft.ExportFloat1_3D(NozzleRT, "test/isf.nozzle.json"); var N = isf.N; // Nozzle mask // ===================== var rtf4 = FFT.CreateRenderTexture3D(N[0], N[1], N[2]); DebugRT = rtf4; CS.SetTexture(kernelZeroOutDebugOutput, "DebugOutput", rtf4); DispatchCS(kernelZeroOutDebugOutput); CS.SetTexture(kernelBlitDebugMask, "Nozzle", NozzleRT); CS.SetTexture(kernelBlitDebugMask, "DebugOutput", rtf4); DispatchCS(kernelBlitDebugMask); fft.ExportFloat4_3D(rtf4, "test/isf.nozzle.mask.json"); DispatchCS(kernelZeroOutDebugOutput); isf.InitializePsi(ref psi1, ref psi2); for (int i = 0; i < 10; ++i) { InitilizeNozzlePsi(ref psi1, ref psi2); } fft.ExportComplex3D(psi1, "test/isf.ini.ps1.json"); fft.ExportComplex3D(psi2, "test/isf.ini.ps2.json"); fft.ExportFloat4_3D(rtf4, "test/isf.phase.json"); // Application.Quit(0); }
void CreateShpereObstacleMask() { if (!CreateObstacle) { return; } var geo_sphere = GeometryGenerator.Sphere(ObstaleRadius, 32, 32); ObstacleChild = new GameObject("sphere"); ObstacleChild.transform.parent = this.gameObject.transform; var mesh_filter = ObstacleChild.AddComponent <MeshFilter>(); mesh_filter.mesh = geo_sphere; ObstacleChild.transform.position = ObstaclePosition; var render = ObstacleChild.AddComponent <MeshRenderer>(); render.material = new Material(Shader.Find("Specular")); int n = Mathf.CeilToInt(2 * ObstaleRadius); n = ISFUtils.CeilToMutiple(n, 8); // 保证 n 是 8 的倍数 ObstacleRoundedRadius = n; Vector3 relative_center = new Vector3(n / 2, n / 2, n / 2); ObstacleMask = FFT.CreateRenderTexture3D(n, n, n); CS.SetVector("nozzle_center", relative_center); CS.SetFloat("nozzle_radius", ObstaleRadius); CS.SetTexture(kernelCreateShpereObstacleMask, "Nozzle", ObstacleMask); DispatchCS(kernelCreateShpereObstacleMask, true, ObstacleMask); ObstacleTopLeft = ISFUtils.VecSubScalar(ObstaclePosition, n); for (int i = 1; i < 10; ++i) { UpdateObstacle(); } }
void TakeTestN(Vector3Int N) { isf.N = N; isf.InitISF(); psi1 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); psi2 = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); isf.InitializePsi(ref psi1, ref psi2); var watch = new System.Diagnostics.Stopwatch(); watch.Start(); for (int i = 0; i < 5; ++i) { isf.current_tick += 1; isf.ShroedingerIntegration(ref psi1, ref psi2); isf.Normalize(ref psi1, ref psi2); isf.PressureProject(ref psi1, ref psi2); fft.ExportComplex3D(psi1, null); Debug.Log(" At: " + i.ToString()); } watch.Stop(); BenchmarkSingleResult ben = new BenchmarkSingleResult(); ben.milli = watch.ElapsedMilliseconds / 5.0; ben.Nx = N.x; ben.Ny = N.y; ben.Nz = N.z; ben.scale = N.x * N.y * N.z; result.results.Add(ben); }
public void InitISF() { int[] res = GetGrids(); SchroedingerMul = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); PossionMul = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RFloat); Velocity = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.ARGBFloat); Divergence = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); TempRT = FFT.CreateRenderTexture3D(N[0], N[1], N[2], RenderTextureFormat.RGFloat); fft.OutputRT = TempRT; fft.SetN(N); ISFCS.SetVector("size", size); ISFCS.SetInts("res", res); ISFCS.SetFloat("hbar", hbar); ISFCS.SetFloat("dt", estimate_dt); ISFCS.SetTexture(kernelInitBuffer, "SchroedingerMul", SchroedingerMul); ISFCS.SetTexture(kernelInitBuffer, "PossionMul", PossionMul); DispatchISFCS(kernelInitBuffer); fft.fftshift(ref SchroedingerMul, ref TempRT); }