diff --git a/Assets/DataStructure/Data/AbstractGridData.cs b/Assets/DataStructure/Data/AbstractGridData.cs index ebca41b..bb24e12 100644 --- a/Assets/DataStructure/Data/AbstractGridData.cs +++ b/Assets/DataStructure/Data/AbstractGridData.cs @@ -4,7 +4,7 @@ namespace SimDataStructure.Data { - // Data for whole grid (one instance per grid) + // Data for whole grid (one instance per grid). [Serializable] public abstract class AbstractGridData { diff --git a/Assets/DataStructure/Data/BufferGridData.cs b/Assets/DataStructure/Data/BufferGridData.cs index 3012c7b..ca9237d 100644 --- a/Assets/DataStructure/Data/BufferGridData.cs +++ b/Assets/DataStructure/Data/BufferGridData.cs @@ -14,11 +14,7 @@ public class BufferGridData : AbstractGridData private ComputeBuffer computeBuffer; - public BufferGridData() - { - } - - public void InitBuffer(int width, int height, int contentSize = sizeof(float) * 4) + public BufferGridData(int width, int height, int contentSize = sizeof(float) * 4) { this.width = width; this.height = height; @@ -50,5 +46,20 @@ public override void Release() this.computeBuffer = null; } } + + public int GetWidth() + { + return this.width; + } + + public int GetHeight() + { + return this.height; + } + + public int GetContentSize() + { + return this.contentSize; + } } } \ No newline at end of file diff --git a/Assets/DataStructure/Data/TextureGridData.cs b/Assets/DataStructure/Data/TextureGridData.cs index c1598ff..dc00389 100644 --- a/Assets/DataStructure/Data/TextureGridData.cs +++ b/Assets/DataStructure/Data/TextureGridData.cs @@ -14,13 +14,13 @@ public class TextureGridData : AbstractGridData public TextureGridData(int resolution, RenderTextureFormat format, FilterMode filterMode = FilterMode.Point) { this.resolution = resolution; - this.renderTexture = this.CreateTexture(format, filterMode); + this.renderTexture = this.createTexture(format, filterMode); } // Return a copy of the texture public RenderTexture GetData() { - RenderTexture copy = CreateTexture(this.renderTexture.format, this.renderTexture.filterMode); + RenderTexture copy = createTexture(this.renderTexture.format, this.renderTexture.filterMode); Graphics.Blit(this.renderTexture, copy); @@ -41,7 +41,7 @@ public override void Release() } } - public RenderTexture CreateTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point) + private RenderTexture createTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point) { RenderTexture rt = new RenderTexture(resolution, resolution, 24, format); rt.filterMode = filterMode; diff --git a/Assets/DataStructure/Scripts/DataStructure.cs b/Assets/DataStructure/Scripts/DataStructure.cs index 433657b..99943fc 100644 --- a/Assets/DataStructure/Scripts/DataStructure.cs +++ b/Assets/DataStructure/Scripts/DataStructure.cs @@ -153,10 +153,11 @@ private void sendRequestedData(IReadDataStructure reader) for (int e = 0; e < reader.ReadDataNames.Count; e++) { string dataName = reader.ReadDataNames[e]; + if (cachedData.ContainsKey(dataName)) { data.Add(cachedData[dataName]); - print("A system has requested data that has already been requested. Please avoid this by making sure data is used by only one system per tick."); + // print("A system has requested data that has already been requested. Please avoid this by making sure data is used by only one system per tick."); } else { @@ -170,7 +171,7 @@ private void sendRequestedData(IReadDataStructure reader) reader.recieveData(data); } - // Reads the new data from a writing class and writes it to the data structure + // Recieves the new data from a writing class and writes it to the data structure // TODO: Make it only write ONCE, not once for every data name. It'll override it anyways so it is currently wasting writes just for them to be overriden private void recieveDataFromWriter(IWriteDataStructure writer) { diff --git a/Assets/Scenes/Testing.unity b/Assets/Scenes/Testing.unity index d29f31e..757fcaf 100644 --- a/Assets/Scenes/Testing.unity +++ b/Assets/Scenes/Testing.unity @@ -153,7 +153,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 638825940} - m_RootOrder: 0 + m_RootOrder: 1 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &282096877 MonoBehaviour: @@ -172,6 +172,53 @@ MonoBehaviour: - {fileID: 11400000, guid: 36751346e59f29e409b3874b0603be45, type: 2} - {fileID: 11400000, guid: a8156ca0bf27694458adbefdae0a24e1, type: 2} - {fileID: 11400000, guid: 5d57596dba7f4ac4582655b943c0fedc, type: 2} +--- !u!1 &582991950 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 582991951} + - component: {fileID: 582991952} + m_Layer: 0 + m_Name: Systems Manager + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &582991951 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 582991950} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 638825940} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &582991952 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 582991950} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 36b1f1d4fbabb9444bb1305de913d34a, type: 3} + m_Name: + m_EditorClassIdentifier: + tickableObjects: + - {fileID: 282096875} + - {fileID: 1364809028} --- !u!1 &638825939 GameObject: m_ObjectHideFlags: 0 @@ -200,11 +247,80 @@ Transform: m_LocalScale: {x: 1, y: 1, z: 1} m_ConstrainProportionsScale: 0 m_Children: + - {fileID: 582991951} - {fileID: 282096876} - {fileID: 1597987556} + - {fileID: 1364809027} m_Father: {fileID: 0} m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!1001 &1364809026 +PrefabInstance: + m_ObjectHideFlags: 0 + serializedVersion: 2 + m_Modification: + m_TransformParent: {fileID: 638825940} + m_Modifications: + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_RootOrder + value: 3 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalPosition.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalPosition.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalPosition.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalRotation.w + value: 1 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalRotation.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalRotation.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalRotation.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalEulerAnglesHint.x + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalEulerAnglesHint.y + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_LocalEulerAnglesHint.z + value: 0 + objectReference: {fileID: 0} + - target: {fileID: 6456605025595122871, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + propertyPath: m_Name + value: Water Simulation + objectReference: {fileID: 0} + m_RemovedComponents: [] + m_SourcePrefab: {fileID: 100100000, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} +--- !u!4 &1364809027 stripped +Transform: + m_CorrespondingSourceObject: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + m_PrefabInstance: {fileID: 1364809026} + m_PrefabAsset: {fileID: 0} +--- !u!1 &1364809028 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 6456605025595122871, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} + m_PrefabInstance: {fileID: 1364809026} + m_PrefabAsset: {fileID: 0} --- !u!1 &1597987555 GameObject: m_ObjectHideFlags: 0 @@ -235,7 +351,7 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 638825940} - m_RootOrder: 1 + m_RootOrder: 2 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!114 &1597987557 MonoBehaviour: diff --git a/Assets/SystemsManagement/Managers/SystemsManager.cs b/Assets/SystemsManagement/Managers/SystemsManager.cs index 84906eb..8ac27a0 100644 --- a/Assets/SystemsManagement/Managers/SystemsManager.cs +++ b/Assets/SystemsManagement/Managers/SystemsManager.cs @@ -8,16 +8,31 @@ namespace Managers { public class SystemsManager : MonoBehaviour { public static SystemsManager Instance { get; private set; } - public List tickableSystems = new List(); + public List tickableObjects = new List(); + private List tickableSystems = new List(); + + private List toTick = new List(); + public void Awake() { Instance = this; } + public void Start() { + for (int i = 0; i < tickableObjects.Count; i++) { + ITickableSystem system = tickableObjects[i].GetComponent(); + if (system == null) { + Debug.LogError("SystemsManager: GameObject " + tickableObjects[i].name + " does not have a component that implements ITickableSystem"); + } + + tickableSystems.Add(system); + } + } + public void FixedUpdate() { float deltaT = Time.fixedDeltaTime; - List toTick = new List(tickableSystems); + toTick.Clear(); // Figure out which systems need to be ticked this frame int currentTick = Time.frameCount; diff --git a/Assets/WaterSimulation/Prefabs/Fluid Sim.prefab b/Assets/WaterSimulation/Prefabs/Fluid Sim.prefab deleted file mode 100644 index eef701f..0000000 --- a/Assets/WaterSimulation/Prefabs/Fluid Sim.prefab +++ /dev/null @@ -1,166 +0,0 @@ -%YAML 1.1 -%TAG !u! tag:unity3d.com,2011: ---- !u!1 &2566442593908158340 -GameObject: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - serializedVersion: 6 - m_Component: - - component: {fileID: 2566442593908158339} - - component: {fileID: 2566442593908158338} - - component: {fileID: 2566442593908158341} - - component: {fileID: 2566442593908158337} - - component: {fileID: 1258558761060615783} - m_Layer: 0 - m_Name: Fluid Sim - m_TagString: MainCamera - m_Icon: {fileID: 0} - m_NavMeshLayer: 0 - m_StaticEditorFlags: 0 - m_IsActive: 1 ---- !u!4 &2566442593908158339 -Transform: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2566442593908158340} - m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} - m_LocalPosition: {x: 0, y: 1, z: -10} - m_LocalScale: {x: 1, y: 1, z: 1} - m_ConstrainProportionsScale: 0 - m_Children: [] - m_Father: {fileID: 0} - m_RootOrder: 0 - m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} ---- !u!20 &2566442593908158338 -Camera: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2566442593908158340} - m_Enabled: 1 - serializedVersion: 2 - m_ClearFlags: 1 - m_BackGroundColor: {r: 0.19215687, g: 0.3019608, b: 0.4745098, a: 0} - m_projectionMatrixMode: 1 - m_GateFitMode: 2 - m_FOVAxisMode: 0 - m_SensorSize: {x: 36, y: 24} - m_LensShift: {x: 0, y: 0} - m_FocalLength: 50 - m_NormalizedViewPortRect: - serializedVersion: 2 - x: 0 - y: 0 - width: 1 - height: 1 - near clip plane: 0.3 - far clip plane: 1000 - field of view: 60 - orthographic: 0 - orthographic size: 5 - m_Depth: -1 - m_CullingMask: - serializedVersion: 2 - m_Bits: 4294967295 - m_RenderingPath: -1 - m_TargetTexture: {fileID: 0} - m_TargetDisplay: 0 - m_TargetEye: 3 - m_HDR: 1 - m_AllowMSAA: 1 - m_AllowDynamicResolution: 0 - m_ForceIntoRT: 0 - m_OcclusionCulling: 1 - m_StereoConvergence: 10 - m_StereoSeparation: 0.022 ---- !u!81 &2566442593908158341 -AudioListener: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2566442593908158340} - m_Enabled: 1 ---- !u!114 &2566442593908158337 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2566442593908158340} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 48fceb84824d81c41a085bda774e1106, type: 3} - m_Name: - m_EditorClassIdentifier: - computeShader: {fileID: 0} - result: {fileID: 0} - waterMap: {fileID: 0} - newWaterMap: {fileID: 0} - flowMap: {fileID: 0} - newFlowMap: {fileID: 0} - velocityMap: {fileID: 0} - newVelocityMap: {fileID: 0} - soilUseMap: {fileID: 0} - newSoilUseMap: {fileID: 0} - textureToDraw: 1 - heightmap: {fileID: 2800000, guid: 90c5f3e74c9152949879f49f22891720, type: 3} - resolution: 1024 - externalResolution: 256 - timeStep: 0.1 - epsilon: 0.00001 - waterDensity: 1 - gravitationAcceleration: 9.81 - cellHeight: 1 - cellArea: 1 - diffuseAlpha: 1 - evaporationConstant: 0.01 - heightmapMultiplier: 1 - flowDamping: 0 - viscosity: 10.5 - iterations: 2 - enableWaterFlux: 1 - enableFlow: 1 - enableHeight: 1 - enableVelocity: 1 - enableVelocityDiffusion: 1 - sourceIsMouse: 1 - sourceRadius: 0.008 - sourceAmount: 1 - sourcePosition: {x: 0, y: 0} - soilDataMap: {fileID: 0} - soilEvaporationConstant: 0.001 - soilDiffusionConstant: 0.1 - soilAbsorptionMultiplier: 1 - soilUseMultiplier: 1 - soilReleaseMultiplier: 1 - soilReleaseThreshold: 0.5 - soilReleaseSurfaceThreshold: 0.1 - enableSoilUse: 1 - enableSoilAbsorption: 1 - enableSoilRelease: 1 - enableSoilEvaporation: 1 - enableSoilFlow: 1 - showDebugTextures: 1 ---- !u!114 &1258558761060615783 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 2566442593908158340} - m_Enabled: 0 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 132d26542ffa23e4aad4f1de5260d8bc, type: 3} - m_Name: - m_EditorClassIdentifier: - waterMaterial: {fileID: 2100000, guid: fb1cf0736cbe0c5409618cd1641a8e96, type: 2} - sun: {fileID: 0} - meshSize: {x: 512, y: 512} - meshHeight: 128 - fluidSim: {fileID: 2566442593908158337} diff --git a/Assets/WaterSimulation/Prefabs/Water Simulation.prefab b/Assets/WaterSimulation/Prefabs/Water Simulation.prefab new file mode 100644 index 0000000..6de9eed --- /dev/null +++ b/Assets/WaterSimulation/Prefabs/Water Simulation.prefab @@ -0,0 +1,97 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!1 &6456605025595122871 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 6456605025595122869} + - component: {fileID: 6456605025595122868} + m_Layer: 0 + m_Name: Water Simulation + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!4 &6456605025595122869 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6456605025595122871} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 0} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} +--- !u!114 &6456605025595122868 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 6456605025595122871} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 2423190bdc600854ab8fb8c7150a0c41, type: 3} + m_Name: + m_EditorClassIdentifier: + computeShader: {fileID: 7200000, guid: 1c3b445941b32804dbb9b992ea49c70f, type: 3} + result: {fileID: 0} + waterMap: {fileID: 0} + newWaterMap: {fileID: 0} + flowMap: {fileID: 0} + newFlowMap: {fileID: 0} + velocityMap: {fileID: 0} + newVelocityMap: {fileID: 0} + soilUseMap: {fileID: 0} + newSoilUseMap: {fileID: 0} + saturationMap: {fileID: 0} + newSaturationMap: {fileID: 0} + textureToDraw: 0 + heightmap: {fileID: 2800000, guid: 90c5f3e74c9152949879f49f22891720, type: 3} + resolution: 1024 + externalResolution: 256 + timeStep: 0.1 + epsilon: 0.00001 + waterDensity: 1 + gravitationAcceleration: 9.81 + cellHeight: 1 + cellArea: 1 + diffuseAlpha: 1 + evaporationConstant: 0.01 + heightmapMultiplier: 1 + flowDamping: 0 + viscosity: 10.5 + iterations: 2 + enableWaterFlux: 1 + enableFlow: 1 + enableHeight: 1 + enableVelocity: 1 + enableVelocityDiffusion: 1 + sourceIsMouse: 0 + sourceRadius: 0.008 + sourceAmount: 1 + sourcePosition: {x: 0, y: 0} + soilDataMap: {fileID: 2800000, guid: 90c5f3e74c9152949879f49f22891720, type: 3} + soilEvaporationConstant: 0.001 + soilDiffusionConstant: 0.1 + soilAbsorptionMultiplier: 1 + soilUseMultiplier: 1 + soilReleaseMultiplier: 1 + soilReleaseThreshold: 0.5 + soilReleaseSurfaceThreshold: 0.1 + enableSoilUse: 1 + enableSoilAbsorption: 1 + enableSoilRelease: 1 + enableSoilEvaporation: 1 + enableSoilDiffusion: 1 + showDebugTextures: 1 diff --git a/Assets/WaterSimulation/Prefabs/Fluid Sim.prefab.meta b/Assets/WaterSimulation/Prefabs/Water Simulation.prefab.meta similarity index 74% rename from Assets/WaterSimulation/Prefabs/Fluid Sim.prefab.meta rename to Assets/WaterSimulation/Prefabs/Water Simulation.prefab.meta index 75149ed..0b68d57 100644 --- a/Assets/WaterSimulation/Prefabs/Fluid Sim.prefab.meta +++ b/Assets/WaterSimulation/Prefabs/Water Simulation.prefab.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc +guid: 2203fda62e853af4a909b4477943d7e9 PrefabImporter: externalObjects: {} userData: diff --git a/Assets/WaterSimulation/Scenes/SurfaceWaterSim.unity b/Assets/WaterSimulation/Scenes/SurfaceWaterSim.unity index 2c05583..ca5a394 100644 --- a/Assets/WaterSimulation/Scenes/SurfaceWaterSim.unity +++ b/Assets/WaterSimulation/Scenes/SurfaceWaterSim.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 0} - m_IndirectSpecularColor: {r: 0.18028378, g: 0.22571412, b: 0.30692285, a: 1} + m_IndirectSpecularColor: {r: 0.18028334, g: 0.22571328, b: 0.3069217, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -215,106 +215,62 @@ Transform: m_ConstrainProportionsScale: 0 m_Children: [] m_Father: {fileID: 0} - m_RootOrder: 1 + m_RootOrder: 0 m_LocalEulerAnglesHint: {x: 50, y: -30, z: 0} ---- !u!1001 &2566442594288933606 +--- !u!1001 &6456605024960930406 PrefabInstance: m_ObjectHideFlags: 0 serializedVersion: 2 m_Modification: m_TransformParent: {fileID: 0} m_Modifications: - - target: {fileID: 1258558761060615783, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: sun - value: - objectReference: {fileID: 2051415026} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: heightmap - value: - objectReference: {fileID: 2800000, guid: 90c5f3e74c9152949879f49f22891720, type: 3} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilDataMap - value: - objectReference: {fileID: 2800000, guid: aa4df7f740d550a4ea09c6611eb97ab2, type: 3} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: computeShader - value: - objectReference: {fileID: 7200000, guid: 1c3b445941b32804dbb9b992ea49c70f, type: 3} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilEnableFlow - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilEnableRelease - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: evaporationConstant - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilEnableAbsorption - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilEnableSaturation - value: 0 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilDiffusionConstant - value: 1 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158337, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} - propertyPath: soilEvaporationConstant - value: 0.000001 - objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_RootOrder - value: 0 + value: 1 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalPosition.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalPosition.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalPosition.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalRotation.w value: 1 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalRotation.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalRotation.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalRotation.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalEulerAnglesHint.x value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalEulerAnglesHint.y value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158339, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122869, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_LocalEulerAnglesHint.z value: 0 objectReference: {fileID: 0} - - target: {fileID: 2566442593908158340, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + - target: {fileID: 6456605025595122871, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} propertyPath: m_Name - value: Fluid Sim + value: Water Simulation objectReference: {fileID: 0} m_RemovedComponents: [] - m_SourcePrefab: {fileID: 100100000, guid: 99e93d985e2bc8b4bbf7a7a4fdf85ebc, type: 3} + m_SourcePrefab: {fileID: 100100000, guid: 2203fda62e853af4a909b4477943d7e9, type: 3} diff --git a/Assets/WaterSimulation/Scripts/WaterSimulation.cs b/Assets/WaterSimulation/Scripts/WaterSimulation.cs index 9bab414..b7dbdd0 100644 --- a/Assets/WaterSimulation/Scripts/WaterSimulation.cs +++ b/Assets/WaterSimulation/Scripts/WaterSimulation.cs @@ -18,12 +18,14 @@ public class WaterSimulation : MonoBehaviour, ITickableSystem, IReadDataStructur [Header("Render Textures")] // Surface Water public RenderTexture result; - public TextureGridData waterMap; - public TextureGridData newWaterMap; - public TextureGridData flowMap; - public TextureGridData newFlowMap; - public TextureGridData velocityMap; - public TextureGridData newVelocityMap; + + public Dictionary gridDatas = new Dictionary(); + public RenderTexture waterMap; + public RenderTexture newWaterMap; + public RenderTexture flowMap; + public RenderTexture newFlowMap; + public RenderTexture velocityMap; + public RenderTexture newVelocityMap; // Soil Water [Space(10)] @@ -111,7 +113,7 @@ public class WaterSimulation : MonoBehaviour, ITickableSystem, IReadDataStructur // [Header("Data Structure")] public int ReadLevel { get { return 0; } } // The grid level to receive data from - private List _readDataNames = new List() { "heightmap", "waterHeight", "waterFlow", "waterVelocity", "soilSaturation", "soilUse" }; // The names of the data to receive from the data structure + private List _readDataNames = new List() {"waterHeight", "waterFlow", "waterVelocity", "soilSaturation", "soilUse" }; // The names of the data to receive from the data structure public List ReadDataNames { get { return _readDataNames; } } public int WriteLevel { get { return 0; } } // The grid level to write data to @@ -143,17 +145,28 @@ private void Awake() sourcePosition = new Vector2(0.5f, 0.5f); // Create render textures - result = CreateTexture(RenderTextureFormat.ARGBHalf, FilterMode.Bilinear); - waterMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); - newWaterMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); - flowMap = CreateTexture(RenderTextureFormat.ARGBHalf, FilterMode.Bilinear); - newFlowMap = CreateTexture(RenderTextureFormat.ARGBHalf, FilterMode.Bilinear); - velocityMap = CreateTexture(RenderTextureFormat.RGFloat, FilterMode.Bilinear); - newVelocityMap = CreateTexture(RenderTextureFormat.RGFloat, FilterMode.Bilinear); - saturationMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); - newSaturationMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); - soilUseMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); - newSoilUseMap = CreateTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); + result = createTexture(RenderTextureFormat.ARGBHalf, FilterMode.Bilinear); + + // Create data + gridDatas.Add("waterHeight", new TextureGridData(resolution, RenderTextureFormat.RFloat, FilterMode.Bilinear)); + waterMap = gridDatas["waterHeight"].GetData(); + newWaterMap = createTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); + + gridDatas.Add("waterFlow", new TextureGridData(resolution, RenderTextureFormat.ARGBHalf, FilterMode.Bilinear)); + flowMap = gridDatas["waterFlow"].GetData(); + newFlowMap = createTexture(RenderTextureFormat.ARGBHalf, FilterMode.Bilinear); + + gridDatas.Add("waterVelocity", new TextureGridData(resolution, RenderTextureFormat.RGFloat, FilterMode.Bilinear)); + velocityMap = gridDatas["waterVelocity"].GetData(); + newVelocityMap = createTexture(RenderTextureFormat.RGFloat, FilterMode.Bilinear); + + gridDatas.Add("soilSaturation", new TextureGridData(resolution, RenderTextureFormat.RFloat, FilterMode.Bilinear)); + saturationMap = gridDatas["soilSaturation"].GetData(); + newSaturationMap = createTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); + + gridDatas.Add("soilUse", new TextureGridData(resolution, RenderTextureFormat.RFloat, FilterMode.Bilinear)); + soilUseMap = gridDatas["soilUse"].GetData(); + newSoilUseMap = createTexture(RenderTextureFormat.RFloat, FilterMode.Bilinear); // Set shader variables computeShader.SetFloat("waterDensity", waterDensity); @@ -202,6 +215,7 @@ private void Awake() // Initialize shader textures dispatchSize = Mathf.CeilToInt(resolution / 8); + DispatchCompute(kernel_reset); } @@ -238,41 +252,70 @@ public void EndTick(float deltaTime) #region Data Structure public void recieveData(List data) { - // List _readDataNames = new List() { "heightmap", "waterHeight", "waterFlow", "waterVelocity", "soilSaturation", "soilUse" }; - for (int i = 0; i < ReadDataNames.Count; i++) { - if (data[i] != null && data is BufferGridData) + AbstractGridData abstractData = data[i]; + TextureGridData dat = abstractData is TextureGridData ? (TextureGridData)abstractData : null; + + if (dat == null) + continue; + + switch (ReadDataNames[i]) + { + case "waterHeight": + waterMap = dat.GetData(); + break; + case "waterFlow": + flowMap = dat.GetData(); + break; + case "waterVelocity": + velocityMap = dat.GetData(); + break; + case "soilSaturation": + saturationMap = dat.GetData(); + break; + case "soilUse": + soilUseMap = dat.GetData(); + break; + } + } + } + + public List writeData() + { + List toWrite = new List(); + + for (int i = 0; i < WriteDataNames.Count; i++) + { + TextureGridData data = gridDatas[WriteDataNames[i]]; + + if (data != null && data is TextureGridData) { - BufferGridData buffer = (BufferGridData)data[i]; - switch (ReadDataNames[i]) + switch(WriteDataNames[i]) { - case "heightmap": - heightmap = data[i].getTexture(); - break; + Set these to theit new--- versions case "waterHeight": - waterMap = data[i].getTexture(); + data.SetData(newWaterMap); break; case "waterFlow": - flowMap = data[i].getTexture(); + data.SetData(flowMap); break; case "waterVelocity": - velocityMap = data[i].getTexture(); + data.SetData(velocityMap); break; case "soilSaturation": - saturationMap = data[i].getTexture(); + data.SetData(saturationMap); break; case "soilUse": - soilUseMap = data[i].getTexture(); + data.SetData(soilUseMap); break; } + + toWrite.Add(data); } } - } - public List writeData() - { - return null; + return toWrite; } #endregion @@ -425,15 +468,15 @@ private void surfaceWaterVelocity() #endregion #region Utilities - private RenderTexture CreateTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point) + private RenderTexture createTexture(RenderTextureFormat format, FilterMode filterMode = FilterMode.Point) { - RenderTexture dataTex = new RenderTexture(resolution, resolution, 24, format); - dataTex.filterMode = filterMode; - dataTex.wrapMode = TextureWrapMode.Clamp; - dataTex.enableRandomWrite = true; - dataTex.Create(); + RenderTexture rt = new RenderTexture(resolution, resolution, 24, format); + rt.filterMode = filterMode; + rt.wrapMode = TextureWrapMode.Clamp; + rt.enableRandomWrite = true; + rt.Create(); - return dataTex; + return rt; } private void DispatchCompute(int kernel)