void ShowCellData(string cellName, FluidSimulator simulator, FluidCellIndex cellIndex, ref bool showCell, bool showOperationData) { return; int gridSize = simulator.fluidParameters.gridSize; if (cellIndex.x >= 0 && cellIndex.y >= 0 && cellIndex.z >= 0 && cellIndex.x < gridSize && cellIndex.y < gridSize && cellIndex.z < gridSize) { FluidCell cell = simulator.GetCell(cellIndex); showCell = EditorGUILayout.Foldout(showCell, string.Format("{0} {1}", cellName, cellIndex.ToString())); if (showCell) { EditorGUILayout.LabelField("Density", "" + cell.density); EditorGUILayout.LabelField("Velocity", "" + cell.velocity); EditorGUILayout.LabelField("Raw Divergence", "" + cell.rawDivergence); EditorGUILayout.LabelField("Relaxed Divergence", "" + cell.relaxedDivergence); if (showOperationData) { FluidCellOperationData operationData = simulator.GetCellOperationData(cellIndex); EditorGUILayout.LabelField("Advect Index Velocity", "" + operationData.advectIdVelocity.ToString()); EditorGUILayout.LabelField("Advect Past Index", "" + operationData.advectPastId.ToString()); EditorGUILayout.LabelField("Advect SamplePercentages", "" + operationData.advectSamplePercentages); } EditorGUILayout.Space(); } } }
protected override string initializeBuffers() { string result = null; cellBuffer1 = new FluidCell[fluidParameters.gridSize, fluidParameters.gridSize]; cellBuffer2 = new FluidCell[fluidParameters.gridSize, fluidParameters.gridSize]; externalAdditions = new FluidCell[fluidParameters.gridSize, fluidParameters.gridSize]; operationData = new FluidCellOperationData[fluidParameters.gridSize, fluidParameters.gridSize]; for (int i = 0; i < fluidParameters.gridSize; i++) { for (int j = 0; j < fluidParameters.gridSize; j++) { cellBuffer1[i, j] = new FluidCell(); cellBuffer2[i, j] = new FluidCell(); externalAdditions[i, j] = new FluidCell(); operationData[i, j] = new FluidCellOperationData(); } } inCells = cellBuffer1; outCells = cellBuffer2; return(result); }
public override void OnInspectorGUI() { FluidSimulator simulator = (FluidSimulator)target; GUILayout.BeginHorizontal(); if (GUILayout.Button("Reset")) { simulator.resetFluid = true; } if (GUILayout.Button(!simulator.pauseFluid ? "Pause" : "Resume")) { simulator.pauseFluid = !simulator.pauseFluid; } if (GUILayout.Button("Step")) { simulator.stepFluid = true; } GUILayout.EndHorizontal(); EditorGUILayout.LabelField("Family", simulator.FamilyName); // Default Inspector Rendering. base.OnInspectorGUI(); if (Application.isPlaying && simulator.isActiveAndEnabled) { EditorGUILayout.LabelField("Global Density", "" + simulator.GlobalDensity); // TODO Display cell and cell data in a layout //EditorGUILayout.LabelField("Selected Cell", simulator.SelectedCell.ToString()); EditorGUILayout.Space(); GUILayout.Label("Cell Data", EditorStyles.boldLabel); FluidCellIndex selectedIndex = simulator.SelectedCellIndex; FluidCellOperationData operationData = simulator.GetCellOperationData(selectedIndex); ShowCellData("Selected", simulator, selectedIndex, ref showSelected, true); ShowCellData("Left", simulator, operationData.leftId, ref showLeft, false); ShowCellData("Right", simulator, operationData.rightId, ref showRight, false); ShowCellData("Down", simulator, operationData.downId, ref showDown, false); ShowCellData("Up", simulator, operationData.upId, ref showUp, false); } }
protected override string initializeBuffers() { clampDataKernel = fluidComputer.FindKernel("ClampData"); applyExternalsKernel = fluidComputer.FindKernel("ApplyExternals"); diffuseKernel = fluidComputer.FindKernel("Diffuse"); advectKernel = fluidComputer.FindKernel("Advect"); computeDivergenceKernel = fluidComputer.FindKernel("ComputeDivergence"); relaxDivergenceKernel = fluidComputer.FindKernel("RelaxDivergence"); removeDivergenceKernel = fluidComputer.FindKernel("RemoveDivergence"); zeroedBoundariesKernel = fluidComputer.FindKernel("EmptyBoundaries"); // This assumes all kernels of compute shader use the same number of threads per group. threadsPerGroup = new uint[3]; fluidComputer.GetKernelThreadGroupSizes(applyExternalsKernel, out threadsPerGroup[0], out threadsPerGroup[1], out threadsPerGroup[2]); threadGroups = new int[] { (int)(fluidParameters.gridSize / threadsPerGroup[0]), (int)(fluidParameters.gridSize / threadsPerGroup[1]), (int)(fluidParameters.gridSize / threadsPerGroup[2]) }; // TODO When 3D is added this can be removed. threadGroups[2] = 1; fluidComputer.SetVector("threadsPerGroup", new Vector4(threadsPerGroup[0], threadsPerGroup[1], threadsPerGroup[2])); fluidComputer.SetVector("threadGroups", new Vector4(threadGroups[0], threadGroups[1], threadGroups[2], 1)); // TODO Move these to inspector as uneditable fields. Debug.Log("Threads per Group: " + threadsPerGroup[0] + " " + threadsPerGroup[1] + " " + threadsPerGroup[2]); Debug.Log("Thread Groups: " + threadGroups[0] + " " + threadGroups[1] + " " + threadGroups[2]); initialCells = new FluidCell[fluidParameters.gridSize, fluidParameters.gridSize]; externalAdditions = new FluidCell[fluidParameters.gridSize, fluidParameters.gridSize]; operationData = new FluidCellOperationData[fluidParameters.gridSize, fluidParameters.gridSize]; for (int j = 0; j < fluidParameters.gridSize; j++) { for (int i = 0; i < fluidParameters.gridSize; i++) { initialCells[j, i] = cellParameters.defaultCell; externalAdditions[j, i] = new FluidCell(); operationData[j, i] = new FluidCellOperationData(); } } int cellStride = Marshal.SizeOf(new FluidCell()); fluidBuffer1 = new ComputeBuffer(fluidParameters.gridSize * fluidParameters.gridSize, cellStride); fluidBuffer1.SetData(initialCells); fluidBuffer2 = new ComputeBuffer(fluidParameters.gridSize * fluidParameters.gridSize, cellStride); fluidBuffer2.SetData(initialCells); inFluidBuffer = fluidBuffer1; outFluidBuffer = fluidBuffer2; externalAdditionBuffer = new ComputeBuffer(fluidParameters.gridSize * fluidParameters.gridSize, cellStride); externalAdditionBuffer.SetData(initialCells); int operationDataStride = Marshal.SizeOf(new FluidCellOperationData()); operationDataBuffer = new ComputeBuffer(fluidParameters.gridSize * fluidParameters.gridSize, operationDataStride); operationDataBuffer.SetData(operationData); fluidComputer.SetFloat("cellSize", cellParameters.cellSize); fluidComputer.SetFloat("cellsPerSide", fluidParameters.gridSize); return(null); }