diff --git a/Assets/Test/test.meta b/Assets/Test/Wind.meta similarity index 100% rename from Assets/Test/test.meta rename to Assets/Test/Wind.meta diff --git a/Assets/Test/test/Test_wave_anim_WaveAnimTest.mat b/Assets/Test/Wind/Test_wave_anim_WaveAnimTest.mat similarity index 85% rename from Assets/Test/test/Test_wave_anim_WaveAnimTest.mat rename to Assets/Test/Wind/Test_wave_anim_WaveAnimTest.mat index 0c087b5..7ea7b79 100644 --- a/Assets/Test/test/Test_wave_anim_WaveAnimTest.mat +++ b/Assets/Test/Wind/Test_wave_anim_WaveAnimTest.mat @@ -24,6 +24,10 @@ Material: m_SavedProperties: serializedVersion: 3 m_TexEnvs: + - _Texture2D: + m_Texture: {fileID: 2800000, guid: 016ab36f33e35487bb91a3712c78b36e, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} - unity_Lightmaps: m_Texture: {fileID: 0} m_Scale: {x: 1, y: 1} @@ -40,10 +44,10 @@ Material: m_Floats: - _QueueControl: 0 - _QueueOffset: 0 - - _WindAmplitude: 0 - - _WindSpeed: 0 + - _WindAmplitude: 0.5 + - _WindSpeed: 0.1 m_Colors: - - _Wind: {r: 0, g: 0, b: 0, a: 0} + - _Wind: {r: 0, g: 0, b: 0, a: 1} m_BuildTextureStacks: [] --- !u!114 &291855134940589853 MonoBehaviour: diff --git a/Assets/Test/test/Test_wave_anim_WaveAnimTest.mat.meta b/Assets/Test/Wind/Test_wave_anim_WaveAnimTest.mat.meta similarity index 100% rename from Assets/Test/test/Test_wave_anim_WaveAnimTest.mat.meta rename to Assets/Test/Wind/Test_wave_anim_WaveAnimTest.mat.meta diff --git a/Assets/Test/test/WaveAnimTest.shadergraph b/Assets/Test/Wind/WaveAnimTest.shadergraph similarity index 83% rename from Assets/Test/test/WaveAnimTest.shadergraph rename to Assets/Test/Wind/WaveAnimTest.shadergraph index 850ff10..88340e6 100644 --- a/Assets/Test/test/WaveAnimTest.shadergraph +++ b/Assets/Test/Wind/WaveAnimTest.shadergraph @@ -27,12 +27,6 @@ { "m_Id": "0943fe63088d42efa041e455f21e71d2" }, - { - "m_Id": "ea742361e9744acb8cd31aa4949b4301" - }, - { - "m_Id": "b952358911ea49fb8f07a4d4cfc07c41" - }, { "m_Id": "e840963ab3d244ffaa6bf841a0301395" }, @@ -67,10 +61,7 @@ "m_Id": "371efd375f804703bc60c3816f4d04c7" }, { - "m_Id": "add0750df8c14705991461537098d01f" - }, - { - "m_Id": "c62ea57a43424109b96fc7522d4c2ac3" + "m_Id": "2449ef89a25342508eabaf32b84f3a91" } ], "m_GroupDatas": [], @@ -93,13 +84,13 @@ { "m_OutputSlot": { "m_Node": { - "m_Id": "2703a6f6f3bf44a19836f57c9a4b35f3" + "m_Id": "2803cfec9f194fb5974e8777c214b995" }, "m_SlotId": 0 }, "m_InputSlot": { "m_Node": { - "m_Id": "c62ea57a43424109b96fc7522d4c2ac3" + "m_Id": "e840963ab3d244ffaa6bf841a0301395" }, "m_SlotId": 0 } @@ -215,20 +206,6 @@ }, "m_SlotId": 0 } - }, - { - "m_OutputSlot": { - "m_Node": { - "m_Id": "c62ea57a43424109b96fc7522d4c2ac3" - }, - "m_SlotId": 4 - }, - "m_InputSlot": { - "m_Node": { - "m_Id": "e840963ab3d244ffaa6bf841a0301395" - }, - "m_SlotId": 0 - } } ], "m_VertexContext": { @@ -239,12 +216,6 @@ "m_Blocks": [ { "m_Id": "0943fe63088d42efa041e455f21e71d2" - }, - { - "m_Id": "ea742361e9744acb8cd31aa4949b4301" - }, - { - "m_Id": "b952358911ea49fb8f07a4d4cfc07c41" } ] }, @@ -261,7 +232,7 @@ "m_Id": "371efd375f804703bc60c3816f4d04c7" }, { - "m_Id": "add0750df8c14705991461537098d01f" + "m_Id": "2449ef89a25342508eabaf32b84f3a91" } ] }, @@ -436,6 +407,40 @@ "m_SupportVFX": false } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.BlockNode", + "m_ObjectId": "2449ef89a25342508eabaf32b84f3a91", + "m_Group": { + "m_Id": "" + }, + "m_Name": "SurfaceDescription.AlphaClipThreshold", + "m_DrawState": { + "m_Expanded": true, + "m_Position": { + "serializedVersion": "2", + "x": 0.0, + "y": 0.0, + "width": 0.0, + "height": 0.0 + } + }, + "m_Slots": [ + { + "m_Id": "f341a428b0504d3db00746f3c6e989d0" + } + ], + "synonyms": [], + "m_Precision": 0, + "m_PreviewExpanded": true, + "m_DismissedVersion": 0, + "m_PreviewMode": 0, + "m_CustomColors": { + "m_SerializableColors": [] + }, + "m_SerializedDescriptor": "SurfaceDescription.AlphaClipThreshold" +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.VertexColorNode", @@ -729,7 +734,7 @@ "m_CustomColors": { "m_SerializableColors": [] }, - "m_Space": 2 + "m_Space": 0 } { @@ -747,21 +752,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", - "m_ObjectId": "55e7ed677b2f43ff972e2ba047fff85d", - "m_Id": 3, - "m_DisplayName": "B", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "B", - "m_StageCapability": 3, - "m_Value": 0.0, - "m_DefaultValue": 0.0, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", @@ -838,30 +828,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.NormalMaterialSlot", - "m_ObjectId": "61e22519e853484aaf32f71f2870d0e8", - "m_Id": 0, - "m_DisplayName": "Normal", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "Normal", - "m_StageCapability": 1, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_Labels": [], - "m_Space": 0 -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -1027,30 +993,6 @@ } } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.DynamicVectorMaterialSlot", - "m_ObjectId": "8fd4b67b566a41a8b0d6415f6ea4fc2d", - "m_Id": 0, - "m_DisplayName": "In", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "In", - "m_StageCapability": 3, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - "w": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0, - "w": 0.0 - } -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.PropertyNode", @@ -1108,21 +1050,6 @@ "m_ObjectId": "9be54a1b27b54d5590cdb2b8c4313bdf" } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", - "m_ObjectId": "a1b6d64974c6499fa66d5d9291d491de", - "m_Id": 1, - "m_DisplayName": "R", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "R", - "m_StageCapability": 3, - "m_Value": 0.0, - "m_DefaultValue": 0.0, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.PropertyNode", @@ -1195,21 +1122,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", - "m_ObjectId": "a7a2f25f3c1d44f48f90f2bf7d23d966", - "m_Id": 0, - "m_DisplayName": "Alpha Clip Threshold", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "AlphaClipThreshold", - "m_StageCapability": 2, - "m_Value": 0.5, - "m_DefaultValue": 0.5, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -1250,40 +1162,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.BlockNode", - "m_ObjectId": "add0750df8c14705991461537098d01f", - "m_Group": { - "m_Id": "" - }, - "m_Name": "SurfaceDescription.AlphaClipThreshold", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 0.0, - "y": 0.0, - "width": 0.0, - "height": 0.0 - } - }, - "m_Slots": [ - { - "m_Id": "a7a2f25f3c1d44f48f90f2bf7d23d966" - } - ], - "synonyms": [], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_DismissedVersion": 0, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - }, - "m_SerializedDescriptor": "SurfaceDescription.AlphaClipThreshold" -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.SamplerStateMaterialSlot", @@ -1322,55 +1200,6 @@ "m_Labels": [] } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.BlockNode", - "m_ObjectId": "b952358911ea49fb8f07a4d4cfc07c41", - "m_Group": { - "m_Id": "" - }, - "m_Name": "VertexDescription.Tangent", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 0.0, - "y": 0.0, - "width": 0.0, - "height": 0.0 - } - }, - "m_Slots": [ - { - "m_Id": "dd86009a27bd487989a74d81707f35d2" - } - ], - "synonyms": [], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_DismissedVersion": 0, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - }, - "m_SerializedDescriptor": "VertexDescription.Tangent" -} - -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", - "m_ObjectId": "bcb3b318c9974741b0b5d7948559d4b7", - "m_Id": 2, - "m_DisplayName": "G", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "G", - "m_StageCapability": 3, - "m_Value": 0.0, - "m_DefaultValue": 0.0, - "m_Labels": [] -} - { "m_SGVersion": 1, "m_Type": "UnityEditor.ShaderGraph.PositionNode", @@ -1408,68 +1237,6 @@ "m_PositionSource": 0 } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.SplitNode", - "m_ObjectId": "c62ea57a43424109b96fc7522d4c2ac3", - "m_Group": { - "m_Id": "" - }, - "m_Name": "Split", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 15.0, - "y": 674.0, - "width": 120.0, - "height": 149.0 - } - }, - "m_Slots": [ - { - "m_Id": "8fd4b67b566a41a8b0d6415f6ea4fc2d" - }, - { - "m_Id": "a1b6d64974c6499fa66d5d9291d491de" - }, - { - "m_Id": "bcb3b318c9974741b0b5d7948559d4b7" - }, - { - "m_Id": "55e7ed677b2f43ff972e2ba047fff85d" - }, - { - "m_Id": "c9444fdf7967477a941288e2f10128af" - } - ], - "synonyms": [ - "separate" - ], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_DismissedVersion": 0, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - } -} - -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", - "m_ObjectId": "c9444fdf7967477a941288e2f10128af", - "m_Id": 4, - "m_DisplayName": "A", - "m_SlotType": 1, - "m_Hidden": false, - "m_ShaderOutputName": "A", - "m_StageCapability": 3, - "m_Value": 0.0, - "m_DefaultValue": 0.0, - "m_Labels": [] -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Texture2DMaterialSlot", @@ -1513,30 +1280,6 @@ "m_DefaultType": 0 } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.TangentMaterialSlot", - "m_ObjectId": "dd86009a27bd487989a74d81707f35d2", - "m_Id": 0, - "m_DisplayName": "Tangent", - "m_SlotType": 0, - "m_Hidden": false, - "m_ShaderOutputName": "Tangent", - "m_StageCapability": 1, - "m_Value": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_DefaultValue": { - "x": 0.0, - "y": 0.0, - "z": 0.0 - }, - "m_Labels": [], - "m_Space": 0 -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Texture2DInputMaterialSlot", @@ -1589,40 +1332,6 @@ "m_SerializedDescriptor": "SurfaceDescription.BaseColor" } -{ - "m_SGVersion": 0, - "m_Type": "UnityEditor.ShaderGraph.BlockNode", - "m_ObjectId": "ea742361e9744acb8cd31aa4949b4301", - "m_Group": { - "m_Id": "" - }, - "m_Name": "VertexDescription.Normal", - "m_DrawState": { - "m_Expanded": true, - "m_Position": { - "serializedVersion": "2", - "x": 0.0, - "y": 0.0, - "width": 0.0, - "height": 0.0 - } - }, - "m_Slots": [ - { - "m_Id": "61e22519e853484aaf32f71f2870d0e8" - } - ], - "synonyms": [], - "m_Precision": 0, - "m_PreviewExpanded": true, - "m_DismissedVersion": 0, - "m_PreviewMode": 0, - "m_CustomColors": { - "m_SerializableColors": [] - }, - "m_SerializedDescriptor": "VertexDescription.Normal" -} - { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", @@ -1638,6 +1347,21 @@ "m_Labels": [] } +{ + "m_SGVersion": 0, + "m_Type": "UnityEditor.ShaderGraph.Vector1MaterialSlot", + "m_ObjectId": "f341a428b0504d3db00746f3c6e989d0", + "m_Id": 0, + "m_DisplayName": "Alpha Clip Threshold", + "m_SlotType": 0, + "m_Hidden": false, + "m_ShaderOutputName": "AlphaClipThreshold", + "m_StageCapability": 2, + "m_Value": 0.5, + "m_DefaultValue": 0.5, + "m_Labels": [] +} + { "m_SGVersion": 0, "m_Type": "UnityEditor.ShaderGraph.Vector3MaterialSlot", diff --git a/Assets/Test/test/WaveAnimTest.shadergraph.meta b/Assets/Test/Wind/WaveAnimTest.shadergraph.meta similarity index 100% rename from Assets/Test/test/WaveAnimTest.shadergraph.meta rename to Assets/Test/Wind/WaveAnimTest.shadergraph.meta diff --git a/Assets/Test/test/WindAnim.hlsl b/Assets/Test/Wind/WindAnim.hlsl similarity index 69% rename from Assets/Test/test/WindAnim.hlsl rename to Assets/Test/Wind/WindAnim.hlsl index c075296..acd3b2b 100644 --- a/Assets/Test/test/WindAnim.hlsl +++ b/Assets/Test/Wind/WindAnim.hlsl @@ -2,20 +2,16 @@ #ifndef WIND_ANIM #define WIND_ANIM -// SmoothTriangleWave function -inline float SmoothTriangleWave(float x) -{ - // 将输入值限制在 [0, 1] 范围内,使用 frac 函数保证值是周期性的 - x = frac(x); - - // 使用三角函数生成平滑的波形,注意:frac(x) 生成的是 [0, 1] 之间的值 - return 1.0 - abs(2.0 * x - 1.0); // 生成平滑的三角波 +inline float4 SmoothCurve( float4 x ) { + return x * x *( 3.0 - 2.0 * x ); } -// SmoothTriangleWave function for a 4-component vector -inline float4 SmoothTriangleWave(float4 x) -{ - return float4(SmoothTriangleWave(x.x), SmoothTriangleWave(x.y), SmoothTriangleWave(x.z), SmoothTriangleWave(x.w)); +inline float4 TriangleWave( float4 x ) { + return abs( frac( x + 0.5 ) * 2.0 - 1.0 ); +} + +inline float4 SmoothTriangleWave( float4 x ) { + return SmoothCurve( TriangleWave( x ) ); } inline void WindVert_float(float4 pos, float3 normal, float3 vertColor, float4 wind, float speed, float amplitude, out float4 aniPos) @@ -27,8 +23,8 @@ inline void WindVert_float(float4 pos, float3 normal, float3 vertColor, float4 w float bendingFact = 1 - vertColor.b; - //wind.xyz = TransformWorldToObject(wind.xyz); - //wind.z = wind.z * bendingFact; + wind.xyz = TransformWorldToObject(wind.xyz); + wind.z = wind.z * bendingFact; float4 animParams = float4(0, amplitude, bendingFact.xx); float time = _Time.y * float2(speed, 1); diff --git a/Assets/Test/test/WindAnim.hlsl.meta b/Assets/Test/Wind/WindAnim.hlsl.meta similarity index 100% rename from Assets/Test/test/WindAnim.hlsl.meta rename to Assets/Test/Wind/WindAnim.hlsl.meta diff --git a/Assets/Test/Wind/WindCloth.mat b/Assets/Test/Wind/WindCloth.mat new file mode 100644 index 0000000..af96a72 --- /dev/null +++ b/Assets/Test/Wind/WindCloth.mat @@ -0,0 +1,135 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &-8966936789293289874 +MonoBehaviour: + m_ObjectHideFlags: 11 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d0353a89b1f911e48b9e16bdc9f2e058, type: 3} + m_Name: + m_EditorClassIdentifier: + version: 7 +--- !u!21 &2100000 +Material: + serializedVersion: 8 + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_Name: WindCloth + m_Shader: {fileID: 4800000, guid: cbc110f6abccf47ada5a8569ec9eb889, type: 3} + m_Parent: {fileID: 0} + m_ModifiedSerializedProperties: 0 + m_ValidKeywords: [] + m_InvalidKeywords: [] + m_LightmapFlags: 4 + m_EnableInstancingVariants: 0 + m_DoubleSidedGI: 0 + m_CustomRenderQueue: -1 + stringTagMap: {} + disabledShaderPasses: [] + m_LockedProperties: + m_SavedProperties: + serializedVersion: 3 + m_TexEnvs: + - _BaseMap: + m_Texture: {fileID: 2800000, guid: 016ab36f33e35487bb91a3712c78b36e, type: 3} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _BumpMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailAlbedoMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailMask: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _DetailNormalMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _EmissionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MainTex: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _MetallicGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _OcclusionMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _ParallaxMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - _SpecGlossMap: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_Lightmaps: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_LightmapsInd: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + - unity_ShadowMasks: + m_Texture: {fileID: 0} + m_Scale: {x: 1, y: 1} + m_Offset: {x: 0, y: 0} + m_Ints: [] + m_Floats: + - _AlphaClip: 0 + - _AlphaToMask: 0 + - _Blend: 0 + - _BlendModePreserveSpecular: 1 + - _BumpScale: 1 + - _ClearCoatMask: 0 + - _ClearCoatSmoothness: 0 + - _Cull: 2 + - _Cutoff: 0.5 + - _DetailAlbedoMapScale: 1 + - _DetailNormalMapScale: 1 + - _DstBlend: 0 + - _DstBlendAlpha: 0 + - _EnvironmentReflections: 1 + - _GlossMapScale: 0 + - _Glossiness: 0 + - _GlossyReflections: 0 + - _Metallic: 0 + - _OcclusionStrength: 1 + - _Parallax: 0.005 + - _QueueOffset: 0 + - _ReceiveShadows: 1 + - _Smoothness: 0.5 + - _SmoothnessTextureChannel: 0 + - _SpecularHighlights: 1 + - _SrcBlend: 1 + - _SrcBlendAlpha: 1 + - _Surface: 0 + - _WindAmplitude: 1.3 + - _WindSpeed: 0.14 + - _WorkflowMode: 1 + - _ZWrite: 1 + m_Colors: + - _BaseColor: {r: 1, g: 1, b: 1, a: 1} + - _Color: {r: 1, g: 1, b: 1, a: 1} + - _EmissionColor: {r: 0, g: 0, b: 0, a: 1} + - _SpecColor: {r: 0.2, g: 0.2, b: 0.2, a: 1} + - _Wind: {r: 0, g: 0, b: 0, a: 1} + m_BuildTextureStacks: [] diff --git a/Assets/Test/Wind/WindCloth.mat.meta b/Assets/Test/Wind/WindCloth.mat.meta new file mode 100644 index 0000000..76b8ef4 --- /dev/null +++ b/Assets/Test/Wind/WindCloth.mat.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: de1a9c4ecd10a42f188ece37e18f10d6 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 2100000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Test/test/grass.fbx b/Assets/Test/Wind/grass.fbx similarity index 100% rename from Assets/Test/test/grass.fbx rename to Assets/Test/Wind/grass.fbx diff --git a/Assets/Test/test/grass.fbx.meta b/Assets/Test/Wind/grass.fbx.meta similarity index 100% rename from Assets/Test/test/grass.fbx.meta rename to Assets/Test/Wind/grass.fbx.meta diff --git a/Assets/Test/test/home18_flower.tga b/Assets/Test/Wind/home18_flower.tga similarity index 100% rename from Assets/Test/test/home18_flower.tga rename to Assets/Test/Wind/home18_flower.tga diff --git a/Assets/Test/test/home18_flower.tga.meta b/Assets/Test/Wind/home18_flower.tga.meta similarity index 100% rename from Assets/Test/test/home18_flower.tga.meta rename to Assets/Test/Wind/home18_flower.tga.meta diff --git a/Packages/zzwater/shaders/libs/WindAnim.hlsl b/Packages/zzwater/shaders/libs/WindAnim.hlsl new file mode 100644 index 0000000..3292e80 --- /dev/null +++ b/Packages/zzwater/shaders/libs/WindAnim.hlsl @@ -0,0 +1,56 @@ +//UNITY_SHADER_NO_UPGRADE +#ifndef WIND_ANIM_INCLUDE +#define WIND_ANIM_INCLUDE + +inline float4 SmoothCurve( float4 x ) { + return x * x *( 3.0 - 2.0 * x ); +} + +inline float4 TriangleWave( float4 x ) { + return abs( frac( x + 0.5 ) * 2.0 - 1.0 ); +} + +inline float4 SmoothTriangleWave( float4 x ) { + return SmoothCurve( TriangleWave( x ) ); +} + + +inline float4 ClothWindAnim(float4 pos, float3 normal, float4 animParams,float4 wind,float2 time) +{ + // animParams.x = branch phase + // animParams.y = edge flutter factor + // animParams.z = primary factor + // animParams.w = secondary factor + + + float fDetailAmp = 0.1f; + float fBranchAmp = 0.3f; + + // Phases (object, vertex, branch) + float fObjPhase = dot(unity_ObjectToWorld[3].xyz, 1); + float fBranchPhase = fObjPhase + animParams.x; + + float fVtxPhase = dot(pos.xyz, animParams.y + fBranchPhase); + + // x is used for edges; y is used for branches + float2 vWavesIn = time + float2(fVtxPhase, fBranchPhase ); + + // 1.975, 0.793, 0.375, 0.193 are good frequencies + float4 vWaves = (frac( vWavesIn.xxyy * float4(1.975, 0.793, 0.375, 0.193) ) * 2.0 - 1.0); + + vWaves = SmoothTriangleWave( vWaves ); + float2 vWavesSum = vWaves.xz + vWaves.yw; + + // Edge (xz) and branch bending (y) + float3 bend = animParams.y * fDetailAmp * normal.xyz; + bend.y = animParams.w * fBranchAmp; + pos.xyz += ((vWavesSum.xyx * bend)*wind.w + (wind.xyz * vWavesSum.y * animParams.w)) * wind.w; + + // Primary bending + // Displace position + pos.xyz += animParams.z * wind.xyz; + + return pos; +} + +#endif //WIND_ANIM_INCLUDE diff --git a/Packages/zzwater/shaders/libs/WindAnim.hlsl.meta b/Packages/zzwater/shaders/libs/WindAnim.hlsl.meta new file mode 100644 index 0000000..1196f6a --- /dev/null +++ b/Packages/zzwater/shaders/libs/WindAnim.hlsl.meta @@ -0,0 +1,7 @@ +fileFormatVersion: 2 +guid: 418d88a69b1774954ace0d91b8c685d7 +ShaderIncludeImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Packages/zzwater/shaders/wind_cloth.shader b/Packages/zzwater/shaders/wind_cloth.shader new file mode 100644 index 0000000..a763939 --- /dev/null +++ b/Packages/zzwater/shaders/wind_cloth.shader @@ -0,0 +1,105 @@ +Shader "zzwind/WindClothUnlit" +{ + + Properties + { + + [MainTexture] _BaseMap("Texture", 2D) = "white" {} + [MainColor] _BaseColor("Color", Color) = (1, 1, 1, 1) + _Cutoff("AlphaCutout", Range(0.0, 1.0)) = 0.5 + _Wind("Wind params",Vector) = (1,1,1,1) + _WindAmplitude("Wind Amplitude", float) = 0.5 + _WindSpeed("Wind Speed",float) = 0.5 + } + + SubShader + { + Tags + { + "RenderType" = "Opaque" + "IgnoreProjector" = "True" + "UniversalMaterialType" = "Unlit" + "RenderPipeline" = "UniversalPipeline" + } + + Pass + { + Name "Unlit" + Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha + ZWrite On + Cull Back + ZTest LEqual + ZClip On + + HLSLPROGRAM + + #pragma vertex vert + #pragma fragment frag + + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl" + #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl" + #include "Packages/zzwater/shaders/libs/WindAnim.hlsl" + + + TEXTURE2D(_BaseMap); + SAMPLER(sampler_BaseMap); + + CBUFFER_START(UnityPerMaterial) + float _Cutoff; + half4 _BaseColor; + half4 _BaseMap_ST; + half4 _Wind; + float _WindAmplitude; + float _WindSpeed; + CBUFFER_END + + struct Attributes + { + float4 positionOS : POSITION; + float4 tangentOS : TANGENT; + float2 uv : TEXCOORD0; + float3 normalOS : NORMAL; + float4 color : COLOR; + }; + + struct Varyings + { + float4 positionCS : SV_POSITION; + float2 uv : TEXCOORD0; + float4 color : TEXCOORD2; + }; + + Varyings vert(Attributes input) + { + Varyings output; + + float bendingFact = input.color.a; + float4 wind; + wind.xyz = _Wind.xyz; + wind.w = _Wind.w * bendingFact.x; + + float4 windParams = float4(0,_WindAmplitude,bendingFact,0); + float windTime = _Time.y * _WindSpeed; + float4 VertexInWndPos = ClothWindAnim(input.positionOS,input.normalOS,windParams,wind,windTime); + + output.positionCS = TransformObjectToHClip(VertexInWndPos); + output.uv = TRANSFORM_TEX(input.uv, _BaseMap); + output.color = input.color; + return output; + } + + float4 frag(Varyings input) : SV_Target + { + half2 uv = input.uv; + half4 texColor = SAMPLE_TEXTURE2D(_BaseMap, sampler_BaseMap, uv); + half3 color = texColor.rgb * _BaseColor.rgb; + half alpha = texColor.a * _BaseColor.a; + clip(alpha - _Cutoff); + + return float4(color, alpha); + } + + ENDHLSL + } + } +} diff --git a/Packages/zzwater/shaders/wind_cloth.shader.meta b/Packages/zzwater/shaders/wind_cloth.shader.meta new file mode 100644 index 0000000..71c1c39 --- /dev/null +++ b/Packages/zzwater/shaders/wind_cloth.shader.meta @@ -0,0 +1,9 @@ +fileFormatVersion: 2 +guid: cbc110f6abccf47ada5a8569ec9eb889 +ShaderImporter: + externalObjects: {} + defaultTextures: [] + nonModifiableTextures: [] + userData: + assetBundleName: + assetBundleVariant: