├── .gitignore ├── Assets ├── LiquidSimulator.meta └── LiquidSimulator │ ├── Examples.meta │ ├── Examples │ ├── Demo.unity │ ├── Demo.unity.meta │ ├── Materials.meta │ ├── Materials │ │ ├── Render.meta │ │ ├── Render │ │ │ ├── caustic.mat │ │ │ ├── caustic.mat.meta │ │ │ ├── water.mat │ │ │ ├── water.mat.meta │ │ │ ├── waterbody.mat │ │ │ └── waterbody.mat.meta │ │ ├── sky.mat │ │ └── sky.mat.meta │ ├── Meshes.meta │ ├── Meshes │ │ ├── Materials.meta │ │ ├── Materials │ │ │ ├── 01 - Default 1.mat │ │ │ ├── 01 - Default 1.mat.meta │ │ │ ├── 01 - Default 2.mat │ │ │ ├── 01 - Default 2.mat.meta │ │ │ ├── 01 - Default.mat │ │ │ ├── 01 - Default.mat.meta │ │ │ ├── No Name.mat │ │ │ └── No Name.mat.meta │ │ ├── pool.FBX │ │ └── pool.FBX.meta │ ├── Textures.meta │ └── Textures │ │ ├── a.png │ │ ├── a.png.meta │ │ ├── b.png │ │ ├── b.png.meta │ │ ├── skyB.cubemap │ │ ├── skyB.cubemap.meta │ │ ├── skyB0.png │ │ ├── skyB0.png.meta │ │ ├── skyB1.png │ │ ├── skyB1.png.meta │ │ ├── skyB2.png │ │ ├── skyB2.png.meta │ │ ├── skyB3.png │ │ ├── skyB3.png.meta │ │ ├── skyB4.png │ │ ├── skyB4.png.meta │ │ ├── skyB5.png │ │ ├── skyB5.png.meta │ │ ├── tile02.jpg │ │ ├── tile02.jpg.meta │ │ ├── tile02b_NRM.png │ │ ├── tile02b_NRM.png.meta │ │ ├── tile02b_SPEC.png │ │ └── tile02b_SPEC.png.meta │ ├── Scripts.meta │ ├── Scripts │ ├── CausticRenderer.cs │ ├── CausticRenderer.cs.meta │ ├── LiquidSampleCamera.cs │ ├── LiquidSampleCamera.cs.meta │ ├── LiquidSampleObject.cs │ ├── LiquidSampleObject.cs.meta │ ├── LiquidSimulator.cs │ ├── LiquidSimulator.cs.meta │ ├── ReflectCamera.cs │ ├── ReflectCamera.cs.meta │ ├── SunLight.cs │ ├── SunLight.cs.meta │ ├── Test.meta │ ├── Test │ │ ├── CameraController.cs │ │ ├── CameraController.cs.meta │ │ ├── DragController.cs │ │ └── DragController.cs.meta │ ├── Utils.cs │ ├── Utils.cs.meta │ ├── WaterVolumeLightRenderer.cs │ └── WaterVolumeLightRenderer.cs.meta │ ├── Shaders.meta │ └── Shaders │ ├── BlinnPhongUnderWater.shader │ ├── BlinnPhongUnderWater.shader.meta │ ├── Caustic.shader │ ├── Caustic.shader.meta │ ├── Force.shader │ ├── Force.shader.meta │ ├── NormalGen.shader │ ├── NormalGen.shader.meta │ ├── ShadowMapRender.shader │ ├── ShadowMapRender.shader.meta │ ├── Test.meta │ ├── Test │ ├── TestGizmos.shader │ └── TestGizmos.shader.meta │ ├── Utils.cginc │ ├── Utils.cginc.meta │ ├── Water.shader │ ├── Water.shader.meta │ ├── WaterBody.shader │ ├── WaterBody.shader.meta │ ├── WaveEquationGen.shader │ └── WaveEquationGen.shader.meta ├── Doc ├── preview.gif ├── preview1.PNG ├── preview1.gif ├── preview2.PNG ├── preview3.PNG └── preview4.PNG ├── ProjectSettings ├── AudioManager.asset ├── ClusterInputManager.asset ├── DynamicsManager.asset ├── EditorBuildSettings.asset ├── EditorSettings.asset ├── GraphicsSettings.asset ├── InputManager.asset ├── NavMeshAreas.asset ├── NetworkManager.asset ├── Physics2DSettings.asset ├── ProjectSettings.asset ├── ProjectVersion.txt ├── QualitySettings.asset ├── TagManager.asset ├── TimeManager.asset ├── UnityAdsSettings.asset └── UnityConnectSettings.asset └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | /[Ll]ibrary/ 2 | /[Tt]emp/ 3 | /[Oo]bj/ 4 | /[Bb]uild/ 5 | /[Bb]uilds/ 6 | /Assets/AssetStoreTools* 7 | 8 | # Visual Studio 2015 cache directory 9 | /.vs/ 10 | 11 | # Autogenerated VS/MD/Consulo solution and project files 12 | ExportedObj/ 13 | .consulo/ 14 | *.csproj 15 | *.unityproj 16 | *.sln 17 | *.suo 18 | *.tmp 19 | *.user 20 | *.userprefs 21 | *.pidb 22 | *.booproj 23 | *.svd 24 | *.pdb 25 | 26 | # Unity3D generated meta files 27 | *.pidb.meta 28 | 29 | # Unity3D Generated File On Crash Reports 30 | sysinfo.txt 31 | 32 | # Builds 33 | *.apk 34 | *.unitypackage 35 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b4c3df1ce5e3a5c44a4ea4bed6c8bca8 3 | folderAsset: yes 4 | timeCreated: 1536213086 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8bed67ff6a17f3f46a2b73d47ebeff45 3 | folderAsset: yes 4 | timeCreated: 1536213113 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Demo.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Demo.unity -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Demo.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 946a445546d13bc408bd196ba29edb97 3 | timeCreated: 1538646224 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 83684e4128848cf4f8133452b723d8c0 3 | folderAsset: yes 4 | timeCreated: 1538655060 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 8d4f5168628a3044e893b46bec905238 3 | folderAsset: yes 4 | timeCreated: 1538725433 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/caustic.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Materials/Render/caustic.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/caustic.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3d263f8fb6f9eb642a597e066a0a7816 3 | timeCreated: 1537929586 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/water.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Materials/Render/water.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/water.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bdd53b2f44426344e865e93d740f597a 3 | timeCreated: 1537451931 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/waterbody.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Materials/Render/waterbody.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/Render/waterbody.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ef749dbb844d346439912447af67d339 3 | timeCreated: 1537929586 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/sky.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Materials/sky.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Materials/sky.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4e03d407210bd3e4f861c1ca29c7004b 3 | timeCreated: 1538655097 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 873677b47a48db64da672c6b8aa5183d 3 | folderAsset: yes 4 | timeCreated: 1536157620 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 1da935aef68c98d43b0fdcce4b2f9dc9 3 | folderAsset: yes 4 | timeCreated: 1536157624 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 1.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 1.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 1.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db493ee83abcedf46b06675027c87621 3 | timeCreated: 1538645238 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 2.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 2.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default 2.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f4a6823818e18244e95a80d2e1775199 3 | timeCreated: 1538645238 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/01 - Default.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: ad7b4906b5c6b284787a3d89affab478 3 | timeCreated: 1538645238 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/No Name.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Meshes/Materials/No Name.mat -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/Materials/No Name.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e547b5b05e4fa6f4fba2cbb3730fbc34 3 | timeCreated: 1536157624 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 2100000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/pool.FBX: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Meshes/pool.FBX -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Meshes/pool.FBX.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cc0550c4633a7144b8ecd34cca04a3f3 3 | timeCreated: 1538645238 4 | licenseType: Pro 5 | ModelImporter: 6 | serializedVersion: 19 7 | fileIDToRecycleName: 8 | 100000: Box001 9 | 100002: Box002 10 | 100004: Circle001 11 | 100006: //RootNode 12 | 400000: Box001 13 | 400002: Box002 14 | 400004: Circle001 15 | 400006: //RootNode 16 | 2300000: Box001 17 | 2300002: Box002 18 | 2300004: Circle001 19 | 3300000: Box001 20 | 3300002: Box002 21 | 3300004: Circle001 22 | 4300000: Box001 23 | 4300002: Box002 24 | 4300004: Circle001 25 | 9500000: //RootNode 26 | materials: 27 | importMaterials: 1 28 | materialName: 0 29 | materialSearch: 1 30 | animations: 31 | legacyGenerateAnimations: 4 32 | bakeSimulation: 0 33 | resampleCurves: 1 34 | optimizeGameObjects: 0 35 | motionNodeName: 36 | rigImportErrors: 37 | rigImportWarnings: 38 | animationImportErrors: 39 | animationImportWarnings: 40 | animationRetargetingWarnings: 41 | animationDoRetargetingWarnings: 0 42 | animationCompression: 1 43 | animationRotationError: 0.5 44 | animationPositionError: 0.5 45 | animationScaleError: 0.5 46 | animationWrapMode: 0 47 | extraExposedTransformPaths: [] 48 | clipAnimations: [] 49 | isReadable: 1 50 | meshes: 51 | lODScreenPercentages: [] 52 | globalScale: 1 53 | meshCompression: 0 54 | addColliders: 0 55 | importBlendShapes: 1 56 | swapUVChannels: 0 57 | generateSecondaryUV: 0 58 | useFileUnits: 1 59 | optimizeMeshForGPU: 1 60 | keepQuads: 0 61 | weldVertices: 1 62 | secondaryUVAngleDistortion: 8 63 | secondaryUVAreaDistortion: 15.000001 64 | secondaryUVHardAngle: 88 65 | secondaryUVPackMargin: 4 66 | useFileScale: 1 67 | tangentSpace: 68 | normalSmoothAngle: 60 69 | normalImportMode: 0 70 | tangentImportMode: 3 71 | importAnimation: 1 72 | copyAvatar: 0 73 | humanDescription: 74 | serializedVersion: 2 75 | human: [] 76 | skeleton: [] 77 | armTwist: 0.5 78 | foreArmTwist: 0.5 79 | upperLegTwist: 0.5 80 | legTwist: 0.5 81 | armStretch: 0.05 82 | legStretch: 0.05 83 | feetSpacing: 0 84 | rootMotionBoneName: 85 | rootMotionBoneRotation: {x: 0, y: 0, z: 0, w: 1} 86 | hasTranslationDoF: 0 87 | hasExtraRoot: 0 88 | skeletonHasParents: 1 89 | lastHumanDescriptionAvatarSource: {instanceID: 0} 90 | animationType: 2 91 | humanoidOversampling: 1 92 | additionalBone: 0 93 | userData: 94 | assetBundleName: 95 | assetBundleVariant: 96 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 536707d9bb30c544c8e6ccf7b9089bc5 3 | folderAsset: yes 4 | timeCreated: 1538655045 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/a.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/a.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/a.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: f8f8b8cd349185442894ea6e31a9f86d 3 | timeCreated: 1538654759 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/b.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/b.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/b.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 24d7a76a65179b64e8c0bf1db989ae07 3 | timeCreated: 1538654759 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB.cubemap: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB.cubemap -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB.cubemap.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a88e3a4000fba1f41924fbc040749527 3 | timeCreated: 1538655069 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | mainObjectFileID: 8900000 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB0.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB0.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB0.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 284936ea9b3636b4ca9f02b8f514f7bf 3 | timeCreated: 1538655049 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB1.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB1.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 921d49a212c48af4b895b7455ebfdb1b 3 | timeCreated: 1538655050 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB2.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB2.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6bb166fcf55e1794bbca8dfbf8070e10 3 | timeCreated: 1538655049 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB3.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB3.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 3af75d2d3f26ee247a755b0c1a6b07ee 3 | timeCreated: 1538655049 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB4.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB4.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e93eff13a998a8b4d9ec55d8838d3a04 3 | timeCreated: 1538655050 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/skyB5.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/skyB5.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: aecea124048194644b4daf6c4c7480b8 3 | timeCreated: 1538655050 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/tile02.jpg -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02.jpg.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a6052cfafdbb0a4489ce374b8cef24bd 3 | timeCreated: 1538646033 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02b_NRM.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/tile02b_NRM.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02b_NRM.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: cb63ef2b5810ab34fa34ced9f00e7419 3 | timeCreated: 1538659980 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 0 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 1 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | - buildTarget: Standalone 62 | maxTextureSize: 2048 63 | textureFormat: -1 64 | textureCompression: 1 65 | compressionQuality: 50 66 | crunchedCompression: 0 67 | allowsAlphaSplitting: 0 68 | overridden: 0 69 | - buildTarget: Android 70 | maxTextureSize: 2048 71 | textureFormat: -1 72 | textureCompression: 1 73 | compressionQuality: 50 74 | crunchedCompression: 0 75 | allowsAlphaSplitting: 0 76 | overridden: 0 77 | - buildTarget: WebGL 78 | maxTextureSize: 2048 79 | textureFormat: -1 80 | textureCompression: 1 81 | compressionQuality: 50 82 | crunchedCompression: 0 83 | allowsAlphaSplitting: 0 84 | overridden: 0 85 | spriteSheet: 86 | serializedVersion: 2 87 | sprites: [] 88 | outline: [] 89 | spritePackingTag: 90 | userData: 91 | assetBundleName: 92 | assetBundleVariant: 93 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02b_SPEC.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Assets/LiquidSimulator/Examples/Textures/tile02b_SPEC.png -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Examples/Textures/tile02b_SPEC.png.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4dec9adf964e6d04cb0e595ad58db8ae 3 | timeCreated: 1538659978 4 | licenseType: Pro 5 | TextureImporter: 6 | fileIDToRecycleName: {} 7 | serializedVersion: 4 8 | mipmaps: 9 | mipMapMode: 0 10 | enableMipMap: 1 11 | sRGBTexture: 1 12 | linearTexture: 0 13 | fadeOut: 0 14 | borderMipMap: 0 15 | mipMapFadeDistanceStart: 1 16 | mipMapFadeDistanceEnd: 3 17 | bumpmap: 18 | convertToNormalMap: 0 19 | externalNormalMap: 0 20 | heightScale: 0.25 21 | normalMapFilter: 0 22 | isReadable: 0 23 | grayScaleToAlpha: 0 24 | generateCubemap: 6 25 | cubemapConvolution: 0 26 | seamlessCubemap: 0 27 | textureFormat: 1 28 | maxTextureSize: 2048 29 | textureSettings: 30 | filterMode: -1 31 | aniso: -1 32 | mipBias: -1 33 | wrapMode: -1 34 | nPOTScale: 1 35 | lightmap: 0 36 | compressionQuality: 50 37 | spriteMode: 0 38 | spriteExtrude: 1 39 | spriteMeshType: 1 40 | alignment: 0 41 | spritePivot: {x: 0.5, y: 0.5} 42 | spriteBorder: {x: 0, y: 0, z: 0, w: 0} 43 | spritePixelsToUnits: 100 44 | alphaUsage: 1 45 | alphaIsTransparency: 0 46 | spriteTessellationDetail: -1 47 | textureType: 0 48 | textureShape: 1 49 | maxTextureSizeSet: 0 50 | compressionQualitySet: 0 51 | textureFormatSet: 0 52 | platformSettings: 53 | - buildTarget: DefaultTexturePlatform 54 | maxTextureSize: 2048 55 | textureFormat: -1 56 | textureCompression: 1 57 | compressionQuality: 50 58 | crunchedCompression: 0 59 | allowsAlphaSplitting: 0 60 | overridden: 0 61 | spriteSheet: 62 | serializedVersion: 2 63 | sprites: [] 64 | outline: [] 65 | spritePackingTag: 66 | userData: 67 | assetBundleName: 68 | assetBundleVariant: 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 87d5a4f532f43504da1406be16d7a183 3 | folderAsset: yes 4 | timeCreated: 1536213095 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/CausticRenderer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | using UnityEngine.Rendering; 5 | 6 | 7 | /// 8 | /// 焦散渲染器 9 | /// 10 | public class CausticRenderer : MonoBehaviour 11 | { 12 | /// 13 | /// 网格单元格大小 14 | /// 15 | public float geometryCellSize; 16 | /// 17 | /// 焦散宽度 18 | /// 19 | public float width; 20 | /// 21 | /// 焦散长度 22 | /// 23 | public float length; 24 | /// 25 | /// 焦散强度 26 | /// 27 | public float causticIntensity = 1.0f; 28 | /// 29 | /// 深度范围(该参数目前实现比较简单,只是简单的传入世界空间的最小高度和有效高度范围,以计算焦散的有效高度范围(线性插值),暂时没有实现复杂的范围计算效果) 30 | /// 31 | public Vector2 causticDepthRange; 32 | 33 | public Material material; 34 | 35 | private Mesh m_Mesh; 36 | 37 | private Camera m_Camera; 38 | 39 | private RenderTexture m_RenderTexture; 40 | private CommandBuffer m_CommandBuffer; 41 | 42 | void Start() 43 | { 44 | m_Camera = gameObject.AddComponent(); 45 | m_Camera.aspect = width / length; 46 | m_Camera.backgroundColor = Color.black; 47 | //m_Camera.enabled = false; 48 | m_Camera.depth = 0; 49 | m_Camera.farClipPlane = 5; 50 | m_Camera.nearClipPlane = -5; 51 | m_Camera.orthographic = true; 52 | m_Camera.orthographicSize = length * 0.5f; 53 | //m_Camera.clearFlags = CameraClearFlags.SolidColor; 54 | m_Camera.clearFlags = CameraClearFlags.SolidColor; 55 | m_Camera.allowHDR = false; 56 | m_Camera.backgroundColor = Color.black; 57 | m_Camera.cullingMask = 0; 58 | 59 | m_RenderTexture = RenderTexture.GetTemporary(512, 512, 16); 60 | m_RenderTexture.name = "[Caustic]"; 61 | m_Camera.targetTexture = m_RenderTexture; 62 | 63 | m_CommandBuffer = new CommandBuffer(); 64 | m_CommandBuffer.name = "[Caustic CB]"; 65 | m_Camera.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque, m_CommandBuffer); 66 | 67 | m_Mesh = Utils.GenerateLiquidMesh(width, length, geometryCellSize); 68 | 69 | } 70 | 71 | void OnPostRender() 72 | { 73 | //绘制焦散mesh 74 | Matrix4x4 trs = Matrix4x4.TRS(transform.position, Quaternion.identity, Vector3.one); 75 | m_CommandBuffer.Clear(); 76 | m_CommandBuffer.ClearRenderTarget(true, true, Color.black); 77 | 78 | m_CommandBuffer.SetRenderTarget(m_RenderTexture); 79 | 80 | m_CommandBuffer.DrawMesh(m_Mesh, trs, material); 81 | 82 | Vector4 plane = new Vector4(0, 1, 0, Vector3.Dot(new Vector3(0, 1, 0), transform.position)); 83 | Vector4 range = new Vector4(transform.position.x, transform.position.z, width * 0.5f, length * 0.5f); 84 | 85 | Shader.SetGlobalVector("_CausticPlane", plane); 86 | Shader.SetGlobalVector("_CausticRange", range); 87 | Shader.SetGlobalTexture("_CausticMap", m_RenderTexture); 88 | Shader.SetGlobalVector("_CausticDepthRange", causticDepthRange); 89 | Shader.SetGlobalFloat("_CausticIntensity", causticIntensity); 90 | } 91 | 92 | void OnDestroy() 93 | { 94 | if (m_RenderTexture) 95 | Destroy(m_RenderTexture); 96 | if (m_Mesh) 97 | Destroy(m_Mesh); 98 | if (m_CommandBuffer != null) 99 | { 100 | m_CommandBuffer.Release(); 101 | m_CommandBuffer = null; 102 | } 103 | } 104 | 105 | void OnDrawGizmosSelected() 106 | { 107 | Utils.DrawWireCube(transform.position, transform.eulerAngles.y, width, length, 0, 0, 108 | Color.blue); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/CausticRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 587ea3e9e49f8884089a08795f506ad7 3 | timeCreated: 1536582952 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSampleCamera.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using UnityEngine.Rendering; 3 | using System.Collections; 4 | 5 | /// 6 | /// 液体高度采样相机 7 | /// 8 | public class LiquidSampleCamera : MonoBehaviour 9 | { 10 | private Camera m_Camera; 11 | 12 | private RenderTexture m_CurTexture; 13 | private RenderTexture m_PreTexture; 14 | private RenderTexture m_HeightMap; 15 | private RenderTexture m_NormalMap; 16 | 17 | private Material m_WaveEquationMat; 18 | private Material m_NormalGenerateMat; 19 | 20 | private Vector4 m_WaveParams; 21 | 22 | private CommandBuffer m_CommandBuffer; 23 | private Material m_ForceMaterial; 24 | 25 | public void DrawRenderer(Renderer renderer) 26 | { 27 | if (!renderer) 28 | return; 29 | if (IsBoundsInCamera(renderer.bounds, m_Camera)) 30 | m_CommandBuffer.DrawRenderer(renderer, m_ForceMaterial); 31 | } 32 | 33 | public void ForceDrawMesh(Mesh mesh, Matrix4x4 matrix) 34 | { 35 | if (!mesh) 36 | return; 37 | //if (IsBoundsInCamera(mesh.bounds, m_Camera)) 38 | m_CommandBuffer.DrawMesh(mesh, matrix, m_ForceMaterial); 39 | } 40 | 41 | public void Init(float width, float height, float depth, float force, Vector4 plane, Vector4 waveParams, 42 | int texSize, Texture2D mask) 43 | { 44 | m_WaveParams = waveParams; 45 | 46 | m_Camera = gameObject.AddComponent(); 47 | m_Camera.aspect = width / height; 48 | m_Camera.backgroundColor = Color.black; 49 | m_Camera.cullingMask = 0; 50 | m_Camera.depth = 0; 51 | m_Camera.farClipPlane = depth; 52 | m_Camera.nearClipPlane = 0; 53 | m_Camera.orthographic = true; 54 | m_Camera.orthographicSize = height * 0.5f; 55 | m_Camera.clearFlags = CameraClearFlags.Depth; 56 | m_Camera.allowHDR = false; 57 | 58 | m_CommandBuffer = new CommandBuffer(); 59 | m_Camera.AddCommandBuffer(CameraEvent.AfterImageEffectsOpaque, m_CommandBuffer); 60 | m_ForceMaterial = new Material(Shader.Find("Hidden/Force")); 61 | 62 | m_CurTexture = RenderTexture.GetTemporary(texSize, texSize, 16); 63 | m_CurTexture.name = "[Cur]"; 64 | m_PreTexture = RenderTexture.GetTemporary(texSize, texSize, 16); 65 | m_PreTexture.name = "[Pre]"; 66 | m_HeightMap = RenderTexture.GetTemporary(texSize, texSize, 16); 67 | m_HeightMap.name = "[HeightMap]"; 68 | m_NormalMap = RenderTexture.GetTemporary(texSize, texSize, 16); 69 | m_NormalMap.anisoLevel = 1; 70 | m_NormalMap.name = "[NormalMap]"; 71 | 72 | RenderTexture tmp = RenderTexture.active; 73 | RenderTexture.active = m_CurTexture; 74 | GL.Clear(false, true, new Color(0, 0, 0, 0)); 75 | RenderTexture.active = m_PreTexture; 76 | GL.Clear(false, true, new Color(0, 0, 0, 0)); 77 | RenderTexture.active = m_HeightMap; 78 | GL.Clear(false, true, new Color(0, 0, 0, 0)); 79 | 80 | RenderTexture.active = tmp; 81 | 82 | m_Camera.targetTexture = m_CurTexture; 83 | 84 | Shader.SetGlobalFloat("internal_Force", force); 85 | 86 | m_WaveEquationMat = new Material(Shader.Find("Hidden/WaveEquationGen")); 87 | m_WaveEquationMat.SetTexture("_Mask", mask); 88 | m_NormalGenerateMat = new Material(Shader.Find("Hidden/NormalGen")); 89 | m_WaveEquationMat.SetVector("_WaveParams", m_WaveParams); 90 | } 91 | 92 | void OnRenderImage(RenderTexture src, RenderTexture dst) 93 | { 94 | //传入前一次的高度渲染结果,以在shader中根据二位波方程计算当前高度 95 | m_WaveEquationMat.SetTexture("_PreTex", m_PreTexture); 96 | 97 | Graphics.Blit(src, dst, m_WaveEquationMat); 98 | 99 | Graphics.Blit(dst, m_HeightMap); 100 | 101 | Graphics.Blit(m_HeightMap, m_NormalMap, m_NormalGenerateMat); 102 | 103 | 104 | Graphics.Blit(src, m_PreTexture); 105 | 106 | 107 | } 108 | 109 | void OnPostRender() 110 | { 111 | m_CommandBuffer.Clear(); 112 | m_CommandBuffer.ClearRenderTarget(true, false, Color.black); 113 | m_CommandBuffer.SetRenderTarget(m_CurTexture); 114 | 115 | Shader.SetGlobalTexture("_LiquidHeightMap", m_HeightMap); 116 | Shader.SetGlobalTexture("_LiquidNormalMap", m_NormalMap); 117 | } 118 | 119 | /// 120 | /// 判断包围盒是否被相机裁剪 121 | /// 122 | /// 123 | /// 124 | /// 125 | private static bool IsBoundsInCamera(Bounds bounds, Camera camera) 126 | { 127 | 128 | Matrix4x4 matrix = camera.projectionMatrix * camera.worldToCameraMatrix; 129 | 130 | int code = 131 | ComputeOutCode(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y + bounds.size.y / 2, 132 | bounds.center.z + bounds.size.z / 2, 1), matrix); 133 | 134 | 135 | code &= 136 | ComputeOutCode(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y + bounds.size.y / 2, 137 | bounds.center.z + bounds.size.z / 2, 1), matrix); 138 | 139 | code &= 140 | ComputeOutCode(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y - bounds.size.y / 2, 141 | bounds.center.z + bounds.size.z / 2, 1), matrix); 142 | 143 | code &= 144 | ComputeOutCode(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y - bounds.size.y / 2, 145 | bounds.center.z + bounds.size.z / 2, 1), matrix); 146 | 147 | code &= 148 | ComputeOutCode(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y + bounds.size.y / 2, 149 | bounds.center.z - bounds.size.z / 2, 1), matrix); 150 | 151 | code &= 152 | ComputeOutCode(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y + bounds.size.y / 2, 153 | bounds.center.z - bounds.size.z / 2, 1), matrix); 154 | 155 | code &= 156 | ComputeOutCode(new Vector4(bounds.center.x + bounds.size.x / 2, bounds.center.y - bounds.size.y / 2, 157 | bounds.center.z - bounds.size.z / 2, 1), matrix); 158 | 159 | code &= 160 | ComputeOutCode(new Vector4(bounds.center.x - bounds.size.x / 2, bounds.center.y - bounds.size.y / 2, 161 | bounds.center.z - bounds.size.z / 2, 1), matrix); 162 | 163 | 164 | if (code != 0) return false; 165 | 166 | return true; 167 | } 168 | 169 | private static int ComputeOutCode(Vector4 pos, Matrix4x4 projection) 170 | { 171 | pos = projection * pos; 172 | int code = 0; 173 | if (pos.x < -pos.w) code |= 0x01; 174 | if (pos.x > pos.w) code |= 0x02; 175 | if (pos.y < -pos.w) code |= 0x04; 176 | if (pos.y > pos.w) code |= 0x08; 177 | if (pos.z < -pos.w) code |= 0x10; 178 | if (pos.z > pos.w) code |= 0x20; 179 | return code; 180 | } 181 | 182 | void OnDestroy() 183 | { 184 | if (m_CurTexture) 185 | RenderTexture.ReleaseTemporary(m_CurTexture); 186 | if (m_PreTexture) 187 | RenderTexture.ReleaseTemporary(m_PreTexture); 188 | if (m_HeightMap) 189 | RenderTexture.ReleaseTemporary(m_HeightMap); 190 | if (m_NormalMap) 191 | RenderTexture.ReleaseTemporary(m_NormalMap); 192 | if (m_ForceMaterial) 193 | Destroy(m_ForceMaterial); 194 | if (m_WaveEquationMat) 195 | Destroy(m_WaveEquationMat); 196 | if (m_NormalGenerateMat) 197 | Destroy(m_NormalGenerateMat); 198 | if (m_CommandBuffer != null) 199 | m_CommandBuffer.Release(); 200 | //if (m_ReflectCamera) 201 | // Destroy(m_ReflectCamera.gameObject); 202 | //m_ForceRenderShader = null; 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSampleCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 73baeadd558cc854d8d182d450298f5b 3 | timeCreated: 1536211783 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSampleObject.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class LiquidSampleObject : MonoBehaviour 5 | { 6 | private Renderer m_Renderer; 7 | private Matrix4x4 m_LocalMatrix; 8 | 9 | void Start() 10 | { 11 | m_Renderer = gameObject.GetComponent(); 12 | m_LocalMatrix = transform.localToWorldMatrix; 13 | } 14 | 15 | void OnRenderObject() 16 | { 17 | if (m_Renderer && m_LocalMatrix != transform.localToWorldMatrix) 18 | { 19 | m_LocalMatrix = transform.localToWorldMatrix; 20 | LiquidSimulator.DrawObject(m_Renderer); 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSampleObject.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ea8d6c8be566144d8d4095af0cdc2c7 3 | timeCreated: 1536211783 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSimulator.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /// 5 | /// 液体模拟器 6 | /// 7 | public class LiquidSimulator : MonoBehaviour 8 | { 9 | #region public 10 | /// 11 | /// 网格单元格大小 12 | /// 13 | public float geometryCellSize; 14 | /// 15 | /// 液面宽度 16 | /// 17 | public float liquidWidth; 18 | /// 19 | /// 液面长度 20 | /// 21 | public float liquidLength; 22 | /// 23 | /// 液体深度 24 | /// 25 | public float liquidDepth; 26 | 27 | public int heightMapSize; 28 | 29 | public Texture2D mask; 30 | 31 | /// 32 | /// 粘度系数 33 | /// 34 | public float Viscosity 35 | { 36 | get { return m_Viscosity; } 37 | } 38 | 39 | /// 40 | /// 波速 41 | /// 42 | public float Velocity 43 | { 44 | get { return m_Velocity; } 45 | } 46 | 47 | /// 48 | /// 力度系数 49 | /// 50 | public float ForceFactor 51 | { 52 | get { return m_ForceFactor; } 53 | } 54 | 55 | #endregion 56 | 57 | [SerializeField] private float m_Viscosity; 58 | [SerializeField] private float m_Velocity; 59 | [SerializeField] private float m_ForceFactor; 60 | [SerializeField] private Material m_LiquidMaterial; 61 | 62 | private bool m_IsSupported; 63 | 64 | private Mesh m_LiquidMesh; 65 | private MeshFilter m_LiquidMeshFilter; 66 | private MeshRenderer m_LiquidMeshRenderer; 67 | private LiquidSampleCamera m_SampleCamera; 68 | //private ReflectCamera m_ReflectCamera; 69 | 70 | private Vector4 m_LiquidParams; 71 | 72 | private float m_SampleSpacing; 73 | 74 | private Vector4 m_LiquidArea; 75 | 76 | private static LiquidSimulator Instance 77 | { 78 | get 79 | { 80 | if (sInstance == null) 81 | sInstance = FindObjectOfType(); 82 | return sInstance; 83 | } 84 | } 85 | 86 | private static LiquidSimulator sInstance; 87 | 88 | void Start() 89 | { 90 | m_SampleSpacing = 1.0f / heightMapSize; 91 | 92 | m_IsSupported = CheckSupport(); 93 | if (!m_IsSupported) 94 | return; 95 | 96 | m_SampleCamera = new GameObject("[LiquidSampleCamera]").AddComponent(); 97 | m_SampleCamera.transform.SetParent(transform); 98 | m_SampleCamera.transform.localPosition = Vector3.zero; 99 | m_SampleCamera.transform.localEulerAngles = new Vector3(90,0,0); 100 | m_SampleCamera.Init(liquidWidth, liquidLength, liquidDepth, m_ForceFactor, 101 | new Vector4(transform.up.x, transform.up.y, transform.up.z, 102 | -Vector3.Dot(transform.up, transform.position)), m_LiquidParams, heightMapSize, mask); 103 | 104 | 105 | m_LiquidMeshRenderer = gameObject.GetComponent(); 106 | if (m_LiquidMeshRenderer == null) 107 | m_LiquidMeshRenderer = gameObject.AddComponent(); 108 | m_LiquidMeshFilter = gameObject.GetComponent(); 109 | if (m_LiquidMeshFilter == null) 110 | m_LiquidMeshFilter = gameObject.AddComponent(); 111 | 112 | m_LiquidMesh = Utils.GenerateLiquidMesh(liquidWidth, liquidLength, geometryCellSize); 113 | m_LiquidMeshFilter.sharedMesh = m_LiquidMesh; 114 | m_LiquidMeshRenderer.sharedMaterial = m_LiquidMaterial; 115 | 116 | m_LiquidArea = new Vector4(transform.position.x - liquidWidth * 0.5f, 117 | transform.position.z - liquidLength * 0.5f, 118 | transform.position.x + liquidWidth * 0.5f, transform.position.z + liquidLength * 0.5f); 119 | 120 | gameObject.AddComponent(); 121 | } 122 | 123 | public static void DrawObject(Renderer renderer) 124 | { 125 | if (Instance != null) 126 | { 127 | Instance.m_SampleCamera.DrawRenderer(renderer); 128 | } 129 | } 130 | 131 | public static void DrawMesh(Mesh mesh, Matrix4x4 matrix) 132 | { 133 | if (Instance != null) 134 | { 135 | Instance.m_SampleCamera.ForceDrawMesh(mesh, matrix); 136 | } 137 | } 138 | 139 | void OnWillRenderObject() 140 | { 141 | Shader.SetGlobalVector("_LiquidArea", m_LiquidArea); 142 | } 143 | 144 | bool CheckSupport() 145 | { 146 | if (geometryCellSize <= 0) 147 | { 148 | Debug.LogError("网格单元格大小不允许小于等于0!"); 149 | return false; 150 | } 151 | if (liquidWidth <= 0 || liquidLength <= 0) 152 | { 153 | Debug.LogError("液体长宽不允许小于等于0!"); 154 | return false; 155 | } 156 | if (liquidDepth <= 0) 157 | { 158 | Debug.LogError("液体深度不允许小于等于0!"); 159 | return false; 160 | } 161 | 162 | 163 | if (!RefreshLiquidParams(m_Velocity, m_Viscosity)) 164 | return false; 165 | 166 | return true; 167 | } 168 | 169 | private bool RefreshLiquidParams(float speed, float viscosity) 170 | { 171 | if (speed <= 0) 172 | { 173 | Debug.LogError("波速不允许小于等于0!"); 174 | return false; 175 | } 176 | if (viscosity <= 0) 177 | { 178 | Debug.LogError("粘度系数不允许小于等于0!"); 179 | return false; 180 | } 181 | float maxvelocity = m_SampleSpacing / (2 * Time.fixedDeltaTime) * Mathf.Sqrt(viscosity * Time.fixedDeltaTime + 2); 182 | float velocity = maxvelocity * speed; 183 | float viscositySq = viscosity * viscosity; 184 | float velocitySq = velocity * velocity; 185 | float deltaSizeSq = m_SampleSpacing * m_SampleSpacing; 186 | float dt = Mathf.Sqrt(viscositySq + 32 * velocitySq / (deltaSizeSq)); 187 | float dtden = 8 * velocitySq / (deltaSizeSq); 188 | float maxT = (viscosity + dt) / dtden; 189 | float maxT2 = (viscosity - dt) / dtden; 190 | if (maxT2 > 0 && maxT2 < maxT) 191 | maxT = maxT2; 192 | if (maxT < Time.fixedDeltaTime) 193 | { 194 | Debug.LogError("粘度系数不符合要求"); 195 | return false; 196 | } 197 | 198 | float fac = velocitySq * Time.fixedDeltaTime * Time.fixedDeltaTime / deltaSizeSq; 199 | float i = viscosity * Time.fixedDeltaTime - 2; 200 | float j = viscosity * Time.fixedDeltaTime + 2; 201 | 202 | float k1 = (4 - 8 * fac) / (j); 203 | float k2 = i / j; 204 | float k3 = 2 * fac / j; 205 | 206 | m_LiquidParams = new Vector4(k1, k2, k3, m_SampleSpacing); 207 | 208 | m_Velocity = speed; 209 | m_Viscosity = viscosity; 210 | 211 | return true; 212 | } 213 | 214 | void OnDrawGizmosSelected() 215 | { 216 | Utils.DrawWireCube(transform.position, transform.eulerAngles.y, liquidWidth, liquidLength, -liquidDepth, 0, Color.green); 217 | } 218 | } 219 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/LiquidSimulator.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a150c614f15564c4bba0433c47930b4a 3 | timeCreated: 1536586564 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/ReflectCamera.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /// 6 | /// 反射相机 7 | /// 8 | public class ReflectCamera : MonoBehaviour 9 | { 10 | 11 | private RenderTexture m_ReflectTex; 12 | 13 | //private Matrix4x4 m_ReflectionMatrix; 14 | //private Matrix4x4 m_ClipProjection; 15 | 16 | private Camera m_Camera; 17 | 18 | private static bool m_IsRendering = false; 19 | 20 | void OnDisable() 21 | { 22 | Clear(); 23 | } 24 | 25 | void Clear() 26 | { 27 | if (m_ReflectTex) 28 | { 29 | Destroy(m_ReflectTex); 30 | m_ReflectTex = null; 31 | } 32 | } 33 | 34 | static void CalculateReflectionMatrix(ref Matrix4x4 reflectionMat, Vector4 plane) 35 | { 36 | reflectionMat.m00 = (1F - 2F * plane[0] * plane[0]); 37 | reflectionMat.m01 = (-2F * plane[0] * plane[1]); 38 | reflectionMat.m02 = (-2F * plane[0] * plane[2]); 39 | reflectionMat.m03 = (-2F * plane[3] * plane[0]); 40 | 41 | reflectionMat.m10 = (-2F * plane[1] * plane[0]); 42 | reflectionMat.m11 = (1F - 2F * plane[1] * plane[1]); 43 | reflectionMat.m12 = (-2F * plane[1] * plane[2]); 44 | reflectionMat.m13 = (-2F * plane[3] * plane[1]); 45 | 46 | reflectionMat.m20 = (-2F * plane[2] * plane[0]); 47 | reflectionMat.m21 = (-2F * plane[2] * plane[1]); 48 | reflectionMat.m22 = (1F - 2F * plane[2] * plane[2]); 49 | reflectionMat.m23 = (-2F * plane[3] * plane[2]); 50 | 51 | reflectionMat.m30 = 0F; 52 | reflectionMat.m31 = 0F; 53 | reflectionMat.m32 = 0F; 54 | reflectionMat.m33 = 1F; 55 | } 56 | 57 | Vector4 CameraSpacePlane(Camera cam, Vector3 pos, Vector3 normal, float sideSign) 58 | { 59 | Matrix4x4 m = cam.worldToCameraMatrix; 60 | Vector3 cpos = m.MultiplyPoint(pos); 61 | Vector3 cnormal = m.MultiplyVector(normal).normalized * sideSign; 62 | return new Vector4(cnormal.x, cnormal.y, cnormal.z, -Vector3.Dot(cpos, cnormal)); 63 | } 64 | 65 | static void CalculateObliqueMatrix(ref Matrix4x4 projection, Vector4 clipPlane) 66 | { 67 | Vector4 q = projection.inverse * new Vector4(SignExt(clipPlane.x), SignExt(clipPlane.y), 1.0f, 1.0f); 68 | Vector4 c = clipPlane * (2.0F / (Vector4.Dot(clipPlane, q))); 69 | 70 | projection[2] = c.x - projection[3]; 71 | projection[6] = c.y - projection[7]; 72 | projection[10] = c.z - projection[11]; 73 | projection[14] = c.w - projection[15]; 74 | } 75 | 76 | static float SignExt(float a) 77 | { 78 | if (a > 0.0f) return 1.0f; 79 | if (a < 0.0f) return -1.0f; 80 | return 0.0f; 81 | } 82 | 83 | Camera GetReflectionCamera(Camera current, Material mat, int textureSize) 84 | { 85 | if (!m_ReflectTex) 86 | { 87 | if (m_ReflectTex) Destroy(m_ReflectTex); 88 | m_ReflectTex = new RenderTexture(textureSize, textureSize, 16); 89 | m_ReflectTex.name = "__MirrorReflection" + GetInstanceID(); 90 | m_ReflectTex.isPowerOfTwo = true; 91 | } 92 | 93 | Camera cam = m_Camera; 94 | 95 | if (!cam) 96 | { 97 | 98 | cam = new GameObject("ReflectCamera").AddComponent(); 99 | cam.enabled = false; 100 | cam.hideFlags = HideFlags.HideInHierarchy; 101 | 102 | Transform t = cam.transform; 103 | t.position = transform.position; 104 | t.rotation = transform.rotation; 105 | 106 | //mCameras[current] = cam; 107 | m_Camera = cam; 108 | } 109 | 110 | // Automatically update the reflection texture 111 | //if (mat.HasProperty("_LiquidReflectMap")) 112 | mat.SetTexture("_LiquidReflectMap", m_ReflectTex); 113 | return cam; 114 | } 115 | 116 | void CopyCamera(Camera src, Camera dest) 117 | { 118 | 119 | dest.clearFlags = src.clearFlags; 120 | dest.backgroundColor = src.backgroundColor; 121 | dest.farClipPlane = src.farClipPlane; 122 | dest.nearClipPlane = src.nearClipPlane; 123 | dest.orthographic = src.orthographic; 124 | dest.fieldOfView = src.fieldOfView; 125 | dest.aspect = src.aspect; 126 | dest.orthographicSize = src.orthographicSize; 127 | dest.depthTextureMode = DepthTextureMode.None; 128 | dest.renderingPath = RenderingPath.Forward; 129 | } 130 | 131 | void OnWillRenderObject() 132 | { 133 | 134 | if (m_IsRendering) return; 135 | Material mat = GetComponent().sharedMaterial; 136 | 137 | Camera cam = Camera.current; 138 | cam.depthTextureMode = DepthTextureMode.Depth; 139 | if (!cam) return; 140 | 141 | LayerMask mask = -1; 142 | 143 | m_IsRendering = true; 144 | Camera mirror = GetReflectionCamera(cam, mat, 512); 145 | 146 | Vector3 pos = transform.position; 147 | Vector3 normal = transform.up; 148 | 149 | CopyCamera(cam, mirror); 150 | 151 | float d = -Vector3.Dot(normal, pos); 152 | Vector4 reflectionPlane = new Vector4(normal.x, normal.y, normal.z, d); 153 | Matrix4x4 reflection = Matrix4x4.zero; 154 | 155 | CalculateReflectionMatrix(ref reflection, reflectionPlane); 156 | 157 | Vector3 oldpos = cam.transform.position; 158 | Vector3 newpos = reflection.MultiplyPoint(oldpos); 159 | //m_ReflectionMatrix = reflection; 160 | mirror.worldToCameraMatrix = cam.worldToCameraMatrix * reflection; 161 | 162 | Vector4 clipPlane = CameraSpacePlane(mirror, pos, normal, 1.0f); 163 | Matrix4x4 projection = cam.projectionMatrix; 164 | 165 | //CalculateObliqueMatrix(ref projection, clipPlane); 166 | projection = cam.CalculateObliqueMatrix(clipPlane); 167 | 168 | //m_ClipProjection = projection; 169 | mirror.projectionMatrix = projection; 170 | mirror.cullingMask = ~(1 << 4) & mask.value; 171 | mirror.targetTexture = m_ReflectTex; 172 | 173 | GL.invertCulling = true; 174 | { 175 | mirror.transform.position = newpos; 176 | Vector3 euler = cam.transform.eulerAngles; 177 | mirror.transform.eulerAngles = new Vector3(0, euler.y, euler.z); 178 | mirror.Render(); 179 | mirror.transform.position = oldpos; 180 | } 181 | //mat.SetTexture("_MainTex", mTex); 182 | GL.invertCulling = false; 183 | m_IsRendering = false; 184 | } 185 | } 186 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/ReflectCamera.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 765b281d8a9a9da4ab9f70a870f79593 3 | timeCreated: 1538736156 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/SunLight.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /// 6 | /// 平行光-用于渲染和投射阴影 7 | /// 8 | public class SunLight : MonoBehaviour { 9 | 10 | public int shadowMapSize; 11 | 12 | public float bias; 13 | 14 | public float near; 15 | public float far; 16 | 17 | public float size; 18 | public float aspect; 19 | public Color color; 20 | public float intensity; 21 | 22 | public Shader shadowMapRenderShader; 23 | 24 | private Camera m_Camera; 25 | private RenderTexture m_ShadowMap; 26 | 27 | private Mesh m_BGMesh; 28 | private Material m_BGMaterial; 29 | 30 | void Start () { 31 | InitRenderTarget(); 32 | 33 | m_BGMesh = new Mesh(); 34 | m_BGMesh.vertices = new Vector3[] 35 | { 36 | new Vector3(-aspect * size, -size, far - 0.01f), new Vector3(-aspect * size, size, far - 0.01f), 37 | new Vector3(aspect * size, size, far - 0.01f), new Vector3(aspect * size, -size, far - 0.01f) 38 | }; 39 | m_BGMesh.triangles = new int[] 40 | { 41 | 0, 1, 2, 0, 2, 3 42 | }; 43 | m_BGMaterial = new Material(shadowMapRenderShader); 44 | 45 | //MeshRenderer mr = new GameObject("t").AddComponent(); 46 | //MeshFilter mf = mr.gameObject.AddComponent(); 47 | //mr.transform.SetParent(transform); 48 | //mr.transform.localPosition = Vector3.zero; 49 | //mr.transform.localEulerAngles = Vector3.zero; 50 | //mr.sharedMaterial = m_BGMaterial; 51 | //mf.sharedMesh = m_BGMesh; 52 | } 53 | 54 | void OnDestroy() 55 | { 56 | if (m_ShadowMap) 57 | Destroy(m_ShadowMap); 58 | m_ShadowMap = null; 59 | if (m_BGMaterial) 60 | Destroy(m_BGMaterial); 61 | if(m_BGMesh) 62 | Destroy(m_BGMesh); 63 | } 64 | 65 | //void OnPostRender() 66 | //{ 67 | // m_BGMaterial.SetPass(0); 68 | // Graphics.DrawMeshNow(m_BGMesh, transform.localToWorldMatrix); 69 | //} 70 | 71 | void OnPreRender() 72 | { 73 | //m_BGMaterial.SetPass(0); 74 | //Graphics.DrawMeshNow(m_BGMesh, transform.localToWorldMatrix); 75 | 76 | Matrix4x4 wtl = m_Camera.worldToCameraMatrix; 77 | 78 | Shader.SetGlobalVector("internalWorldLightPos", 79 | new Vector4(transform.forward.x, transform.forward.y, transform.forward.z, 0)); 80 | Shader.SetGlobalMatrix("internalWorldLightMV", wtl); 81 | 82 | Shader.SetGlobalMatrix("internalWorldLightVP", m_Camera.projectionMatrix); 83 | Shader.SetGlobalVector("internalProjectionParams", 84 | new Vector4(0.01f, m_Camera.nearClipPlane, m_Camera.farClipPlane, 1 / m_Camera.farClipPlane)); 85 | Shader.SetGlobalColor("internalWorldLightColor", 86 | new Color(color.r*intensity, color.g * intensity, color.b * intensity, color.a)); 87 | Shader.SetGlobalFloat("internalBias", bias); 88 | } 89 | 90 | void InitRenderTarget() 91 | { 92 | if (m_Camera == null) 93 | { 94 | m_Camera = GetComponent(); 95 | if (m_Camera == null) 96 | m_Camera = gameObject.AddComponent(); 97 | //m_Camera.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector; 98 | //m_Camera = new GameObject("[RenderCamera]").AddComponent(); 99 | //m_Camera.transform.SetParent(transform); 100 | //m_Camera.transform.localPosition = Vector3.zero; 101 | //m_Camera.transform.localRotation = Quaternion.identity; 102 | m_Camera.aspect = aspect; 103 | m_Camera.backgroundColor = new Color(1,1,1,0);//new Color(0, 0, 0, 0); 104 | m_Camera.clearFlags = CameraClearFlags.SolidColor; 105 | m_Camera.depth = 0; 106 | m_Camera.farClipPlane = far; 107 | m_Camera.nearClipPlane = near; 108 | m_Camera.orthographic = true; 109 | m_Camera.orthographicSize = size; 110 | m_Camera.SetReplacementShader(shadowMapRenderShader, "RenderType"); 111 | } 112 | if (m_ShadowMap == null) 113 | { 114 | m_ShadowMap = new RenderTexture(shadowMapSize, shadowMapSize, 16); 115 | m_Camera.targetTexture = m_ShadowMap; 116 | Shader.SetGlobalTexture("internalShadowMap", m_ShadowMap); 117 | } 118 | } 119 | 120 | void OnDrawGizmos() 121 | { 122 | Gizmos.color = new Color(0, 0.3f, 1f, 0.6f); 123 | 124 | Vector3 vp1 = transform.position + transform.rotation * new Vector3(-size * aspect, -size, near); 125 | Vector3 vp2 = transform.position + transform.rotation * new Vector3(-size * aspect, size, near); 126 | Vector3 vp3 = transform.position + transform.rotation * new Vector3(size * aspect, size, near); 127 | Vector3 vp4 = transform.position + transform.rotation * new Vector3(size * aspect, -size, near); 128 | 129 | Vector3 vp5 = transform.position + transform.rotation * new Vector3(-size * aspect, -size, far); 130 | Vector3 vp6 = transform.position + transform.rotation * new Vector3(-size * aspect, size, far); 131 | Vector3 vp7 = transform.position + transform.rotation * new Vector3(size * aspect, size, far); 132 | Vector3 vp8 = transform.position + transform.rotation * new Vector3(size * aspect, -size, far); 133 | 134 | Gizmos.DrawLine(vp1, vp2); 135 | Gizmos.DrawLine(vp2, vp3); 136 | Gizmos.DrawLine(vp3, vp4); 137 | Gizmos.DrawLine(vp4, vp1); 138 | 139 | Gizmos.DrawLine(vp5, vp6); 140 | Gizmos.DrawLine(vp6, vp7); 141 | Gizmos.DrawLine(vp7, vp8); 142 | Gizmos.DrawLine(vp8, vp5); 143 | 144 | Gizmos.DrawLine(vp1, vp5); 145 | Gizmos.DrawLine(vp2, vp6); 146 | Gizmos.DrawLine(vp3, vp7); 147 | Gizmos.DrawLine(vp4, vp8); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/SunLight.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 4d92a643da394ea4abc8cff48793c94f 3 | timeCreated: 1538658820 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: d2f875b28faaecb468dd4ae90d3e2a14 3 | folderAsset: yes 4 | timeCreated: 1538748354 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Test/CameraController.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | /// 5 | /// 摄像机控制器 6 | /// 7 | public class CameraController : MonoBehaviour 8 | { 9 | 10 | public Vector3 cameraTarget; 11 | public Bounds targetRange; 12 | public Vector2 distanceRange; 13 | public Vector2 eulerXRange; 14 | public Vector2 eulerYRange; 15 | 16 | public float moveLerpSpeed; 17 | public float rotateLerpSpeed; 18 | 19 | public float speedMove = 50; 20 | public float speedRotate = 500; 21 | public float speedScalling = 100; 22 | 23 | [SerializeField]private float m_Distance; 24 | private Vector3 m_Target; 25 | private Quaternion m_Rotation; 26 | 27 | void Start () 28 | { 29 | m_Target = cameraTarget; 30 | m_Distance = Vector3.Distance(transform.position, m_Target); 31 | m_Rotation = transform.rotation; 32 | 33 | transform.position = m_Target - transform.forward * m_Distance; 34 | } 35 | 36 | void Update() 37 | { 38 | float _scrollWheelValue = Input.GetAxis("Mouse ScrollWheel"); 39 | if (Input.GetMouseButton(1)) 40 | { 41 | CameraRotate(); 42 | } 43 | if (Input.GetMouseButton(2)) 44 | { 45 | CameraMove(); 46 | } 47 | CameraScalling(_scrollWheelValue); 48 | 49 | Vector3 camPos = m_Target - transform.forward * m_Distance; 50 | 51 | transform.rotation = Quaternion.Lerp(transform.rotation, m_Rotation, Time.deltaTime * rotateLerpSpeed); 52 | transform.position = Vector3.Lerp(transform.position, camPos, Time.deltaTime * moveLerpSpeed); 53 | } 54 | 55 | private void CameraMove() 56 | { 57 | m_Target += (-Input.GetAxis("Mouse X") * transform.right - Input.GetAxis("Mouse Y") * transform.up) * Time.deltaTime * speedMove; 58 | 59 | m_Target.x = Mathf.Clamp(m_Target.x, targetRange.min.x, targetRange.max.x); 60 | m_Target.y = Mathf.Clamp(m_Target.y, targetRange.min.y, targetRange.max.y); 61 | m_Target.z = Mathf.Clamp(m_Target.z, targetRange.min.z, targetRange.max.z); 62 | } 63 | 64 | private void CameraScalling(float axis) 65 | { 66 | if (Mathf.Abs(axis) > 0.01f) 67 | { 68 | m_Distance -= Time.deltaTime* axis * speedScalling; 69 | m_Distance = Mathf.Clamp(m_Distance, distanceRange.x, distanceRange.y); 70 | } 71 | } 72 | 73 | private void CameraRotate() 74 | { 75 | Vector3 _rotation = transform.rotation.eulerAngles; 76 | _rotation += new Vector3(-Input.GetAxis("Mouse Y"), Input.GetAxis("Mouse X"), 0) * Time.deltaTime * speedRotate; 77 | 78 | _rotation.x = Mathf.Clamp(_rotation.x, eulerXRange.x, eulerXRange.y); 79 | _rotation.y = Mathf.Clamp(_rotation.y, eulerYRange.x, eulerYRange.y); 80 | 81 | _rotation.z = 0; 82 | 83 | m_Rotation = Quaternion.Euler(_rotation); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Test/CameraController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 5786c7f9ad030384482acd32fb7025b8 3 | timeCreated: 1538064104 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Test/DragController.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | public class DragController : MonoBehaviour 6 | { 7 | 8 | public GameObject dragTarget; 9 | public LiquidSimulator simulator; 10 | public Mesh swipeMesh; 11 | public float swipeSize; 12 | public float height; 13 | 14 | private Camera m_Camera; 15 | 16 | private bool m_IsBeginDrag; 17 | private float m_DragPlane; 18 | private Vector4 m_DragWorldPlane; 19 | private Vector4 m_SwipePlane; 20 | 21 | private Vector3 m_Offset; 22 | 23 | void Start () 24 | { 25 | m_Camera = gameObject.GetComponent(); 26 | m_SwipePlane = new Vector4(0, 1, 0, Vector3.Dot(Vector3.up, new Vector3(0, height, 0))); 27 | } 28 | 29 | void Update() 30 | { 31 | if (Input.GetMouseButton(0)) 32 | { 33 | Ray ray = m_Camera.ScreenPointToRay(Input.mousePosition); 34 | RaycastHit hit; 35 | if (!m_IsBeginDrag) 36 | { 37 | if (Physics.Raycast(ray, out hit)) 38 | { 39 | if (hit.collider.gameObject == dragTarget) 40 | { 41 | if (!m_IsBeginDrag) 42 | { 43 | m_IsBeginDrag = true; 44 | Vector3 viewPos = 45 | m_Camera.transform.worldToLocalMatrix.MultiplyPoint(hit.collider.transform.position); 46 | m_DragPlane = viewPos.z; 47 | m_Offset = hit.point - hit.collider.transform.position; 48 | m_DragWorldPlane = new Vector4(0, 1, 0, Vector3.Dot(Vector3.up, hit.point)); 49 | } 50 | } 51 | else if (hit.collider.gameObject == simulator.gameObject) 52 | { 53 | if (!m_IsBeginDrag) 54 | { 55 | float t = (m_SwipePlane.w - 56 | Vector3.Dot(ray.origin, 57 | new Vector3(m_SwipePlane.x, m_SwipePlane.y, m_SwipePlane.z)))/ 58 | Vector3.Dot(ray.direction, 59 | new Vector3(m_SwipePlane.x, m_SwipePlane.y, m_SwipePlane.z)); 60 | Vector3 hitpos = ray.origin + ray.direction*t; 61 | Matrix4x4 matrix = Matrix4x4.TRS(hitpos, Quaternion.identity, Vector3.one*swipeSize); 62 | LiquidSimulator.DrawMesh(swipeMesh, matrix); 63 | } 64 | } 65 | } 66 | } 67 | else 68 | { 69 | if (m_Camera.transform.eulerAngles.x > 45) 70 | { 71 | float t = (m_DragWorldPlane.w - 72 | Vector3.Dot(ray.origin, 73 | new Vector3(m_DragWorldPlane.x, m_DragWorldPlane.y, m_DragWorldPlane.z))) / 74 | Vector3.Dot(ray.direction, 75 | new Vector3(m_DragWorldPlane.x, m_DragWorldPlane.y, m_DragWorldPlane.z)); 76 | Vector3 hitpos = ray.origin + ray.direction * t; 77 | 78 | dragTarget.transform.position = hitpos - m_Offset; 79 | } 80 | else 81 | { 82 | float tan = Mathf.Tan(m_Camera.fieldOfView * 0.5f * Mathf.Deg2Rad); 83 | float height = m_DragPlane * tan; 84 | float width = height * m_Camera.aspect; 85 | 86 | float x = (Input.mousePosition.x / Screen.width) * 2 - 1; 87 | float y = (Input.mousePosition.y / Screen.height) * 2 - 1; 88 | Vector3 viewPos = new Vector3(x * width, y * height, m_DragPlane); 89 | Vector3 pos = m_Camera.transform.localToWorldMatrix.MultiplyPoint(viewPos); 90 | dragTarget.transform.position = pos - m_Offset; 91 | } 92 | } 93 | } 94 | 95 | if (Input.GetMouseButtonUp(0)) 96 | { 97 | m_IsBeginDrag = false; 98 | } 99 | } 100 | 101 | } 102 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Test/DragController.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 71e1a3cd85420fc469107274e6da5f87 3 | timeCreated: 1538967524 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Utils.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | using System.Collections.Generic; 4 | 5 | 6 | public static class Utils 7 | { 8 | public static Mesh GenerateLiquidMesh(float width, float length, float cellSize) 9 | { 10 | int xsize = Mathf.RoundToInt(width / cellSize); 11 | int ysize = Mathf.RoundToInt(length / cellSize); 12 | 13 | Mesh mesh = new Mesh(); 14 | 15 | List vertexList = new List(); 16 | List uvList = new List(); 17 | List normalList = new List(); 18 | List indexList = new List(); 19 | float xcellsize = width / xsize; 20 | float uvxcellsize = 1.0f / xsize; 21 | float ycellsize = length / ysize; 22 | float uvycellsize = 1.0f / ysize; 23 | 24 | for (int i = 0; i <= ysize; i++) 25 | { 26 | for (int j = 0; j <= xsize; j++) 27 | { 28 | vertexList.Add(new Vector3(-width * 0.5f + j * xcellsize, 0, -length * 0.5f + i * ycellsize)); 29 | uvList.Add(new Vector2(j * uvxcellsize, i * uvycellsize)); 30 | normalList.Add(Vector3.up); 31 | 32 | if (i < ysize && j < xsize) 33 | { 34 | indexList.Add(i * (xsize + 1) + j); 35 | indexList.Add((i + 1) * (xsize + 1) + j); 36 | indexList.Add((i + 1) * (xsize + 1) + j + 1); 37 | 38 | indexList.Add(i * (xsize + 1) + j); 39 | indexList.Add((i + 1) * (xsize + 1) + j + 1); 40 | indexList.Add(i * (xsize + 1) + j + 1); 41 | } 42 | } 43 | } 44 | 45 | mesh.SetVertices(vertexList); 46 | mesh.SetUVs(0, uvList); 47 | mesh.SetNormals(normalList); 48 | mesh.SetTriangles(indexList, 0); 49 | mesh.RecalculateNormals(); 50 | mesh.RecalculateTangents(); 51 | 52 | return mesh; 53 | } 54 | 55 | public static Mesh GenerateLiquidBodyMesh(float width, float length, float depth, float cellSize) 56 | { 57 | int xsize = Mathf.RoundToInt(width / cellSize); 58 | int ysize = Mathf.RoundToInt(length / cellSize); 59 | 60 | Mesh mesh = new Mesh(); 61 | 62 | List vertexList = new List(); 63 | List normalList = new List(); 64 | List uvList = new List(); 65 | List colorList = new List(); 66 | List indexList = new List(); 67 | float xcellsize = width / xsize; 68 | float uvxcellsize = 1.0f / xsize; 69 | float ycellsize = length / ysize; 70 | float uvycellsize = 1.0f / ysize; 71 | 72 | for (int i = 0; i <= ysize; i++) 73 | { 74 | vertexList.Add(new Vector3(-width * 0.5f, -depth, -length * 0.5f + i * ycellsize)); 75 | vertexList.Add(new Vector3(-width * 0.5f, 0, -length * 0.5f + i * ycellsize)); 76 | vertexList.Add(new Vector3(width * 0.5f, -depth, -length * 0.5f + i * ycellsize)); 77 | vertexList.Add(new Vector3(width * 0.5f, 0, -length * 0.5f + i * ycellsize)); 78 | normalList.Add(Vector3.left); 79 | normalList.Add(Vector3.left); 80 | normalList.Add(Vector3.right); 81 | normalList.Add(Vector3.right); 82 | colorList.Add(Color.white); 83 | colorList.Add(new Color(1, 1, 1, 0)); 84 | colorList.Add(Color.white); 85 | colorList.Add(new Color(1, 1, 1, 0)); 86 | uvList.Add(new Vector2(0, i * uvycellsize)); 87 | uvList.Add(new Vector2(0, i * uvycellsize)); 88 | uvList.Add(new Vector2(1, i * uvycellsize)); 89 | uvList.Add(new Vector2(1, i * uvycellsize)); 90 | 91 | if (i < ysize) 92 | { 93 | indexList.Add(i * 4); 94 | indexList.Add((i + 1) * 4 + 1); 95 | indexList.Add(i * 4 + 1); 96 | indexList.Add(i * 4); 97 | indexList.Add((i + 1) * 4); 98 | indexList.Add((i + 1) * 4 + 1); 99 | 100 | indexList.Add((i + 1) * 4 + 2); 101 | indexList.Add(i * 4 + 3); 102 | indexList.Add((i + 1) * 4 + 3); 103 | indexList.Add((i + 1) * 4 + 2); 104 | indexList.Add(i * 4 + 2); 105 | indexList.Add(i * 4 + 3); 106 | } 107 | } 108 | 109 | for (int j = 0; j <= xsize; j++) 110 | { 111 | vertexList.Add(new Vector3(-width * 0.5f + j * xcellsize, -depth, -length * 0.5f)); 112 | vertexList.Add(new Vector3(-width * 0.5f + j * xcellsize, 0, -length * 0.5f)); 113 | vertexList.Add(new Vector3(-width * 0.5f + j * xcellsize, -depth, length * 0.5f)); 114 | vertexList.Add(new Vector3(-width * 0.5f + j * xcellsize, 0, length * 0.5f)); 115 | normalList.Add(Vector3.back); 116 | normalList.Add(Vector3.back); 117 | normalList.Add(Vector3.forward); 118 | normalList.Add(Vector3.forward); 119 | colorList.Add(Color.white); 120 | colorList.Add(new Color(1, 1, 1, 0)); 121 | colorList.Add(Color.white); 122 | colorList.Add(new Color(1, 1, 1, 0)); 123 | uvList.Add(new Vector2(j * uvxcellsize, 0)); 124 | uvList.Add(new Vector2(j * uvxcellsize, 0)); 125 | uvList.Add(new Vector2(j * uvxcellsize, 1)); 126 | uvList.Add(new Vector2(j * uvxcellsize, 1)); 127 | 128 | if (j < xsize) 129 | { 130 | indexList.Add((ysize + 1) * 4 + j * 4); 131 | indexList.Add((ysize + 1) * 4 + j * 4 + 1); 132 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4 + 1); 133 | indexList.Add((ysize + 1) * 4 + j * 4); 134 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4 + 1); 135 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4); 136 | 137 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4 + 2); 138 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4 + 3); 139 | indexList.Add((ysize + 1) * 4 + j * 4 + 3); 140 | indexList.Add((ysize + 1) * 4 + (j + 1) * 4 + 2); 141 | indexList.Add((ysize + 1) * 4 + j * 4 + 3); 142 | indexList.Add((ysize + 1) * 4 + j * 4 + 2); 143 | } 144 | } 145 | 146 | mesh.SetVertices(vertexList); 147 | mesh.SetNormals(normalList); 148 | mesh.SetColors(colorList); 149 | mesh.SetUVs(0, uvList); 150 | mesh.SetTriangles(indexList, 0); 151 | mesh.RecalculateNormals(); 152 | mesh.RecalculateTangents(); 153 | 154 | return mesh; 155 | } 156 | 157 | public static void DrawWirePlane(Vector3 position, float angle, float width, float length, Color color) 158 | { 159 | Vector3 p1 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, 0, -length * 0.5f); 160 | Vector3 p2 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, 0, length * 0.5f); 161 | Vector3 p3 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, 0, length * 0.5f); 162 | Vector3 p4 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, 0, -length * 0.5f); 163 | 164 | Gizmos.color = color; 165 | 166 | Gizmos.DrawLine(p1, p2); 167 | Gizmos.DrawLine(p2, p3); 168 | Gizmos.DrawLine(p3, p4); 169 | Gizmos.DrawLine(p4, p1); 170 | } 171 | 172 | public static void DrawWireCube(Vector3 position, float angle, float width, float length, float minHeight, 173 | float maxHeight, Color color) 174 | { 175 | Vector3 p1 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, minHeight, -length * 0.5f); 176 | Vector3 p2 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, minHeight, length * 0.5f); 177 | Vector3 p3 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, minHeight, length * 0.5f); 178 | Vector3 p4 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, minHeight, -length * 0.5f); 179 | 180 | Vector3 p5 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, maxHeight, -length * 0.5f); 181 | Vector3 p6 = position + Quaternion.Euler(0, angle, 0) * new Vector3(-width * 0.5f, maxHeight, length * 0.5f); 182 | Vector3 p7 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, maxHeight, length * 0.5f); 183 | Vector3 p8 = position + Quaternion.Euler(0, angle, 0) * new Vector3(width * 0.5f, maxHeight, -length * 0.5f); 184 | 185 | Gizmos.color = color; 186 | 187 | Gizmos.DrawLine(p1, p2); 188 | Gizmos.DrawLine(p2, p3); 189 | Gizmos.DrawLine(p3, p4); 190 | Gizmos.DrawLine(p4, p1); 191 | 192 | Gizmos.DrawLine(p5, p6); 193 | Gizmos.DrawLine(p6, p7); 194 | Gizmos.DrawLine(p7, p8); 195 | Gizmos.DrawLine(p8, p5); 196 | 197 | Gizmos.DrawLine(p1, p5); 198 | Gizmos.DrawLine(p2, p6); 199 | Gizmos.DrawLine(p3, p7); 200 | Gizmos.DrawLine(p4, p8); 201 | } 202 | } -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/Utils.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 6540671390b07324ab8b547745879442 3 | timeCreated: 1536207694 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/WaterVolumeLightRenderer.cs: -------------------------------------------------------------------------------- 1 | using System.Collections; 2 | using System.Collections.Generic; 3 | using UnityEngine; 4 | 5 | /// 6 | /// 液体体积光渲染器 7 | /// 该渲染器的功能只是生成水体(不含水面)的Mesh并为材质传入包围盒和水面平面信息,实际的功能实现全部在shader中 8 | /// 9 | public class WaterVolumeLightRenderer : MonoBehaviour { 10 | 11 | /// 12 | /// 网格单元格大小 13 | /// 14 | public float geometryCellSize; 15 | /// 16 | /// 水体宽度 17 | /// 18 | public float width; 19 | /// 20 | /// 水体长度 21 | /// 22 | public float length; 23 | /// 24 | /// 水体深度 25 | /// 26 | public float depth; 27 | 28 | public Material material; 29 | 30 | private Mesh m_waterBodyMesh; 31 | private MeshFilter m_MeshFilter; 32 | private MeshRenderer m_MeshRenderer; 33 | 34 | void Start () { 35 | m_MeshRenderer = gameObject.GetComponent(); 36 | if (m_MeshRenderer == null) 37 | m_MeshRenderer = gameObject.AddComponent(); 38 | m_MeshFilter = gameObject.GetComponent(); 39 | if (m_MeshFilter == null) 40 | m_MeshFilter = gameObject.AddComponent(); 41 | 42 | m_waterBodyMesh = Utils.GenerateLiquidBodyMesh(width, length, depth, geometryCellSize); 43 | m_MeshFilter.sharedMesh = m_waterBodyMesh; 44 | m_MeshRenderer.sharedMaterial = material; 45 | 46 | //传入水体包围盒信息,用于计算水底光线追踪的范围 47 | Vector3 boundsMin = new Vector3(transform.position.x - width * 0.5f, transform.position.y - depth, 48 | transform.position.z - length * 0.5f); 49 | Vector3 boundsMax = new Vector3(transform.position.x + width * 0.5f, transform.position.y, 50 | transform.position.z + length * 0.5f); 51 | 52 | //传入水体平面用于获取水体表面法线,以计算折射光线 53 | Vector4 plane = new Vector4(0, 1, 0, Vector3.Dot(new Vector3(0, 1, 0), transform.position)); 54 | 55 | material.SetVector("_BoundsMin", boundsMin); 56 | material.SetVector("_BoundsMax", boundsMax); 57 | material.SetVector("_WaterPlane", plane); 58 | } 59 | 60 | void OnDrawGizmosSelected() 61 | { 62 | Utils.DrawWireCube(transform.position, transform.eulerAngles.y, width, length, -depth, 0, Color.yellow); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Scripts/WaterVolumeLightRenderer.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e9a33c18ad9bf4c4b8203a87743ab88f 3 | timeCreated: 1538705069 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 45c45b1b3397f0643b1b2501d5dc256c 3 | folderAsset: yes 4 | timeCreated: 1538662657 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/BlinnPhongUnderWater.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced '_Object2World' with 'unity_ObjectToWorld' 2 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 3 | 4 | Shader "Custom/BlinnPhongUnderWater" 5 | { 6 | Properties 7 | { 8 | _MainTex ("Texture", 2D) = "white" {} 9 | [Normal][NoScaleOffset]_BumpTex("BumpTex", 2D) = "bump" {} 10 | _SpecTex ("SpecTex", 2D) = "white" {} 11 | _AOTex ("AoTex", 2D) = "white" {} 12 | _SpecColor ("SpecCol", color) = (1,1,1,1) 13 | _Specular ("Specular", float) = 0 14 | _Gloss ("Gloss", float) = 0 15 | _GI ("GI", cube) = "" {} 16 | _GILod ("GILod", float) = 0 17 | _GIColor ("GIColor", color) = (0,0,0,1) 18 | _Range("Range", vector) = (0, 0, 0, 0) 19 | _ShallowColor("ShallowColor", color) = (1,1,1,1) 20 | _DeepColor("DeepColor", color) = (1,1,1,1) 21 | } 22 | SubShader 23 | { 24 | Tags { "RenderType"="Opaque" } 25 | 26 | Pass 27 | { 28 | CGPROGRAM 29 | #pragma vertex vert 30 | #pragma fragment frag 31 | #pragma multi_compile_fog 32 | 33 | #include "UnityCG.cginc" 34 | #include "Lighting.cginc" 35 | #include "Utils.cginc" 36 | 37 | struct v2f 38 | { 39 | float2 uv : TEXCOORD0; 40 | float2 aouv : TEXCOORD1; 41 | UNITY_FOG_COORDS(2) 42 | float4 vertex : SV_POSITION; 43 | L_SHADOWCOORDS(3, 4) 44 | float4 RT0 : TEXCOORD5; 45 | float4 RT1 : TEXCOORD6; 46 | float4 RT2 : TEXCOORD7; 47 | }; 48 | 49 | sampler2D _BumpTex; 50 | sampler2D _MainTex; 51 | sampler2D _SpecTex; 52 | sampler2D _AOTex; 53 | samplerCUBE _GI; 54 | float4 _MainTex_ST; 55 | 56 | float _Specular; 57 | half _Gloss; 58 | 59 | half4 _GIColor; 60 | half _GILod; 61 | 62 | half4 _ShallowColor; 63 | half4 _DeepColor; 64 | 65 | half4 _Range; 66 | 67 | 68 | v2f vert (appdata_full v) 69 | { 70 | v2f o; 71 | 72 | o.vertex = UnityObjectToClipPos(v.vertex); 73 | o.uv = TRANSFORM_TEX(v.texcoord, _MainTex); 74 | o.aouv = v.texcoord; 75 | UNITY_TRANSFER_FOG(o,o.vertex); 76 | L_TRANSFER_SHADOWCOORDS(v, o); 77 | 78 | float3 worldPos = mul(unity_ObjectToWorld, v.vertex); 79 | float3 worldNormal = UnityObjectToWorldNormal(v.normal); 80 | float3 worldTan = UnityObjectToWorldDir(v.tangent.xyz); 81 | float tanSign = v.tangent.w * unity_WorldTransformParams.w; 82 | float3 worldBinormal = cross(worldNormal, worldTan)*tanSign; 83 | o.RT0 = float4(worldTan.x, worldBinormal.x, worldNormal.x, worldPos.x); 84 | o.RT1 = float4(worldTan.y, worldBinormal.y, worldNormal.y, worldPos.y); 85 | o.RT2 = float4(worldTan.z, worldBinormal.z, worldNormal.z, worldPos.z); 86 | return o; 87 | } 88 | 89 | half4 frag (v2f i) : SV_Target 90 | { 91 | float3 worldPos = float3(i.RT0.w,i.RT1.w,i.RT2.w); 92 | float3 rnormal = UnpackNormal(tex2D(_BumpTex, i.uv)); 93 | float3 worldNormal = float3(dot(i.RT0.xyz, rnormal), dot(i.RT1.xyz, rnormal), dot(i.RT2.xyz, rnormal)); 94 | 95 | L_SHADOW_ATTEN(atten, i); 96 | 97 | float3 litDir = normalize(GetLightDirection(worldPos.xyz)); 98 | float3 viewDir = normalize(UnityWorldSpaceViewDir(worldPos.xyz)); 99 | float3 h = normalize(viewDir + litDir); 100 | float ndl = max(0, dot(worldNormal, litDir)); 101 | float spec = max(0, dot(worldNormal, h)); 102 | float4 gi = texCUBElod(_GI, float4(worldNormal, _GILod))+ _GIColor; 103 | 104 | float3 ao = tex2D(_AOTex, i.aouv).rgb; 105 | 106 | half4 col = tex2D(_MainTex, i.uv); 107 | 108 | float clipArea = ClipArea(worldPos.xyz); 109 | float3 shallCol = lerp(float3(1, 1, 1), _ShallowColor.rgb, (1.0 - saturate((worldPos.y - _Range.x) / _Range.y))*clipArea); 110 | float3 deepCol = lerp(float3(1, 1, 1), _DeepColor.rgb, (1.0 - saturate((worldPos.y - _Range.z) / _Range.w))*clipArea); 111 | float3 caustic = SampleCaustic(worldPos.xyz, clipArea); 112 | 113 | col.rgb *= ao* shallCol*deepCol; 114 | 115 | col.rgb *= UNITY_LIGHTMODEL_AMBIENT.rgb + (caustic*ndl + internalWorldLightColor.rgb* ndl*gi.rgb + _SpecColor.rgb * pow(spec, _Specular)*_Gloss*tex2D(_SpecTex, i.uv).rgb*internalWorldLightColor.rgb) *atten; 116 | 117 | UNITY_APPLY_FOG(i.fogCoord, col); 118 | return col; 119 | //return fixed4(depth, depth, depth, 1); 120 | } 121 | ENDCG 122 | } 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/BlinnPhongUnderWater.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 828878cdfb29a764ea366ff074ba5096 3 | timeCreated: 1538659554 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Caustic.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "Hidden/Caustic" 4 | { 5 | Properties 6 | { 7 | _Refract ("Refract", float) = 0 8 | } 9 | SubShader 10 | { 11 | Tags { "RenderType"="Opaque" } 12 | LOD 100 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "UnityCG.cginc" 21 | #include "Utils.cginc" 22 | 23 | struct appdata 24 | { 25 | float4 vertex : POSITION; 26 | }; 27 | 28 | struct v2f 29 | { 30 | float4 vertex : SV_POSITION; 31 | float2 oldPos : TEXCOORD1; 32 | float2 newPos : TEXCOORD2; 33 | }; 34 | 35 | half _Refract; 36 | 37 | v2f vert (appdata_full v) 38 | { 39 | v2f o; 40 | float3 normal = UnpackNormal(tex2Dlod(_LiquidNormalMap, float4(v.texcoord.xy, 0, 0))); 41 | 42 | o.oldPos = v.vertex.xz; 43 | v.vertex.xz += normal.xy*_Refract; 44 | o.newPos = v.vertex.xz; 45 | 46 | 47 | o.vertex = UnityObjectToClipPos(v.vertex); 48 | return o; 49 | } 50 | 51 | fixed4 frag (v2f i) : SV_Target 52 | { 53 | float oldArea = length(ddx(i.oldPos)) * length(ddy(i.oldPos)); 54 | float newArea = length(ddx(i.newPos)) * length(ddy(i.newPos)); 55 | 56 | float area = (oldArea / newArea) * 0.5; 57 | 58 | return float4(area, area, area, 1); 59 | } 60 | ENDCG 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Caustic.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c0645564eed73b14a99f16098d6c826e 3 | timeCreated: 1537879769 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Force.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/Force" 2 | { 3 | Properties 4 | { 5 | } 6 | SubShader 7 | { 8 | Tags { "RenderType"="Opaque" } 9 | 10 | Pass 11 | { 12 | cull front 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | #include "UnityCG.cginc" 18 | #include "Utils.cginc" 19 | 20 | struct appdata 21 | { 22 | float4 vertex : POSITION; 23 | }; 24 | 25 | struct v2f 26 | { 27 | float depth : TEXCOORD0; 28 | float4 vertex : SV_POSITION; 29 | }; 30 | 31 | float internal_Force; 32 | 33 | v2f vert (appdata v) 34 | { 35 | v2f o; 36 | o.vertex = UnityObjectToClipPos(v.vertex); 37 | o.depth = COMPUTE_DEPTH_01; 38 | return o; 39 | } 40 | 41 | fixed4 frag (v2f i) : SV_Target 42 | { 43 | return EncodeHeight(i.depth*internal_Force); 44 | } 45 | ENDCG 46 | } 47 | 48 | Pass 49 | { 50 | CGPROGRAM 51 | #pragma vertex vert 52 | #pragma fragment frag 53 | 54 | #include "UnityCG.cginc" 55 | 56 | float4 vert(float4 vertex:POSITION) : SV_POSITION 57 | { 58 | return UnityObjectToClipPos(vertex); 59 | } 60 | 61 | fixed4 frag(float4 i:SV_POSITION) : SV_Target 62 | { 63 | return fixed4(0, 0, 0, 1.0); 64 | } 65 | ENDCG 66 | } 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Force.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 7af47d919cf44034d82bdff1ba4015b0 3 | timeCreated: 1536213160 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/NormalGen.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/NormalGen" 2 | { 3 | Properties 4 | { 5 | _MainTex ("Texture", 2D) = "white" {} 6 | } 7 | SubShader 8 | { 9 | Cull Off ZWrite Off ZTest Always 10 | 11 | Pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | #include "UnityCG.cginc" 18 | #include "Utils.cginc" 19 | 20 | struct appdata 21 | { 22 | float4 vertex : POSITION; 23 | float2 uv : TEXCOORD0; 24 | }; 25 | 26 | struct v2f 27 | { 28 | float2 uv : TEXCOORD0; 29 | float4 vertex : SV_POSITION; 30 | }; 31 | 32 | v2f vert(appdata v) 33 | { 34 | v2f o; 35 | o.vertex = UnityObjectToClipPos(v.vertex); 36 | o.uv = v.uv; 37 | return o; 38 | } 39 | 40 | sampler2D _MainTex; 41 | float4 _MainTex_TexelSize; 42 | 43 | fixed4 frag(v2f i) : SV_Target 44 | { 45 | float lh = DecodeHeight(tex2D(_MainTex, i.uv + float2(-_MainTex_TexelSize.x, 0.0))); 46 | float rh = DecodeHeight(tex2D(_MainTex, i.uv + float2(_MainTex_TexelSize.x, 0.0))); 47 | float bh = DecodeHeight(tex2D(_MainTex, i.uv + float2(0.0, -_MainTex_TexelSize.y))); 48 | float th = DecodeHeight(tex2D(_MainTex, i.uv + float2(0.0, _MainTex_TexelSize.y))); 49 | 50 | //float3 va = normalize(float3(2.0, 0.0, rh - lh)); 51 | //float3 vb = normalize(float3(0.0, 2.0, th - bh)); 52 | 53 | float3 normal = normalize(float3(lh - rh, bh - th, 5.0*_MainTex_TexelSize.x)); 54 | //float3 normal = cross(va, vb); 55 | 56 | 57 | //return EncodeDepthNormal(ch, normal); 58 | #if defined(UNITY_NO_DXT5nm) 59 | return float4(normal*0.5 + 0.5, 1.0); 60 | #else 61 | #if UNITY_VERSION > 2018 62 | return float4(normal.x*0.5 + 0.5, normal.y*0.5 + 0.5, 0, 1); //2018修改了法线压缩方式,增加了一种BC5压缩 63 | #else 64 | return float4(0, normal.y*0.5 + 0.5, 0, normal.x*0.5 + 0.5); 65 | #endif 66 | #endif 67 | } 68 | ENDCG 69 | } 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/NormalGen.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 0365ce587bbfd9b44bb0fcf4912c3990 3 | timeCreated: 1539010672 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/ShadowMapRender.shader: -------------------------------------------------------------------------------- 1 | // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)' 2 | 3 | Shader "Hidden/ShadowMapRender" 4 | { 5 | Properties 6 | { 7 | } 8 | SubShader 9 | { 10 | Tags { "RenderType" = "Opaque" } 11 | Pass 12 | { 13 | CGPROGRAM 14 | #pragma vertex vert 15 | #pragma fragment frag 16 | 17 | #include "UnityCG.cginc" 18 | 19 | struct v2f 20 | { 21 | float4 vertex : SV_POSITION; 22 | float depth : TEXCOORD0; 23 | }; 24 | 25 | v2f vert (appdata_base v) 26 | { 27 | v2f o; 28 | o.vertex = UnityObjectToClipPos(v.vertex); 29 | o.depth = COMPUTE_DEPTH_01; 30 | return o; 31 | } 32 | 33 | fixed4 frag (v2f i) : SV_Target 34 | { 35 | fixed4 col = EncodeFloatRGBA(i.depth); 36 | return col; 37 | } 38 | ENDCG 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/ShadowMapRender.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 68f2839f207bb73469cf29b42878a116 3 | timeCreated: 1538659460 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 55a24332fd64e2949bf9eaf8bbb0e879 3 | folderAsset: yes 4 | timeCreated: 1538968245 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Test/TestGizmos.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/TestGizmos" 2 | { 3 | Properties 4 | { 5 | } 6 | SubShader 7 | { 8 | Tags { "RenderType"="Transparent" "Queue"="Transparent" } 9 | LOD 100 10 | 11 | Pass 12 | { 13 | cull off 14 | zwrite off 15 | ztest always 16 | blend srcalpha oneminussrcalpha 17 | CGPROGRAM 18 | #pragma vertex vert 19 | #pragma fragment frag 20 | 21 | #include "UnityCG.cginc" 22 | 23 | struct v2f 24 | { 25 | float4 color : COLOR; 26 | float4 vertex : SV_POSITION; 27 | }; 28 | 29 | v2f vert (float4 vertex:POSITION, float4 color:COLOR) 30 | { 31 | v2f o; 32 | o.vertex = UnityObjectToClipPos(vertex); 33 | o.color = color; 34 | return o; 35 | } 36 | 37 | fixed4 frag (v2f i) : SV_Target 38 | { 39 | return i.color; 40 | } 41 | ENDCG 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Test/TestGizmos.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 40256256841e8a649b9d66e3c44e426a 3 | timeCreated: 1538968251 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Utils.cginc: -------------------------------------------------------------------------------- 1 | #ifndef UTILS_CGINC 2 | #define UTILS_CGINC 3 | 4 | uniform float4 internalWorldLightPos; 5 | uniform float4 internalWorldLightColor; 6 | 7 | sampler2D internalShadowMap; 8 | float4x4 internalWorldLightMV; 9 | float4x4 internalWorldLightVP; 10 | float4 internalProjectionParams; 11 | float internalBias; 12 | 13 | float3 GetLightDirection(float3 worldPos) { 14 | if (internalWorldLightPos.w == 0) 15 | return -internalWorldLightPos.xyz; 16 | else 17 | return internalWorldLightPos.xyz - worldPos; 18 | } 19 | 20 | #define L_SHADOWCOORDS(n, m) float4 shadowProj:TEXCOORD##n;float shadowDepth:TEXCOORD##m; 21 | 22 | #define L_TRANSFER_SHADOWCOORDS(v, o) \ 23 | float4 cpos = mul(internalWorldLightMV, mul(unity_ObjectToWorld, v.vertex)); \ 24 | o.shadowProj = mul(internalWorldLightVP, cpos); \ 25 | float4 pj = o.shadowProj * 0.5f; \ 26 | pj.xy = float2(pj.x, pj.y) + pj.w; \ 27 | pj.zw = o.shadowProj.zw; \ 28 | o.shadowProj = pj; \ 29 | o.shadowDepth = -cpos.z*internalProjectionParams.w 30 | 31 | #define L_SHADOW_ATTEN(atten, input) \ 32 | float4 shadow = tex2Dproj(internalShadowMap, input.shadowProj); \ 33 | float shadowdepth = DecodeFloatRGBA(shadow); \ 34 | float shadowcol = step(input.shadowDepth - internalBias, shadowdepth)*0.7 + 0.3; \ 35 | float2 shadowatten = saturate((0.5 - abs(input.shadowProj.xy / input.shadowProj.w - 0.5)) / (1 - internalWorldLightColor.a)); \ 36 | float atten = shadowatten.x*shadowatten.y*shadowcol 37 | 38 | #define L_SHADOW_ATTEN_REFRACT(atten, input, refract) \ 39 | float2 sduv = input.shadowProj.xy/input.shadowProj.w + refract; \ 40 | float4 shadow = tex2D(internalShadowMap, sduv); \ 41 | float shadowdepth = DecodeFloatRGBA(shadow); \ 42 | float shadowcol = step(input.shadowDepth - internalBias, shadowdepth)*0.7 + 0.3; \ 43 | float2 shadowatten = saturate((0.5 - abs(input.shadowProj.xy / input.shadowProj.w - 0.5)) / (1 - internalWorldLightColor.a)); \ 44 | float atten = shadowatten.x*shadowatten.y*shadowcol 45 | 46 | float SampleShadow(float3 worldPos) { 47 | float4 cpos = mul(internalWorldLightMV, float4(worldPos, 1.0f)); 48 | float4 shadowProj = mul(internalWorldLightVP, cpos); 49 | float4 pj = shadowProj * 0.5f; 50 | pj.xy = float2(pj.x, pj.y) + pj.w; 51 | pj.zw = shadowProj.zw; 52 | shadowProj = pj; 53 | float depth = -cpos.z*internalProjectionParams.w; 54 | float4 shadow = tex2Dproj(internalShadowMap, shadowProj); 55 | float shadowdepth = DecodeFloatRGBA(shadow); 56 | float shadowcol = step(depth - internalBias, shadowdepth); 57 | //float2 shadowatten = saturate((0.5 - abs(shadowProj.xy / shadowProj.w - 0.5)) / (1 - internalWorldLightColor.a)); 58 | //float atten = shadowatten.x*shadowatten.y*shadowcol; 59 | return shadowcol; 60 | } 61 | 62 | sampler2D _LiquidHeightMap; 63 | sampler2D _LiquidNormalMap; 64 | sampler2D _LiquidReflectMap; 65 | sampler2D _CausticMap; 66 | 67 | float4 _CausticPlane; 68 | float4 _CausticRange; 69 | float2 _CausticDepthRange; 70 | float _CausticIntensity; 71 | 72 | float4 _LiquidArea; 73 | 74 | float ClipArea(float3 worldPos) { 75 | /*if (worldPos.x > _LiquidArea.x&&worldPos.x < _LiquidArea.z) 76 | return 0; 77 | return 1;*/ 78 | 79 | float x = 1.0 - step(_LiquidArea.x, worldPos.x)*step(worldPos.x, _LiquidArea.z); 80 | float y = 1.0 - step(_LiquidArea.y, worldPos.z)*step(worldPos.z, _LiquidArea.w); 81 | return 1.0 - saturate(x + y); 82 | //float x = step(_LiquidArea.z, step(worldPos.x, _LiquidArea.x)); 83 | //return x; 84 | } 85 | 86 | float3 SampleCaustic(float3 worldPos, float clipArea) { 87 | float3 lightDir = GetLightDirection(worldPos); 88 | float3 hitPos = worldPos + lightDir * (_CausticPlane.w - dot(worldPos, _CausticPlane.xyz) / dot(lightDir, _CausticPlane.xyz)); 89 | float2 uv = (hitPos.xz - _CausticRange.xy) / _CausticRange.zw*0.5 + 0.5; 90 | float fade = 1.0 - saturate((worldPos.y - _CausticDepthRange.x) / _CausticDepthRange.y); 91 | float3 caustic = tex2D(_CausticMap, uv).rgb - 0.5; 92 | if (uv.x < 0 || uv.x>1 || uv.y < 0 || uv.y>1) 93 | return 0; 94 | return caustic*clipArea*fade*_CausticIntensity; 95 | } 96 | 97 | float4 EncodeHeight(float height) { 98 | float2 rg = EncodeFloatRG(height >= 0 ? height : 0); 99 | float2 ba = EncodeFloatRG(height < 0 ? -height : 0); 100 | 101 | return float4(rg, ba); 102 | } 103 | 104 | float DecodeHeight(float4 rgba) { 105 | float d1 = DecodeFloatRG(rgba.rg); 106 | float d2 = DecodeFloatRG(rgba.ba); 107 | 108 | if (d1 >= d2) 109 | return d1; 110 | else 111 | return -d2; 112 | } 113 | 114 | #endif -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Utils.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 016c1e95e2141044190db2169b20fd6d 3 | timeCreated: 1537796949 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Water.shader: -------------------------------------------------------------------------------- 1 | Shader "Custom/Water" 2 | { 3 | Properties 4 | { 5 | _Specular("Specular", float) = 0 6 | _Gloss("Gloss", float) = 0 7 | _Refract("Refract", float) = 0 8 | _Height ("Height(position, color)", vector) = (0.36, 0, 0, 0) 9 | _Fresnel ("Fresnel", float) = 3.0 10 | _BaseColor ("BaseColor", color) = (1,1,1,1) 11 | _WaterColor ("WaterColor", color) = (1,1,1,1) 12 | } 13 | SubShader 14 | { 15 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" } 16 | LOD 100 17 | 18 | GrabPass {} 19 | 20 | Pass 21 | { 22 | zwrite off 23 | blend srcalpha oneminussrcalpha 24 | CGPROGRAM 25 | #pragma vertex vert 26 | #pragma fragment frag 27 | #pragma multi_compile_fog 28 | 29 | #include "UnityCG.cginc" 30 | #include "Utils.cginc" 31 | #include "Lighting.cginc" 32 | 33 | struct v2f 34 | { 35 | float2 uv : TEXCOORD0; 36 | UNITY_FOG_COORDS(1) 37 | float4 proj0 : TEXCOORD2; 38 | float4 proj1 : TEXCOORD3; 39 | float4 vertex : SV_POSITION; 40 | float4 TW0 : TEXCOORD4; 41 | float4 TW1 : TEXCOORD5; 42 | float4 TW2 : TEXCOORD6; 43 | L_SHADOWCOORDS(7, 8) 44 | }; 45 | 46 | sampler2D _GrabTexture; 47 | 48 | sampler2D_float _CameraDepthTexture; 49 | 50 | half _Specular; 51 | half _Gloss; 52 | 53 | half4 _BaseColor; 54 | half4 _WaterColor; 55 | 56 | half _Refract; 57 | 58 | half _Fresnel; 59 | 60 | float2 _Height; 61 | 62 | v2f vert (appdata_full v) 63 | { 64 | v2f o; 65 | float4 projPos = UnityObjectToClipPos(v.vertex); 66 | 67 | o.proj0 = ComputeGrabScreenPos(projPos); 68 | o.proj1 = ComputeScreenPos(projPos); 69 | 70 | float height = DecodeHeight(tex2Dlod(_LiquidHeightMap, float4(v.texcoord.xy,0,0))); 71 | v.vertex.y += height*_Height.x; 72 | o.uv = v.texcoord; 73 | UNITY_TRANSFER_FOG(o,o.vertex); 74 | o.vertex = UnityObjectToClipPos(v.vertex); 75 | 76 | COMPUTE_EYEDEPTH(o.proj0.z); 77 | 78 | L_TRANSFER_SHADOWCOORDS(v, o); 79 | 80 | float3 worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; 81 | float3 worldNormal = UnityObjectToWorldNormal(v.normal); 82 | float3 worldTan = UnityObjectToWorldDir(v.tangent.xyz); 83 | float tanSign = v.tangent.w * unity_WorldTransformParams.w; 84 | float3 worldBinormal = cross(worldNormal, worldTan)*tanSign; 85 | o.TW0 = float4(worldTan.x, worldBinormal.x, worldNormal.x, worldPos.x); 86 | o.TW1 = float4(worldTan.y, worldBinormal.y, worldNormal.y, worldPos.y); 87 | o.TW2 = float4(worldTan.z, worldBinormal.z, worldNormal.z, worldPos.z); 88 | 89 | return o; 90 | } 91 | 92 | half3 WaterColor(float3 refractColor, float3 reflectColor, float3 worldPos, float height, float3 worldNormal, float3 lightDir, float3 viewDir) { 93 | float f = pow(clamp(1.0 - dot(worldNormal, viewDir), 0.0, 1.0), _Fresnel) * 0.65; 94 | float3 viewDis = -UnityWorldSpaceViewDir(worldPos); 95 | 96 | float3 refraccol = _BaseColor.rgb*refractColor + pow(dot(worldNormal, lightDir) * 0.4 + 0.6, 80.0) * _WaterColor.rgb * 0.12; 97 | 98 | float3 color = lerp(refraccol, reflectColor, f); 99 | 100 | float atten = max(1.0 - dot(viewDis, viewDis) * 0.001, 0.0); 101 | color += _WaterColor.rgb*refractColor * (height*_Height.y) * 0.18 * atten; 102 | 103 | return color; 104 | } 105 | 106 | 107 | half4 frag (v2f i) : SV_Target 108 | { 109 | float depth = LinearEyeDepth(tex2Dproj(_CameraDepthTexture, i.proj1)); 110 | float deltaDepth = depth - i.proj0.z; 111 | 112 | 113 | float3 normal = UnpackNormal(tex2D(_LiquidNormalMap, i.uv)); 114 | 115 | L_SHADOW_ATTEN_REFRACT(atten, i, (normal.xy*_Refract)); 116 | 117 | float height = DecodeHeight(tex2D(_LiquidHeightMap, i.uv)); 118 | 119 | float3 worldNormal = float3(dot(i.TW0.xyz, normal), dot(i.TW1.xyz, normal), dot(i.TW2.xyz, normal)); 120 | float3 worldPos = float3(i.TW0.w, i.TW1.w, i.TW2.w); 121 | 122 | float3 lightDir = normalize(GetLightDirection(worldPos.xyz)); 123 | float3 viewDir = normalize(UnityWorldSpaceViewDir(worldPos)); 124 | 125 | float2 projUv = i.proj0.xy / i.proj0.w + normal.xy*_Refract; 126 | half4 col = tex2D(_GrabTexture, projUv); 127 | half4 reflcol = tex2D(_LiquidReflectMap, projUv); 128 | 129 | col.rgb = WaterColor(col.rgb, reflcol.rgb, worldPos, height, worldNormal, lightDir, viewDir); 130 | 131 | float3 hdir = normalize(lightDir + viewDir); 132 | 133 | float ndh = max(0, dot(worldNormal, hdir)); 134 | 135 | col.rgb += internalWorldLightColor.rgb * pow(ndh, _Specular*128.0) * _Gloss*atten; 136 | 137 | UNITY_APPLY_FOG(i.fogCoord, col); 138 | 139 | col.a = 1.0; 140 | return col; 141 | } 142 | ENDCG 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/Water.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5fadd089e69595448f7ff36c7aaa2a9 3 | timeCreated: 1536158748 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/WaterBody.shader: -------------------------------------------------------------------------------- 1 | Shader "Unlit/WaterBody" 2 | { 3 | Properties 4 | { 5 | _BoundsMin("BoundsMin", vector) = (0,0,0,0) 6 | _BoundsMax("BoundsMax", vector) = (0,0,0,0) 7 | _Height("Height", float) = 0 8 | _FilterColor ("FilterColor", color) = (1,1,1,1) 9 | _LightIntensity ("Intensity", float) = 1 10 | } 11 | SubShader 12 | { 13 | Tags { "RenderType" = "Transparent" "Queue" = "Transparent" "IgnoreProjector" = "true" } 14 | LOD 100 15 | 16 | Pass 17 | { 18 | zwrite off 19 | blend srcalpha one 20 | colormask rgb 21 | CGPROGRAM 22 | #pragma vertex vert 23 | #pragma fragment frag 24 | #pragma multi_compile_fog 25 | 26 | #define RAY_STEP 64 27 | 28 | #include "UnityCG.cginc" 29 | #include "Utils.cginc" 30 | 31 | float3 _BoundsMin; 32 | float3 _BoundsMax; 33 | float4 _WaterPlane; 34 | 35 | float4 _FilterColor; 36 | float _LightIntensity; 37 | 38 | struct appdata { 39 | float4 vertex:POSITION; 40 | float2 texcoord:TEXCOORD0; 41 | float4 color:COLOR; 42 | }; 43 | 44 | struct v2f 45 | { 46 | UNITY_FOG_COORDS(0) 47 | float4 vertex : SV_POSITION; 48 | float3 worldPos : TEXCOORD1; 49 | }; 50 | 51 | float _Height; 52 | 53 | v2f vert (appdata v) 54 | { 55 | v2f o; 56 | float height = DecodeHeight(tex2Dlod(_LiquidHeightMap, float4(v.texcoord.xy, 0, 0))); 57 | v.vertex.y += height * _Height * (1 - v.color.a); 58 | 59 | o.worldPos = mul(unity_ObjectToWorld, v.vertex).xyz; 60 | o.vertex = UnityObjectToClipPos(v.vertex); 61 | UNITY_TRANSFER_FOG(o,o.vertex); 62 | return o; 63 | } 64 | 65 | float ClipInBounds(float3 worldPos) { 66 | if (worldPos.x < _BoundsMin.x || worldPos.x > _BoundsMax.x) 67 | return 0; 68 | if (worldPos.y < _BoundsMin.y || worldPos.y > _BoundsMax.y) 69 | return 0; 70 | if (worldPos.z < _BoundsMin.z || worldPos.z > _BoundsMax.z) 71 | return 0; 72 | return 1; 73 | } 74 | 75 | float SampleWaterNormalDotLightDir(float3 worldPos) { 76 | float3 boundSize = _BoundsMax - _BoundsMin; 77 | 78 | float3 lightDir = GetLightDirection(worldPos); 79 | float3 hitPos = worldPos + lightDir * (_WaterPlane.w - dot(worldPos, _WaterPlane.xyz) / dot(lightDir, _WaterPlane.xyz)); 80 | float2 uv = (hitPos.xz - _BoundsMin.xz) / boundSize.xz; 81 | float3 normal = UnpackNormal(tex2D(_LiquidNormalMap, uv)); 82 | return max(0, dot(normal, -lightDir)); 83 | } 84 | 85 | float4 frag (v2f i) : SV_Target 86 | { 87 | float3 boundSize = _BoundsMax - _BoundsMin; 88 | float delta = max(boundSize.x, max(boundSize.y, boundSize.z)) / RAY_STEP; 89 | float coldelta = 1.0 / RAY_STEP * _LightIntensity; 90 | 91 | float3 viewDir = normalize(-UnityWorldSpaceViewDir(i.worldPos)); 92 | 93 | float4 col = float4(0, 0, 0, 0); 94 | 95 | for (float k = 0; k < RAY_STEP; k++) { 96 | float3 wp = i.worldPos + viewDir * k * delta; 97 | float atten = SampleShadow(wp); 98 | float clipv = ClipInBounds(wp); 99 | 100 | float ndl = SampleWaterNormalDotLightDir(wp); 101 | 102 | col += _FilterColor * coldelta * atten * clipv*ndl; 103 | } 104 | 105 | return col; 106 | } 107 | ENDCG 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/WaterBody.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bdaea2ea4c7a7f44b8ca0ea31c6e803c 3 | timeCreated: 1538708230 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/WaveEquationGen.shader: -------------------------------------------------------------------------------- 1 | Shader "Hidden/WaveEquationGen" 2 | { 3 | Properties 4 | { 5 | _MainTex ("MainTexture", 2D) = "white" {} 6 | _Mask ("Mask", 2D) = "white" {} 7 | _PreTex("PreTex", 2D) = "white" {} 8 | _WaveParams("WaveParams", vector) = (0,0,0,0) 9 | } 10 | SubShader 11 | { 12 | Cull Off ZWrite Off ZTest Always 13 | 14 | Pass 15 | { 16 | CGPROGRAM 17 | #pragma vertex vert 18 | #pragma fragment frag 19 | 20 | #include "UnityCG.cginc" 21 | #include "Utils.cginc" 22 | 23 | struct appdata 24 | { 25 | float4 vertex : POSITION; 26 | float2 uv : TEXCOORD0; 27 | }; 28 | 29 | struct v2f 30 | { 31 | float2 uv : TEXCOORD0; 32 | float4 vertex : SV_POSITION; 33 | }; 34 | 35 | v2f vert (appdata v) 36 | { 37 | v2f o; 38 | o.vertex = UnityObjectToClipPos(v.vertex); 39 | o.uv = v.uv; 40 | return o; 41 | } 42 | 43 | sampler2D _MainTex; 44 | sampler2D _PreTex; 45 | 46 | sampler2D _Mask; 47 | 48 | half4 _WaveParams; 49 | 50 | fixed4 frag (v2f i) : SV_Target 51 | { 52 | float cur = _WaveParams.x*DecodeHeight(tex2D(_MainTex, i.uv)); 53 | fixed mask = tex2D(_Mask, i.uv).r; 54 | 55 | float rg = _WaveParams.z*(DecodeHeight(tex2D(_MainTex, i.uv + float2(_WaveParams.w, 0))) + DecodeHeight(tex2D(_MainTex, i.uv + float2(-_WaveParams.w,0))) 56 | + DecodeHeight(tex2D(_MainTex, i.uv + float2(0, _WaveParams.w))) + DecodeHeight(tex2D(_MainTex, i.uv + float2(0,-_WaveParams.w)))); 57 | 58 | float pre = _WaveParams.y*DecodeHeight(tex2D(_PreTex, i.uv)); 59 | 60 | cur += (rg + pre) * mask; 61 | 62 | cur *= 0.96*mask; 63 | 64 | 65 | return EncodeHeight(cur); 66 | } 67 | ENDCG 68 | } 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Assets/LiquidSimulator/Shaders/WaveEquationGen.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c19fcb77d59c1014983ade3875857ff4 3 | timeCreated: 1516004345 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Doc/preview.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview.gif -------------------------------------------------------------------------------- /Doc/preview1.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview1.PNG -------------------------------------------------------------------------------- /Doc/preview1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview1.gif -------------------------------------------------------------------------------- /Doc/preview2.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview2.PNG -------------------------------------------------------------------------------- /Doc/preview3.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview3.PNG -------------------------------------------------------------------------------- /Doc/preview4.PNG: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/Doc/preview4.PNG -------------------------------------------------------------------------------- /ProjectSettings/AudioManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/AudioManager.asset -------------------------------------------------------------------------------- /ProjectSettings/ClusterInputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/ClusterInputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/DynamicsManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/DynamicsManager.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorBuildSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/EditorBuildSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/EditorSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/EditorSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/GraphicsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/GraphicsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/InputManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/InputManager.asset -------------------------------------------------------------------------------- /ProjectSettings/NavMeshAreas.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/NavMeshAreas.asset -------------------------------------------------------------------------------- /ProjectSettings/NetworkManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/NetworkManager.asset -------------------------------------------------------------------------------- /ProjectSettings/Physics2DSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/Physics2DSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/ProjectSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/ProjectVersion.txt: -------------------------------------------------------------------------------- 1 | m_EditorVersion: 5.6.3p2 2 | -------------------------------------------------------------------------------- /ProjectSettings/QualitySettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/QualitySettings.asset -------------------------------------------------------------------------------- /ProjectSettings/TagManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/TagManager.asset -------------------------------------------------------------------------------- /ProjectSettings/TimeManager.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/TimeManager.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityAdsSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/UnityAdsSettings.asset -------------------------------------------------------------------------------- /ProjectSettings/UnityConnectSettings.asset: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/AsehesL/UnityWaveEquation/db745a18c4d0547996806022ea61b62633a60260/ProjectSettings/UnityConnectSettings.asset -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UnityWaveEquation 2 | 3 | Unity下实现二维波方程可互动水面+实时焦散+实时水下体积光效果: 4 | 5 | 该Demo为技术演示Demo,仅用于参考与学习。 6 | 7 | 更多内容欢迎博客留言:http://www.lsngo.net/ 8 | 9 | ### 效果演示: 10 | 11 | ![preview2](Doc/preview.gif) 12 | 13 | ![preview2](Doc/preview1.gif) 14 | 15 | #### 交互水域: 16 | 17 | ![preview2](Doc/preview2.PNG) 18 | 19 | #### 焦散: 20 | 21 | ![preview4](Doc/preview4.PNG) 22 | 23 | #### 体积光: 24 | 25 | ![preview3](Doc/preview3.PNG) --------------------------------------------------------------------------------