12 |
14 |
15 |
16 |
17 |
33 | Stable Fluids Demo
34 | Go back to the project page.
35 |
36 |
37 |
38 |
--------------------------------------------------------------------------------
/Assets/Marbling/Canvas/Canvas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!86 &8600000
4 | CustomRenderTexture:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_Name: Canvas
10 | m_ImageContentsHash:
11 | serializedVersion: 2
12 | Hash: 00000000000000000000000000000000
13 | m_IsAlphaChannelOptional: 0
14 | serializedVersion: 6
15 | m_Width: 1920
16 | m_Height: 1080
17 | m_AntiAliasing: 1
18 | m_MipCount: -1
19 | m_DepthStencilFormat: 0
20 | m_ColorFormat: 24
21 | m_MipMap: 0
22 | m_GenerateMips: 1
23 | m_SRGB: 0
24 | m_UseDynamicScale: 0
25 | m_UseDynamicScaleExplicit: 0
26 | m_BindMS: 0
27 | m_EnableCompatibleFormat: 1
28 | m_EnableRandomWrite: 0
29 | m_TextureSettings:
30 | serializedVersion: 2
31 | m_FilterMode: 1
32 | m_Aniso: 0
33 | m_MipBias: 0
34 | m_WrapU: 1
35 | m_WrapV: 1
36 | m_WrapW: 1
37 | m_Dimension: 2
38 | m_VolumeDepth: 1
39 | m_ShadowSamplingMode: 2
40 | m_Material: {fileID: 2100000, guid: 000a06032c91d4bf9964fa97db0bfd44, type: 2}
41 | m_InitSource: 0
42 | m_InitMaterial: {fileID: 2100000, guid: 000a06032c91d4bf9964fa97db0bfd44, type: 2}
43 | m_InitColor: {r: 1, g: 1, b: 1, a: 1}
44 | m_InitTexture: {fileID: 2800000, guid: ded36cca018f2e741aa6a4c55495a7f0, type: 3}
45 | m_UpdateMode: 2
46 | m_InitializationMode: 2
47 | m_UpdateZoneSpace: 0
48 | m_CurrentUpdateZoneSpace: 0
49 | m_UpdateZones: []
50 | m_UpdatePeriod: 0
51 | m_ShaderPass: 0
52 | m_CubemapFaceMask: 4294967295
53 | m_DoubleBuffered: 1
54 | m_WrapUpdateZones: 0
55 |
--------------------------------------------------------------------------------
/Assets/Common/UITK/DefaultSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 19101, guid: 0000000000000000e000000000000000, type: 0}
13 | m_Name: DefaultSettings
14 | m_EditorClassIdentifier:
15 | themeUss: {fileID: -4733365628477956816, guid: fc13e98ced2863a498ac563b785f68af, type: 3}
16 | m_DisableNoThemeWarning: 0
17 | m_TargetTexture: {fileID: 0}
18 | m_RenderMode: 0
19 | m_WorldSpaceLayer: 0
20 | m_ScaleMode: 1
21 | m_ReferenceSpritePixelsPerUnit: 100
22 | m_PixelsPerUnit: 100
23 | m_Scale: 1
24 | m_ReferenceDpi: 96
25 | m_FallbackDpi: 96
26 | m_ReferenceResolution: {x: 1200, y: 800}
27 | m_ScreenMatchMode: 0
28 | m_Match: 0
29 | m_SortingOrder: 0
30 | m_TargetDisplay: 0
31 | m_BindingLogLevel: 0
32 | m_ClearDepthStencil: 1
33 | m_ClearColor: 0
34 | m_ColorClearValue: {r: 0, g: 0, b: 0, a: 0}
35 | m_VertexBudget: 0
36 | m_DynamicAtlasSettings:
37 | m_MinAtlasSize: 64
38 | m_MaxAtlasSize: 4096
39 | m_MaxSubTextureSize: 64
40 | m_ActiveFilters: -1
41 | m_AtlasBlitShader: {fileID: 9101, guid: 0000000000000000f000000000000000, type: 0}
42 | m_RuntimeShader: {fileID: 9100, guid: 0000000000000000f000000000000000, type: 0}
43 | m_RuntimeWorldShader: {fileID: 9102, guid: 0000000000000000f000000000000000, type: 0}
44 | m_ICUDataAsset: {fileID: 0}
45 | forceGammaRendering: 0
46 | textSettings: {fileID: 0}
47 |
--------------------------------------------------------------------------------
/Assets/Marbling/Canvas/Canvas.shader:
--------------------------------------------------------------------------------
1 | Shader "StableFluids/Canvas"
2 | {
3 | Properties
4 | {
5 | _InjectTex("Color Injection", 2D) = "Black"{}
6 | _VelocityTex("Velocity Field", 2D) = "Black"{}
7 | }
8 |
9 | HLSLINCLUDE
10 |
11 | #include "../../Common/Shaders/CustomRenderTexture.hlsl"
12 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
13 |
14 | TEXTURE2D(_InjectTex);
15 | SAMPLER(sampler_InjectTex);
16 | float4 _InjectTex_TexelSize;
17 |
18 | TEXTURE2D(_VelocityTex);
19 | SAMPLER(sampler_VelocityTex);
20 | float4 _VelocityTex_TexelSize;
21 |
22 | half4 fragUpdate(CustomRenderTextureVaryings i) : SV_Target
23 | {
24 | float2 uv = i.globalTexcoord.xy;
25 |
26 | // Injection color sample
27 | float4 c = SAMPLE_TEXTURE2D(_InjectTex, sampler_InjectTex, uv);
28 |
29 | // Velocity field sample
30 | float2 v = SAMPLE_TEXTURE2D(_VelocityTex, sampler_VelocityTex, uv).xy;
31 |
32 | // Aspect ratio compensation (width-based normalization)
33 | v.y *= _VelocityTex_TexelSize.y * _VelocityTex_TexelSize.z;
34 |
35 | // Sample from advected position
36 | float2 uv_prev = uv - v * unity_DeltaTime.x;
37 | float4 c0 = SAMPLE_TEXTURE2D(_SelfTexture2D, sampler_SelfTexture2D, uv_prev);
38 |
39 | return float4(lerp(c0.rgb, c.rgb, c.a), 1);
40 | }
41 |
42 | ENDHLSL
43 |
44 | SubShader
45 | {
46 | Cull Off ZWrite Off ZTest Always
47 | Pass
48 | {
49 | Name "Update"
50 | HLSLPROGRAM
51 | #pragma vertex CustomRenderTextureVertexShader
52 | #pragma fragment fragUpdate
53 | ENDHLSL
54 | }
55 | }
56 | }
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!159 &1
4 | EditorSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 12
7 | m_SerializationMode: 2
8 | m_LineEndingsForNewScripts: 1
9 | m_DefaultBehaviorMode: 0
10 | m_PrefabRegularEnvironment: {fileID: 0}
11 | m_PrefabUIEnvironment: {fileID: 0}
12 | m_SpritePackerMode: 0
13 | m_SpritePackerCacheSize: 10
14 | m_SpritePackerPaddingPower: 1
15 | m_Bc7TextureCompressor: 0
16 | m_EtcTextureCompressorBehavior: 1
17 | m_EtcTextureFastCompressor: 1
18 | m_EtcTextureNormalCompressor: 2
19 | m_EtcTextureBestCompressor: 4
20 | m_ProjectGenerationIncludedExtensions: txt;xml;fnt;cd;asmdef;rsp;asmref
21 | m_ProjectGenerationRootNamespace:
22 | m_EnableTextureStreamingInEditMode: 1
23 | m_EnableTextureStreamingInPlayMode: 1
24 | m_EnableEditorAsyncCPUTextureLoading: 0
25 | m_AsyncShaderCompilation: 1
26 | m_PrefabModeAllowAutoSave: 1
27 | m_EnterPlayModeOptionsEnabled: 1
28 | m_EnterPlayModeOptions: 3
29 | m_GameObjectNamingDigits: 1
30 | m_GameObjectNamingScheme: 0
31 | m_AssetNamingUsesSpace: 1
32 | m_InspectorUseIMGUIDefaultInspector: 0
33 | m_UseLegacyProbeSampleCount: 0
34 | m_SerializeInlineMappingsOnOneLine: 1
35 | m_DisableCookiesInLightmapper: 0
36 | m_AssetPipelineMode: 1
37 | m_RefreshImportMode: 0
38 | m_CacheServerMode: 0
39 | m_CacheServerEndpoint:
40 | m_CacheServerNamespacePrefix: default
41 | m_CacheServerEnableDownload: 1
42 | m_CacheServerEnableUpload: 1
43 | m_CacheServerEnableAuth: 0
44 | m_CacheServerEnableTls: 0
45 | m_CacheServerValidationMode: 2
46 | m_CacheServerDownloadBatchSize: 128
47 | m_EnableEnlightenBakedGI: 0
48 |
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshAreas.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!126 &1
4 | NavMeshProjectSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 2
7 | areas:
8 | - name: Walkable
9 | cost: 1
10 | - name: Not Walkable
11 | cost: 1
12 | - name: Jump
13 | cost: 2
14 | - name:
15 | cost: 1
16 | - name:
17 | cost: 1
18 | - name:
19 | cost: 1
20 | - name:
21 | cost: 1
22 | - name:
23 | cost: 1
24 | - name:
25 | cost: 1
26 | - name:
27 | cost: 1
28 | - name:
29 | cost: 1
30 | - name:
31 | cost: 1
32 | - name:
33 | cost: 1
34 | - name:
35 | cost: 1
36 | - name:
37 | cost: 1
38 | - name:
39 | cost: 1
40 | - name:
41 | cost: 1
42 | - name:
43 | cost: 1
44 | - name:
45 | cost: 1
46 | - name:
47 | cost: 1
48 | - name:
49 | cost: 1
50 | - name:
51 | cost: 1
52 | - name:
53 | cost: 1
54 | - name:
55 | cost: 1
56 | - name:
57 | cost: 1
58 | - name:
59 | cost: 1
60 | - name:
61 | cost: 1
62 | - name:
63 | cost: 1
64 | - name:
65 | cost: 1
66 | - name:
67 | cost: 1
68 | - name:
69 | cost: 1
70 | - name:
71 | cost: 1
72 | m_LastAgentTypeID: -887442657
73 | m_Settings:
74 | - serializedVersion: 2
75 | agentTypeID: 0
76 | agentRadius: 0.5
77 | agentHeight: 2
78 | agentSlope: 45
79 | agentClimb: 0.75
80 | ledgeDropHeight: 0
81 | maxJumpAcrossDistance: 0
82 | minRegionArea: 2
83 | manualCellSize: 0
84 | cellSize: 0.16666667
85 | manualTileSize: 0
86 | tileSize: 256
87 | accuratePlacement: 0
88 | debug:
89 | m_Flags: 0
90 | m_SettingNames:
91 | - Humanoid
92 |
--------------------------------------------------------------------------------
/Assets/Marbling/Shaders/Marbling.shader:
--------------------------------------------------------------------------------
1 | Shader "Hidden/StableFluids/Marbling"
2 | {
3 | HLSLINCLUDE
4 |
5 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
6 | #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
7 | #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Input.hlsl"
8 |
9 | float2 _Origin;
10 | float _Falloff;
11 | float4 _Color;
12 | float2 _Force;
13 | float _Aspect;
14 |
15 | // Position-based amplitude with peak at _Origin and falloff with _Falloff
16 | float GetAmplitude(float2 uv)
17 | {
18 | float2 pos = uv - 0.5;
19 | pos.y /= _Aspect;
20 | return exp(-_Falloff * distance(_Origin, pos));
21 | }
22 |
23 | void VertexProcedural(uint vertexID : SV_VertexID,
24 | out float4 positionCS : SV_POSITION,
25 | out float2 uv : TEXCOORD0)
26 | {
27 | positionCS = GetFullScreenTriangleVertexPosition(vertexID);
28 | uv = GetFullScreenTriangleTexCoord(vertexID);
29 | }
30 |
31 | half4 FragmentInjection(float4 positionCS : SV_POSITION,
32 | float2 uv : TEXCOORD0) : SV_Target
33 | {
34 | float alpha = _Color.a * saturate(100 * GetAmplitude(uv));
35 | return float4(_Color.rgb, alpha);
36 | }
37 |
38 | half4 FragmentForce(float4 positionCS : SV_POSITION,
39 | float2 uv : TEXCOORD0) : SV_Target
40 | {
41 | return half4(_Force * GetAmplitude(uv), 0, 1);
42 | }
43 |
44 | ENDHLSL
45 |
46 | SubShader
47 | {
48 | Cull Off ZWrite Off ZTest Always
49 |
50 | // Pass 0: Color Injection
51 | Pass
52 | {
53 | HLSLPROGRAM
54 | #pragma vertex VertexProcedural
55 | #pragma fragment FragmentInjection
56 | ENDHLSL
57 | }
58 |
59 | // Pass 1: Force Application
60 | Pass
61 | {
62 | HLSLPROGRAM
63 | #pragma vertex VertexProcedural
64 | #pragma fragment FragmentForce
65 | ENDHLSL
66 | }
67 | }
68 | }
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!19 &1
4 | Physics2DSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 4
7 | m_Gravity: {x: 0, y: -9.81}
8 | m_DefaultMaterial: {fileID: 0}
9 | m_VelocityIterations: 8
10 | m_PositionIterations: 3
11 | m_VelocityThreshold: 1
12 | m_MaxLinearCorrection: 0.2
13 | m_MaxAngularCorrection: 8
14 | m_MaxTranslationSpeed: 100
15 | m_MaxRotationSpeed: 360
16 | m_BaumgarteScale: 0.2
17 | m_BaumgarteTimeOfImpactScale: 0.75
18 | m_TimeToSleep: 0.5
19 | m_LinearSleepTolerance: 0.01
20 | m_AngularSleepTolerance: 2
21 | m_DefaultContactOffset: 0.01
22 | m_JobOptions:
23 | serializedVersion: 2
24 | useMultithreading: 0
25 | useConsistencySorting: 0
26 | m_InterpolationPosesPerJob: 100
27 | m_NewContactsPerJob: 30
28 | m_CollideContactsPerJob: 100
29 | m_ClearFlagsPerJob: 200
30 | m_ClearBodyForcesPerJob: 200
31 | m_SyncDiscreteFixturesPerJob: 50
32 | m_SyncContinuousFixturesPerJob: 50
33 | m_FindNearestContactsPerJob: 100
34 | m_UpdateTriggerContactsPerJob: 100
35 | m_IslandSolverCostThreshold: 100
36 | m_IslandSolverBodyCostScale: 1
37 | m_IslandSolverContactCostScale: 10
38 | m_IslandSolverJointCostScale: 10
39 | m_IslandSolverBodiesPerJob: 50
40 | m_IslandSolverContactsPerJob: 50
41 | m_AutoSimulation: 1
42 | m_QueriesHitTriggers: 1
43 | m_QueriesStartInColliders: 1
44 | m_CallbacksOnDisable: 1
45 | m_ReuseCollisionCallbacks: 1
46 | m_AutoSyncTransforms: 0
47 | m_AlwaysShowColliders: 0
48 | m_ShowColliderSleep: 1
49 | m_ShowColliderContacts: 0
50 | m_ShowColliderAABB: 0
51 | m_ContactArrowScale: 0.2
52 | m_ColliderAwakeColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.7529412}
53 | m_ColliderAsleepColor: {r: 0.5686275, g: 0.95686275, b: 0.54509807, a: 0.36078432}
54 | m_ColliderContactColor: {r: 1, g: 0, b: 1, a: 0.6862745}
55 | m_ColliderAABBColor: {r: 1, g: 1, b: 0, a: 0.2509804}
56 | m_LayerCollisionMatrix: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
57 |
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!47 &1
4 | QualitySettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 5
7 | m_CurrentQuality: 0
8 | m_QualitySettings:
9 | - serializedVersion: 4
10 | name: High
11 | pixelLightCount: 2
12 | shadows: 2
13 | shadowResolution: 1
14 | shadowProjection: 1
15 | shadowCascades: 2
16 | shadowDistance: 40
17 | shadowNearPlaneOffset: 3
18 | shadowCascade2Split: 0.33333334
19 | shadowCascade4Split: {x: 0.06666667, y: 0.2, z: 0.46666667}
20 | shadowmaskMode: 1
21 | skinWeights: 2
22 | globalTextureMipmapLimit: 0
23 | textureMipmapLimitSettings: []
24 | anisotropicTextures: 1
25 | antiAliasing: 0
26 | softParticles: 0
27 | softVegetation: 1
28 | realtimeReflectionProbes: 1
29 | billboardsFaceCameraPosition: 1
30 | useLegacyDetailDistribution: 1
31 | adaptiveVsync: 0
32 | vSyncCount: 1
33 | realtimeGICPUUsage: 50
34 | adaptiveVsyncExtraA: 0
35 | adaptiveVsyncExtraB: 0
36 | lodBias: 1
37 | maximumLODLevel: 0
38 | enableLODCrossFade: 1
39 | streamingMipmapsActive: 0
40 | streamingMipmapsAddAllCameras: 1
41 | streamingMipmapsMemoryBudget: 512
42 | streamingMipmapsRenderersPerFrame: 512
43 | streamingMipmapsMaxLevelReduction: 2
44 | streamingMipmapsMaxFileIORequests: 1024
45 | particleRaycastBudget: 256
46 | asyncUploadTimeSlice: 2
47 | asyncUploadBufferSize: 16
48 | asyncUploadPersistentBuffer: 1
49 | resolutionScalingFixedDPIFactor: 1
50 | customRenderPipeline: {fileID: 0}
51 | terrainQualityOverrides: 0
52 | terrainPixelError: 1
53 | terrainDetailDensityScale: 1
54 | terrainBasemapDistance: 1000
55 | terrainDetailDistance: 80
56 | terrainTreeDistance: 5000
57 | terrainBillboardStart: 50
58 | terrainFadeLength: 5
59 | terrainMaxTrees: 50
60 | excludedTargetPlatforms: []
61 | m_TextureMipmapLimitGroupNames: []
62 | m_PerPlatformDefaultQuality:
63 | Android: 0
64 | GameCoreScarlett: 0
65 | GameCoreXboxOne: 0
66 | Lumin: 0
67 | Nintendo 3DS: 0
68 | Nintendo Switch: 0
69 | PS4: 0
70 | PS5: 0
71 | Stadia: 0
72 | Standalone: 0
73 | WebGL: 0
74 | Windows Store Apps: 0
75 | XboxOne: 0
76 | iPhone: 0
77 | tvOS: 0
78 |
--------------------------------------------------------------------------------
/Assets/Marbling/Canvas/Canvas.mat:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!21 &2100000
4 | Material:
5 | serializedVersion: 8
6 | m_ObjectHideFlags: 0
7 | m_CorrespondingSourceObject: {fileID: 0}
8 | m_PrefabInstance: {fileID: 0}
9 | m_PrefabAsset: {fileID: 0}
10 | m_Name: Canvas
11 | m_Shader: {fileID: 4800000, guid: bfaaf1fc05e084abc89dfb4591eec67c, type: 3}
12 | m_Parent: {fileID: 0}
13 | m_ModifiedSerializedProperties: 0
14 | m_ValidKeywords: []
15 | m_InvalidKeywords: []
16 | m_LightmapFlags: 4
17 | m_EnableInstancingVariants: 0
18 | m_DoubleSidedGI: 0
19 | m_CustomRenderQueue: -1
20 | stringTagMap: {}
21 | disabledShaderPasses: []
22 | m_LockedProperties:
23 | m_SavedProperties:
24 | serializedVersion: 3
25 | m_TexEnvs:
26 | - _AlphaTex:
27 | m_Texture: {fileID: 0}
28 | m_Scale: {x: 1, y: 1}
29 | m_Offset: {x: 0, y: 0}
30 | - _ColorTex:
31 | m_Texture: {fileID: 0}
32 | m_Scale: {x: 1, y: 1}
33 | m_Offset: {x: 0, y: 0}
34 | - _InitTex:
35 | m_Texture: {fileID: 0}
36 | m_Scale: {x: 1, y: 1}
37 | m_Offset: {x: 0, y: 0}
38 | - _InjectTex:
39 | m_Texture: {fileID: 8400000, guid: 9f6f8ff8db5154ec3a818fdf0a35f31a, type: 2}
40 | m_Scale: {x: 1, y: 1}
41 | m_Offset: {x: 0, y: 0}
42 | - _InputTex:
43 | m_Texture: {fileID: 0}
44 | m_Scale: {x: 1, y: 1}
45 | m_Offset: {x: 0, y: 0}
46 | - _MainTex:
47 | m_Texture: {fileID: 8400000, guid: 923813d341c134baf9b00384790ddcbe, type: 2}
48 | m_Scale: {x: 1, y: 1}
49 | m_Offset: {x: 0, y: 0}
50 | - _MaskTex:
51 | m_Texture: {fileID: 0}
52 | m_Scale: {x: 1, y: 1}
53 | m_Offset: {x: 0, y: 0}
54 | - _NormalMap:
55 | m_Texture: {fileID: 0}
56 | m_Scale: {x: 1, y: 1}
57 | m_Offset: {x: 0, y: 0}
58 | - _VelocityTex:
59 | m_Texture: {fileID: 8400000, guid: a637d858b4e8a43e6babfe9244a39176, type: 2}
60 | m_Scale: {x: 1, y: 1}
61 | m_Offset: {x: 0, y: 0}
62 | m_Ints:
63 | - _Seed: 1234
64 | m_Floats:
65 | - _Du: 1
66 | - _Dv: 0.4
67 | - _EnableExternalAlpha: 0
68 | - _Feed: 0.05
69 | - _Kill: 0.05
70 | - _Pop: 0.1
71 | - _ZWrite: 0
72 | m_Colors:
73 | - _Color: {r: 1, g: 1, b: 1, a: 1}
74 | - _RendererColor: {r: 1, g: 1, b: 1, a: 1}
75 | m_BuildTextureStacks: []
76 | m_AllowLocking: 1
77 |
--------------------------------------------------------------------------------
/Assets/StableFluids/FluidUtils.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEngine.Experimental.Rendering;
3 | using UnityEngine.Rendering;
4 |
5 | namespace StableFluids {
6 |
7 | static class RTUtil
8 | {
9 | public static RenderTexture Allocate
10 | (int width, int height, RenderTextureFormat format)
11 | {
12 | var rt = new RenderTexture(width, height, 0, format);
13 | rt.Create();
14 | return rt;
15 | }
16 |
17 | public static RenderTexture AllocateCompatible
18 | (int width, int height, GraphicsFormat requestedFormat)
19 | {
20 | var compatibleFormat = SystemInfo.GetCompatibleFormat(
21 | requestedFormat,
22 | GraphicsFormatUsage.Render
23 | );
24 |
25 | var descriptor = new RenderTextureDescriptor(width, height)
26 | {
27 | graphicsFormat = compatibleFormat,
28 | depthBufferBits = 0,
29 | msaaSamples = 1
30 | };
31 |
32 | var rt = new RenderTexture(descriptor);
33 | rt.Create();
34 | return rt;
35 | }
36 |
37 | public static RenderTexture AllocateRHalf(Vector2Int dims)
38 | => AllocateCompatible(dims.x, dims.y, GraphicsFormat.R16_SFloat);
39 |
40 | public static RenderTexture AllocateRGHalf(Vector2Int dims)
41 | => AllocateCompatible(dims.x, dims.y, GraphicsFormat.R16G16_SFloat);
42 |
43 | public static RenderTexture GetTemporaryCompatible(RenderTexture source)
44 | {
45 | var descriptor = source.descriptor;
46 | descriptor.graphicsFormat = SystemInfo.GetCompatibleFormat(
47 | descriptor.graphicsFormat,
48 | GraphicsFormatUsage.Render
49 | );
50 | return RenderTexture.GetTemporary(descriptor);
51 | }
52 | }
53 |
54 | static class ShaderIDs
55 | {
56 | public static readonly int TexWidth = Shader.PropertyToID("_TexWidth");
57 | public static readonly int TexHeight = Shader.PropertyToID("_TexHeight");
58 |
59 | public static readonly int X = Shader.PropertyToID("_X");
60 | public static readonly int B = Shader.PropertyToID("_B");
61 | public static readonly int Alpha = Shader.PropertyToID("_Alpha");
62 | public static readonly int Beta = Shader.PropertyToID("_Beta");
63 |
64 | public static readonly int MainTex = Shader.PropertyToID("_MainTex");
65 | public static readonly int W = Shader.PropertyToID("_W");
66 | public static readonly int P = Shader.PropertyToID("_P");
67 | public static readonly int ForceField = Shader.PropertyToID("_ForceField");
68 | }
69 |
70 | } // namespace StableFluids
71 |
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!30 &1
4 | GraphicsSettings:
5 | m_ObjectHideFlags: 0
6 | serializedVersion: 16
7 | m_Deferred:
8 | m_Mode: 1
9 | m_Shader: {fileID: 69, guid: 0000000000000000f000000000000000, type: 0}
10 | m_DeferredReflections:
11 | m_Mode: 1
12 | m_Shader: {fileID: 74, guid: 0000000000000000f000000000000000, type: 0}
13 | m_ScreenSpaceShadows:
14 | m_Mode: 1
15 | m_Shader: {fileID: 64, guid: 0000000000000000f000000000000000, type: 0}
16 | m_DepthNormals:
17 | m_Mode: 1
18 | m_Shader: {fileID: 62, guid: 0000000000000000f000000000000000, type: 0}
19 | m_MotionVectors:
20 | m_Mode: 1
21 | m_Shader: {fileID: 75, guid: 0000000000000000f000000000000000, type: 0}
22 | m_LightHalo:
23 | m_Mode: 1
24 | m_Shader: {fileID: 105, guid: 0000000000000000f000000000000000, type: 0}
25 | m_LensFlare:
26 | m_Mode: 1
27 | m_Shader: {fileID: 102, guid: 0000000000000000f000000000000000, type: 0}
28 | m_VideoShadersIncludeMode: 2
29 | m_AlwaysIncludedShaders:
30 | - {fileID: 7, guid: 0000000000000000f000000000000000, type: 0}
31 | - {fileID: 15104, guid: 0000000000000000f000000000000000, type: 0}
32 | - {fileID: 15105, guid: 0000000000000000f000000000000000, type: 0}
33 | - {fileID: 15106, guid: 0000000000000000f000000000000000, type: 0}
34 | - {fileID: 10753, guid: 0000000000000000f000000000000000, type: 0}
35 | - {fileID: 10770, guid: 0000000000000000f000000000000000, type: 0}
36 | m_PreloadedShaders: []
37 | m_PreloadShadersBatchTimeLimit: -1
38 | m_SpritesDefaultMaterial: {fileID: 10754, guid: 0000000000000000f000000000000000, type: 0}
39 | m_CustomRenderPipeline: {fileID: 11400000, guid: 20b57e50be50f4cf3bb2306d63c8e0e7, type: 2}
40 | m_TransparencySortMode: 0
41 | m_TransparencySortAxis: {x: 0, y: 0, z: 1}
42 | m_DefaultRenderingPath: 1
43 | m_DefaultMobileRenderingPath: 1
44 | m_TierSettings: []
45 | m_LightmapStripping: 0
46 | m_FogStripping: 0
47 | m_InstancingStripping: 0
48 | m_BrgStripping: 0
49 | m_LightmapKeepPlain: 1
50 | m_LightmapKeepDirCombined: 1
51 | m_LightmapKeepDynamicPlain: 1
52 | m_LightmapKeepDynamicDirCombined: 1
53 | m_LightmapKeepShadowMask: 1
54 | m_LightmapKeepSubtractive: 1
55 | m_FogKeepLinear: 1
56 | m_FogKeepExp: 1
57 | m_FogKeepExp2: 1
58 | m_AlbedoSwatchInfos: []
59 | m_RenderPipelineGlobalSettingsMap:
60 | UnityEngine.Rendering.Universal.UniversalRenderPipeline: {fileID: 11400000, guid: 27a43ffdced204282b6a42ae51c4b451, type: 2}
61 | m_LightsUseLinearIntensity: 1
62 | m_LightsUseColorTemperature: 1
63 | m_LogWhenShaderIsCompiled: 0
64 | m_LightProbeOutsideHullStrategy: 0
65 | m_CameraRelativeLightCulling: 0
66 | m_CameraRelativeShadowCulling: 0
67 |
--------------------------------------------------------------------------------
/Assets/Marbling/Scripts/MarblingController.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 |
3 | namespace StableFluids.Marbling {
4 |
5 | public sealed class MarblingController : MonoBehaviour
6 | {
7 | #region Public properties
8 |
9 | [field:SerializeField] public float PointForce { get; set; } = 300;
10 | [field:SerializeField] public float PointFalloff { get; set; } = 200;
11 |
12 | #endregion
13 |
14 | #region Editable attributes
15 |
16 | [SerializeField] RenderTexture _colorInjection = null;
17 | [SerializeField] RenderTexture _forceField = null;
18 |
19 | #endregion
20 |
21 | #region Project asset references
22 |
23 | [SerializeField, HideInInspector] Shader _shader = null;
24 |
25 | #endregion
26 |
27 | #region Private members
28 |
29 | MarblingInputHandler _input;
30 | Material _material;
31 |
32 | #endregion
33 |
34 | #region MonoBehaviour implementation
35 |
36 | void Start()
37 | {
38 | _input = new MarblingInputHandler(_colorInjection);
39 |
40 | _material = new Material(_shader);
41 | _material.SetFloat("_Aspect", (float)_forceField.width / _forceField.height);
42 |
43 | Graphics.Blit(Texture2D.blackTexture, _colorInjection);
44 | Graphics.Blit(Texture2D.blackTexture, _forceField);
45 | }
46 |
47 | void OnDestroy()
48 | => Destroy(_material);
49 |
50 | void Update()
51 | {
52 | _input.Update();
53 | UpdateColorInjection();
54 | UpdateForceField();
55 | }
56 |
57 | #endregion
58 |
59 | #region Update methods
60 |
61 | void UpdateColorInjection()
62 | {
63 | if (_input.RightPressed)
64 | {
65 | _material.color = Color.HSVToRGB(Time.time % 1, 1, 1);
66 | _material.SetVector("_Origin", _input.Position);
67 | _material.SetFloat("_Falloff", PointFalloff);
68 | Graphics.Blit(null, _colorInjection, _material, 0);
69 | }
70 | else
71 | {
72 | Graphics.Blit(Texture2D.blackTexture, _colorInjection);
73 | }
74 | }
75 |
76 | void UpdateForceField()
77 | {
78 | if (_input.RightPressed)
79 | {
80 | BlitToForceField(Random.insideUnitCircle * PointForce * 0.025f);
81 | }
82 | else if (_input.LeftPressed)
83 | {
84 | BlitToForceField(_input.Velocity * PointForce);
85 | }
86 | else
87 | {
88 | Graphics.Blit(Texture2D.blackTexture, _forceField);
89 | }
90 | }
91 |
92 | void BlitToForceField(Vector2 force)
93 | {
94 | _material.SetVector("_Origin", _input.Position);
95 | _material.SetFloat("_Falloff", PointFalloff);
96 | _material.SetVector("_Force", force);
97 | Graphics.Blit(null, _forceField, _material, 1);
98 | }
99 |
100 | #endregion
101 | }
102 |
103 | } // namespace StableFluids.Marbling
--------------------------------------------------------------------------------
/Assets/Common/URP/DefaultRenderer.asset:
--------------------------------------------------------------------------------
1 | %YAML 1.1
2 | %TAG !u! tag:unity3d.com,2011:
3 | --- !u!114 &11400000
4 | MonoBehaviour:
5 | m_ObjectHideFlags: 0
6 | m_CorrespondingSourceObject: {fileID: 0}
7 | m_PrefabInstance: {fileID: 0}
8 | m_PrefabAsset: {fileID: 0}
9 | m_GameObject: {fileID: 0}
10 | m_Enabled: 1
11 | m_EditorHideFlags: 0
12 | m_Script: {fileID: 11500000, guid: de640fe3d0db1804a85f9fc8f5cadab6, type: 3}
13 | m_Name: DefaultRenderer
14 | m_EditorClassIdentifier:
15 | debugShaders:
16 | debugReplacementPS: {fileID: 4800000, guid: cf852408f2e174538bcd9b7fda1c5ae7, type: 3}
17 | hdrDebugViewPS: {fileID: 4800000, guid: 573620ae32aec764abd4d728906d2587, type: 3}
18 | probeVolumeSamplingDebugComputeShader: {fileID: 7200000, guid: 53626a513ea68ce47b59dc1299fe3959, type: 3}
19 | probeVolumeResources:
20 | probeVolumeDebugShader: {fileID: 4800000, guid: e5c6678ed2aaa91408dd3df699057aae, type: 3}
21 | probeVolumeFragmentationDebugShader: {fileID: 4800000, guid: 03cfc4915c15d504a9ed85ecc404e607, type: 3}
22 | probeVolumeOffsetDebugShader: {fileID: 4800000, guid: 53a11f4ebaebf4049b3638ef78dc9664, type: 3}
23 | probeVolumeSamplingDebugShader: {fileID: 4800000, guid: 8f96cd657dc40064aa21efcc7e50a2e7, type: 3}
24 | probeSamplingDebugMesh: {fileID: -3555484719484374845, guid: 57d7c4c16e2765b47a4d2069b311bffe, type: 3}
25 | probeSamplingDebugTexture: {fileID: 2800000, guid: 24ec0e140fb444a44ab96ee80844e18e, type: 3}
26 | m_RendererFeatures: []
27 | m_RendererFeatureMap:
28 | m_UseNativeRenderPass: 0
29 | postProcessData: {fileID: 11400000, guid: 41439944d30ece34e96484bdb6645b55, type: 2}
30 | shaders:
31 | blitPS: {fileID: 4800000, guid: c17132b1f77d20942aa75f8429c0f8bc, type: 3}
32 | copyDepthPS: {fileID: 4800000, guid: d6dae50ee9e1bfa4db75f19f99355220, type: 3}
33 | screenSpaceShadowPS: {fileID: 0}
34 | samplingPS: {fileID: 4800000, guid: 04c410c9937594faa893a11dceb85f7e, type: 3}
35 | stencilDeferredPS: {fileID: 4800000, guid: e9155b26e1bc55942a41e518703fe304, type: 3}
36 | fallbackErrorPS: {fileID: 4800000, guid: e6e9a19c3678ded42a3bc431ebef7dbd, type: 3}
37 | fallbackLoadingPS: {fileID: 4800000, guid: 7f888aff2ac86494babad1c2c5daeee2, type: 3}
38 | materialErrorPS: {fileID: 0}
39 | coreBlitPS: {fileID: 4800000, guid: 93446b5c5339d4f00b85c159e1159b7c, type: 3}
40 | coreBlitColorAndDepthPS: {fileID: 4800000, guid: d104b2fc1ca6445babb8e90b0758136b, type: 3}
41 | blitHDROverlay: {fileID: 4800000, guid: a89bee29cffa951418fc1e2da94d1959, type: 3}
42 | cameraMotionVector: {fileID: 4800000, guid: c56b7e0d4c7cb484e959caeeedae9bbf, type: 3}
43 | screenSpaceLensFlare: {fileID: 4800000, guid: 701880fecb344ea4c9cd0db3407ab287, type: 3}
44 | dataDrivenLensFlare: {fileID: 4800000, guid: 6cda457ac28612740adb23da5d39ea92, type: 3}
45 | m_AssetVersion: 2
46 | m_OpaqueLayerMask:
47 | serializedVersion: 2
48 | m_Bits: 4294967295
49 | m_TransparentLayerMask:
50 | serializedVersion: 2
51 | m_Bits: 4294967295
52 | m_DefaultStencilState:
53 | overrideStencilState: 0
54 | stencilReference: 0
55 | stencilCompareFunction: 8
56 | passOperation: 2
57 | failOperation: 0
58 | zFailOperation: 0
59 | m_ShadowTransparentReceive: 1
60 | m_RenderingMode: 0
61 | m_DepthPrimingMode: 0
62 | m_CopyDepthMode: 1
63 | m_AccurateGbufferNormals: 0
64 | m_IntermediateTextureMode: 1
65 |
--------------------------------------------------------------------------------
/Assets/StableFluids/FluidSimulation.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using UnityEngine;
3 |
4 | namespace StableFluids {
5 |
6 | public sealed class FluidSimulation : IDisposable
7 | {
8 | #region Simulation parameters
9 |
10 | public float Viscosity { get; set; } = 1e-6f;
11 |
12 | #endregion
13 |
14 | #region Private members
15 |
16 | readonly Vector2Int _resolution;
17 | RenderTexture _v1, _v2, _v3, _p1, _p2, _divW;
18 | Material _mat;
19 |
20 | #endregion
21 |
22 | #region Constructor and Dispose
23 |
24 | public FluidSimulation(RenderTexture velocityField, Shader kernelsShader)
25 | {
26 | _v1 = velocityField;
27 | _resolution = new Vector2Int(_v1.width, _v1.height);
28 |
29 | _v2 = RTUtil.AllocateRGHalf(_resolution);
30 | _v3 = RTUtil.AllocateRGHalf(_resolution);
31 | _p1 = RTUtil.AllocateRHalf(_resolution);
32 | _p2 = RTUtil.AllocateRHalf(_resolution);
33 | _divW = RTUtil.AllocateRHalf(_resolution);
34 |
35 | _mat = new Material(kernelsShader);
36 | _mat.SetInt(ShaderIDs.TexWidth, _resolution.x);
37 | _mat.SetInt(ShaderIDs.TexHeight, _resolution.y);
38 | }
39 |
40 | public void Dispose()
41 | {
42 | UnityEngine.Object.Destroy(_v2);
43 | UnityEngine.Object.Destroy(_v3);
44 | UnityEngine.Object.Destroy(_p1);
45 | UnityEngine.Object.Destroy(_p2);
46 | UnityEngine.Object.Destroy(_divW);
47 | UnityEngine.Object.Destroy(_mat);
48 | }
49 |
50 | #endregion
51 |
52 | #region Simulation methods
53 |
54 | public void ClearVelocityField()
55 | {
56 | Graphics.Blit(Texture2D.blackTexture, _v1);
57 | }
58 |
59 | public void ApplyForceField(RenderTexture forceField)
60 | {
61 | _mat.SetTexture(ShaderIDs.ForceField, forceField);
62 | Graphics.Blit(_v2, _v3, _mat, 0);
63 | (_v2, _v3) = (_v3, _v2);
64 | }
65 |
66 | public void PreStep()
67 | {
68 | var dt = Time.deltaTime;
69 |
70 | // Advection U -> W (_v1 -> v2)
71 | Graphics.Blit(_v1, _v2, _mat, 1);
72 |
73 | // Diffusion via Jacobi on vector field (pass 4)
74 | var dx = 1.0f / _resolution.x;
75 | var dif_alpha = dx * dx / (Mathf.Max(Viscosity, 1e-12f) * Mathf.Max(dt, 1e-12f));
76 | var beta = 4 + dif_alpha;
77 |
78 | Graphics.CopyTexture(_v2, _v1); // B2_in = _v1
79 |
80 | // Iterate: X2_in/out over v2 <-> v3
81 | for (var i = 0; i < 20; i++)
82 | {
83 | _mat.SetTexture(ShaderIDs.X, _v2);
84 | _mat.SetTexture(ShaderIDs.B, _v1);
85 | _mat.SetFloat(ShaderIDs.Alpha, dif_alpha);
86 | _mat.SetFloat(ShaderIDs.Beta, beta);
87 | Graphics.Blit(_v2, _v3, _mat, 4);
88 | (_v2, _v3) = (_v3, _v2);
89 | }
90 | }
91 |
92 | public void PostStep()
93 | {
94 | // PSetup: compute divergence of W_in (v2) to divW and clear p1 (pass 2)
95 | _mat.SetTexture(ShaderIDs.MainTex, _v2);
96 | Graphics.Blit(_v2, _divW, _mat, 2);
97 | Graphics.Blit(Texture2D.blackTexture, _p1);
98 |
99 | // Jacobi on scalar field for pressure
100 | var dx = 1.0f / _resolution.x;
101 | _mat.SetFloat(ShaderIDs.Alpha, -dx * dx);
102 | _mat.SetFloat(ShaderIDs.Beta, 4);
103 | for (var i = 0; i < 20; i++)
104 | {
105 | _mat.SetTexture(ShaderIDs.X, _p1);
106 | _mat.SetTexture(ShaderIDs.B, _divW);
107 | Graphics.Blit(_p1, _p2, _mat, 3);
108 | (_p1, _p2) = (_p2, _p1);
109 | }
110 |
111 | // PFinish (pass 5): subtract pressure gradient to get divergence-free field U_out (_v1)
112 | _mat.SetTexture(ShaderIDs.W, _v2);
113 | _mat.SetTexture(ShaderIDs.P, _p1);
114 | Graphics.Blit(_v2, _v1, _mat, 5);
115 | }
116 |
117 | #endregion
118 | }
119 |
120 | } // namespace StableFluids
121 |
--------------------------------------------------------------------------------
/ProjectSettings/SceneTemplateSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "templatePinStates": [],
3 | "dependencyTypeInfos": [
4 | {
5 | "userAdded": false,
6 | "type": "UnityEngine.AnimationClip",
7 | "defaultInstantiationMode": 0
8 | },
9 | {
10 | "userAdded": false,
11 | "type": "UnityEditor.Animations.AnimatorController",
12 | "defaultInstantiationMode": 0
13 | },
14 | {
15 | "userAdded": false,
16 | "type": "UnityEngine.AnimatorOverrideController",
17 | "defaultInstantiationMode": 0
18 | },
19 | {
20 | "userAdded": false,
21 | "type": "UnityEditor.Audio.AudioMixerController",
22 | "defaultInstantiationMode": 0
23 | },
24 | {
25 | "userAdded": false,
26 | "type": "UnityEngine.ComputeShader",
27 | "defaultInstantiationMode": 1
28 | },
29 | {
30 | "userAdded": false,
31 | "type": "UnityEngine.Cubemap",
32 | "defaultInstantiationMode": 0
33 | },
34 | {
35 | "userAdded": false,
36 | "type": "UnityEngine.GameObject",
37 | "defaultInstantiationMode": 0
38 | },
39 | {
40 | "userAdded": false,
41 | "type": "UnityEditor.LightingDataAsset",
42 | "defaultInstantiationMode": 0
43 | },
44 | {
45 | "userAdded": false,
46 | "type": "UnityEngine.LightingSettings",
47 | "defaultInstantiationMode": 0
48 | },
49 | {
50 | "userAdded": false,
51 | "type": "UnityEngine.Material",
52 | "defaultInstantiationMode": 0
53 | },
54 | {
55 | "userAdded": false,
56 | "type": "UnityEditor.MonoScript",
57 | "defaultInstantiationMode": 1
58 | },
59 | {
60 | "userAdded": false,
61 | "type": "UnityEngine.PhysicMaterial",
62 | "defaultInstantiationMode": 0
63 | },
64 | {
65 | "userAdded": false,
66 | "type": "UnityEngine.PhysicsMaterial",
67 | "defaultInstantiationMode": 0
68 | },
69 | {
70 | "userAdded": false,
71 | "type": "UnityEngine.PhysicsMaterial2D",
72 | "defaultInstantiationMode": 0
73 | },
74 | {
75 | "userAdded": false,
76 | "type": "UnityEngine.Rendering.PostProcessing.PostProcessProfile",
77 | "defaultInstantiationMode": 0
78 | },
79 | {
80 | "userAdded": false,
81 | "type": "UnityEngine.Rendering.PostProcessing.PostProcessResources",
82 | "defaultInstantiationMode": 0
83 | },
84 | {
85 | "userAdded": false,
86 | "type": "UnityEngine.Rendering.VolumeProfile",
87 | "defaultInstantiationMode": 0
88 | },
89 | {
90 | "userAdded": false,
91 | "type": "UnityEditor.SceneAsset",
92 | "defaultInstantiationMode": 1
93 | },
94 | {
95 | "userAdded": false,
96 | "type": "UnityEngine.Shader",
97 | "defaultInstantiationMode": 1
98 | },
99 | {
100 | "userAdded": false,
101 | "type": "UnityEngine.ShaderVariantCollection",
102 | "defaultInstantiationMode": 1
103 | },
104 | {
105 | "userAdded": false,
106 | "type": "UnityEngine.Texture",
107 | "defaultInstantiationMode": 0
108 | },
109 | {
110 | "userAdded": false,
111 | "type": "UnityEngine.Texture2D",
112 | "defaultInstantiationMode": 0
113 | },
114 | {
115 | "userAdded": false,
116 | "type": "UnityEngine.Timeline.TimelineAsset",
117 | "defaultInstantiationMode": 0
118 | }
119 | ],
120 | "defaultDependencyTypeInfo": {
121 | "userAdded": false,
122 | "type": "