Skip to content

Commit b363ecd

Browse files
Added first version of vertex wind and a corresponding test scene.
1 parent 523a005 commit b363ecd

32 files changed

Lines changed: 13939 additions & 8 deletions

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/Editor/LayeredLitUI.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -729,6 +729,9 @@ public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] pro
729729
{
730730
BaseMaterialPropertiesGUI();
731731
EditorGUILayout.Space();
732+
733+
VertexAnimationPropertiesGUI();
734+
EditorGUILayout.Space();
732735
}
733736
if (EditorGUI.EndChangeCheck())
734737
{

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLit.shader

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ Shader "HDRenderPipeline/LayeredLit"
172172

173173
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
174174

175+
// Wind
176+
[ToggleOff] _EnableWind("Enable Wind", Float) = 0.0
177+
_InitialBend("Initial Bend", float) = 1.0
178+
_Stiffness("Stiffness", float) = 1.0
179+
_Drag("Drag", float) = 1.0
180+
_ShiverDrag("Shiver Drag", float) = 0.2
181+
175182
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
176183
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
177184
_EmissiveIntensity("EmissiveIntensity", Float) = 0
@@ -295,6 +302,7 @@ Shader "HDRenderPipeline/LayeredLit"
295302
#pragma shader_feature _DENSITY_MODE
296303
#pragma shader_feature _HEIGHT_BASED_BLEND
297304
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
305+
#pragma shader_feature _VERTEX_WIND
298306

299307
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
300308
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED
@@ -317,6 +325,7 @@ Shader "HDRenderPipeline/LayeredLit"
317325
//-------------------------------------------------------------------------------------
318326

319327
#include "../../../ShaderLibrary/common.hlsl"
328+
#include "../../../ShaderLibrary/Wind.hlsl"
320329
#include "../../ShaderConfig.cs.hlsl"
321330
#include "../../ShaderVariables.hlsl"
322331
#include "../../ShaderPass/FragInputs.hlsl"

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/LayeredLit/LayeredLitTessellation.shader

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,13 @@ Shader "HDRenderPipeline/LayeredLitTessellation"
172172

173173
_DistortionVectorMap("DistortionVectorMap", 2D) = "black" {}
174174

175+
// Wind
176+
[ToggleOff] _EnableWind("Enable Wind", Float) = 0.0
177+
_InitialBend("Initial Bend", float) = 1.0
178+
_Stiffness("Stiffness", float) = 1.0
179+
_Drag("Drag", float) = 1.0
180+
_ShiverDrag("Shiver Drag", float) = 0.2
181+
175182
_EmissiveColor("EmissiveColor", Color) = (0, 0, 0)
176183
_EmissiveColorMap("EmissiveColorMap", 2D) = "white" {}
177184
_EmissiveIntensity("EmissiveIntensity", Float) = 0
@@ -311,6 +318,7 @@ Shader "HDRenderPipeline/LayeredLitTessellation"
311318
#pragma shader_feature _DENSITY_MODE
312319
#pragma shader_feature _HEIGHT_BASED_BLEND
313320
#pragma shader_feature _ _LAYEREDLIT_3_LAYERS _LAYEREDLIT_4_LAYERS
321+
#pragma shader_feature _VERTEX_WIND
314322

315323
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
316324
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED
@@ -334,6 +342,7 @@ Shader "HDRenderPipeline/LayeredLitTessellation"
334342
//-------------------------------------------------------------------------------------
335343

336344
#include "../../../ShaderLibrary/common.hlsl"
345+
#include "../../../ShaderLibrary/Wind.hlsl"
337346
#include "../../../ShaderLibrary/tessellation.hlsl"
338347
#include "../../ShaderConfig.cs.hlsl"
339348
#include "../../ShaderVariables.hlsl"

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Editor/BaseLitUI.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,15 @@ protected static class StylesBaseLit
3737
public static GUIContent tessellationBackFaceCullEpsilonText = new GUIContent("Triangle culling Epsilon", "If -1.0 back face culling is enabled for tessellation, higher number mean more aggressive culling and better performance");
3838
public static GUIContent tessellationObjectScaleText = new GUIContent("Enable object scale", "Tessellation displacement will take into account the object scale - Only work with uniform positive scale");
3939
public static GUIContent tessellationTilingScaleText = new GUIContent("Enable tiling scale", "Tessellation displacement will take into account the tiling scale - Only work with uniform positive scale");
40+
41+
// Wind
42+
public static GUIContent windText = new GUIContent("Enable Wind");
43+
public static GUIContent windInitialBendText = new GUIContent("Initial Bend");
44+
public static GUIContent windStiffnessText = new GUIContent("Stiffness");
45+
public static GUIContent windDragText = new GUIContent("Drag");
46+
public static GUIContent windShiverDragText = new GUIContent("Shiver Drag");
47+
48+
public static string vertexAnimation = "Vertex Animation";
4049
}
4150

4251
public enum TessellationMode
@@ -56,6 +65,18 @@ public enum TessellationMode
5665
protected MaterialProperty materialID = null;
5766
protected const string kMaterialID = "_MaterialID";
5867

68+
// Wind
69+
protected MaterialProperty windEnable = null;
70+
protected const string kWindEnabled = "_EnableWind";
71+
protected MaterialProperty windInitialBend = null;
72+
protected const string kWindInitialBend = "_InitialBend";
73+
protected MaterialProperty windStiffness = null;
74+
protected const string kWindStiffness = "_Stiffness";
75+
protected MaterialProperty windDrag = null;
76+
protected const string kWindDrag = "_Drag";
77+
protected MaterialProperty windShiverDrag = null;
78+
protected const string kWindShiverDrag = "_ShiverDrag";
79+
5980
// Per pixel displacement params
6081
protected MaterialProperty enablePerPixelDisplacement = null;
6182
protected const string kEnablePerPixelDisplacement = "_EnablePerPixelDisplacement";
@@ -112,6 +133,13 @@ protected override void FindBaseMaterialProperties(MaterialProperty[] props)
112133
tessellationBackFaceCullEpsilon = FindProperty(kTessellationBackFaceCullEpsilon, props, false);
113134
tessellationObjectScale = FindProperty(kTessellationObjectScale, props, false);
114135
tessellationTilingScale = FindProperty(kTessellationTilingScale, props, false);
136+
137+
// Wind
138+
windEnable = FindProperty(kWindEnabled, props);
139+
windInitialBend = FindProperty(kWindInitialBend, props);
140+
windStiffness = FindProperty(kWindStiffness, props);
141+
windDrag = FindProperty(kWindDrag, props);
142+
windShiverDrag = FindProperty(kWindShiverDrag, props);
115143
}
116144

117145
void TessellationModePopup()
@@ -186,6 +214,26 @@ protected override void BaseMaterialPropertiesGUI()
186214
}
187215
}
188216

217+
protected override void VertexAnimationPropertiesGUI()
218+
{
219+
GUILayout.Label(StylesBaseLit.vertexAnimation, EditorStyles.boldLabel);
220+
221+
EditorGUI.indentLevel++;
222+
223+
m_MaterialEditor.ShaderProperty(windEnable, StylesBaseLit.windText);
224+
if (!windEnable.hasMixedValue && windEnable.floatValue > 0.0f)
225+
{
226+
EditorGUI.indentLevel++;
227+
m_MaterialEditor.ShaderProperty(windInitialBend, StylesBaseLit.windInitialBendText);
228+
m_MaterialEditor.ShaderProperty(windStiffness, StylesBaseLit.windStiffnessText);
229+
m_MaterialEditor.ShaderProperty(windDrag, StylesBaseLit.windDragText);
230+
m_MaterialEditor.ShaderProperty(windShiverDrag, StylesBaseLit.windShiverDragText);
231+
EditorGUI.indentLevel--;
232+
}
233+
234+
EditorGUI.indentLevel--;
235+
}
236+
189237
// All Setup Keyword functions must be static. It allow to create script to automatically update the shaders with a script if ocde change
190238
static public void SetupBaseLitKeywords(Material material)
191239
{
@@ -260,6 +308,9 @@ static public void SetupBaseLitKeywords(Material material)
260308
bool tessellationTilingScaleEnable = material.GetFloat(kTessellationTilingScale) > 0.0;
261309
SetKeyword(material, "_TESSELLATION_TILING_SCALE", tessellationTilingScaleEnable);
262310
}
311+
312+
bool windEnabled = material.GetFloat(kWindEnabled) > 0.0f;
313+
SetKeyword(material, "_VERTEX_WIND", windEnabled);
263314
}
264315

265316
static public void SetupBaseLitMaterialPass(Material material)

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/Lit.shader

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Shader "HDRenderPipeline/Lit"
3838
_Thickness("Thickness", Range(0.004, 1.0)) = 1.0
3939
_ThicknessMap("Thickness Map", 2D) = "white" {}
4040

41+
// Wind
42+
[ToggleOff] _EnableWind("Enable Wind", Float) = 0.0
43+
_InitialBend("Initial Bend", float) = 1.0
44+
_Stiffness("Stiffness", float) = 1.0
45+
_Drag("Drag", float) = 1.0
46+
_ShiverDrag("Shiver Drag", float) = 0.2
47+
4148
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
4249
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}
4350

@@ -133,6 +140,7 @@ Shader "HDRenderPipeline/Lit"
133140
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
134141
#pragma shader_feature _THICKNESS_MAP
135142
#pragma shader_feature _SUBSURFACE_SCATTERING
143+
#pragma shader_feature _VERTEX_WIND
136144

137145
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
138146
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED
@@ -155,6 +163,7 @@ Shader "HDRenderPipeline/Lit"
155163
//-------------------------------------------------------------------------------------
156164

157165
#include "../../../ShaderLibrary/common.hlsl"
166+
#include "../../../ShaderLibrary/Wind.hlsl"
158167
#include "../../ShaderConfig.cs.hlsl"
159168
#include "../../ShaderVariables.hlsl"
160169
#include "../../ShaderPass/FragInputs.hlsl"

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitProperties.hlsl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@ float _EmissiveIntensity;
2525
// TODO: Fix the code in legacy unity so we can customize the beahvior for GI
2626
float3 _EmissionColor;
2727

28+
// Wind
29+
float _InitialBend;
30+
float _Stiffness;
31+
float _Drag;
32+
float _ShiverDrag;
33+
2834
#ifndef LAYERED_LIT_SHADER
2935

3036
// Set of users variables

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Lit/LitTessellation.shader

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ Shader "HDRenderPipeline/LitTessellation"
3838
_Thickness("Thickness", Range(0.004, 1.0)) = 1.0
3939
_ThicknessMap("Thickness Map", 2D) = "white" {}
4040

41+
// Wind
42+
[ToggleOff] _EnableWind("Enable Wind", Float) = 0.0
43+
_InitialBend("Initial Bend", float) = 1.0
44+
_Stiffness("Stiffness", float) = 1.0
45+
_Drag("Drag", float) = 1.0
46+
_ShiverDrag("Shiver Drag", float) = 0.2
47+
4148
//_CoatCoverage("CoatCoverage", Range(0.0, 1.0)) = 0
4249
//_CoatCoverageMap("CoatCoverageMapMap", 2D) = "white" {}
4350

@@ -149,6 +156,7 @@ Shader "HDRenderPipeline/LitTessellation"
149156
#pragma shader_feature _SUBSURFACE_RADIUS_MAP
150157
#pragma shader_feature _THICKNESS_MAP
151158
#pragma shader_feature _SUBSURFACE_SCATTERING
159+
#pragma shader_feature _VERTEX_WIND
152160

153161
#pragma multi_compile LIGHTMAP_OFF LIGHTMAP_ON
154162
#pragma multi_compile DIRLIGHTMAP_OFF DIRLIGHTMAP_COMBINED
@@ -172,6 +180,7 @@ Shader "HDRenderPipeline/LitTessellation"
172180
//-------------------------------------------------------------------------------------
173181

174182
#include "../../../ShaderLibrary/common.hlsl"
183+
#include "../../../ShaderLibrary/Wind.hlsl"
175184
#include "../../../ShaderLibrary/tessellation.hlsl"
176185
#include "../../ShaderConfig.cs.hlsl"
177186
#include "../../ShaderVariables.hlsl"

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/BaseUnlitUI.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ public enum BlendMode
7070
protected abstract void FindMaterialProperties(MaterialProperty[] props);
7171
protected abstract void SetupMaterialKeywordsAndPassInternal(Material material);
7272
protected abstract void MaterialPropertiesGUI(Material material);
73-
// This function will said if emissive is use or not regarding enlighten/PVR
73+
protected abstract void VertexAnimationPropertiesGUI();
74+
// This function will saiy if emissive is used or not regarding enlighten/PVR
7475
protected abstract bool ShouldEmissionBeEnabled(Material material);
7576

