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(); }
// 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 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(); } }
public Vector3 GetGridSize() { return(ISFUtils.Div(size, ISFUtils.IntToFloat(N))); }