7677
protected virtual void FindBaseMaterialProperties(MaterialProperty[] props)
@@ -294,6 +295,8 @@ public void ShaderPropertiesGUI(Material material)
294295
BaseMaterialPropertiesGUI();
295296
EditorGUILayout.Space();
296297

298+
VertexAnimationPropertiesGUI();
299+
297300
EditorGUILayout.Space();
298301
MaterialPropertiesGUI(material);
299302

Assets/ScriptableRenderPipeline/HDRenderPipeline/Material/Unlit/Editor/UnlitUI.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ protected override void MaterialPropertiesGUI(Material material)
4848
m_MaterialEditor.ShaderProperty(emissiveIntensity, Styles.emissiveIntensityText);
4949
}
5050

51+
protected override void VertexAnimationPropertiesGUI()
52+
{
53+
54+
}
55+
5156
protected override bool ShouldEmissionBeEnabled(Material mat)
5257
{
5358
return mat.GetFloat(kEmissiveIntensity) > 0.0f;

Assets/ScriptableRenderPipeline/HDRenderPipeline/ShaderPass/VertMesh.hlsl

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,30 @@ VaryingsMeshType VertMesh(AttributesMesh input)
9797
{
9898
VaryingsMeshType output;
9999

100+
float3 positionWS = TransformObjectToWorld(input.positionOS);
101+
float3 normalWS = float3(0.0, 0.0, 0.0);
102+
float4 tangentWS = float4(0.0, 0.0, 0.0, 0.0);
103+
float4 vertexColor = float4(0.0, 0.0, 0.0, 0.0);
104+
105+
#if (defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(TESSELLATION_ON)) && (SHADERPASS != SHADERPASS_VELOCITY)
106+
normalWS = TransformObjectToWorldNormal(input.normalOS);
107+
#endif
108+
109+
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_TANGENT)
110+
tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
111+
#endif
112+
113+
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR)
114+
vertexColor = input.color;
115+
#endif
116+
117+
#if _VERTEX_WIND
118+
float3 rootWP = mul(GetObjectToWorldMatrix(), float4(0, 0, 0, 1)).xyz;
119+
ApplyWind(positionWS, normalWS, rootWP, _Drag, _Stiffness, _ShiverDrag, _InitialBend, vertexColor.a, _Time);
120+
#endif
121+
100122
#ifdef TESSELLATION_ON
101-
output.positionWS = TransformObjectToWorld(input.positionOS);
123+
output.positionWS = positionWS;
102124
#ifdef _TESSELLATION_OBJECT_SCALE
103125
// Extract scaling from world transform
104126
float4x4 worldTransform = GetObjectToWorldMatrix();
@@ -111,21 +133,21 @@ VaryingsMeshType VertMesh(AttributesMesh input)
111133
#if SHADERPASS == SHADERPASS_VELOCITY
112134
output.normalWS = float3(0.0, 0.0, 1.0);
113135
#else
114-
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
136+
output.normalWS = normalWS;
115137
#endif
116138
#if defined(VARYINGS_NEED_TANGENT_TO_WORLD) || defined(VARYINGS_DS_NEED_TANGENT)
117-
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
139+
output.tangentWS = tangentWS;
118140
#endif
119141
#else
120-
float3 positionWS = TransformObjectToWorld(input.positionOS);
142+
121143
// TODO deal with camera center rendering and instancing (This is the reason why we always perform tow steps transform to clip space + instancing matrix)
122144
#ifdef VARYINGS_NEED_POSITION_WS
123145
output.positionWS = positionWS;
124146
#endif
125147
output.positionCS = TransformWorldToHClip(positionWS);
126148
#ifdef VARYINGS_NEED_TANGENT_TO_WORLD
127-
output.normalWS = TransformObjectToWorldNormal(input.normalOS);
128-
output.tangentWS = float4(TransformObjectToWorldDir(input.tangentOS.xyz), input.tangentOS.w);
149+
output.normalWS = normalWS;
150+
output.tangentWS = tangentWS;
129151
#endif
130152
#endif
131153

@@ -142,7 +164,7 @@ VaryingsMeshType VertMesh(AttributesMesh input)
142164
output.texCoord3 = input.uv3;
143165
#endif
144166
#if defined(VARYINGS_NEED_COLOR) || defined(VARYINGS_DS_NEED_COLOR)
145-
output.color = input.color;
167+
output.color = vertexColor;
146168
#endif
147169

148170
return output;

0 commit comments

Comments
 (0)