Skip to content

Commit

Permalink
Edit motion vector, code improvements
Browse files Browse the repository at this point in the history
Signed-off-by: Judy Ng <[email protected]>
  • Loading branch information
judysng committed Jul 28, 2022
1 parent ec4f695 commit 4c11c3c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@
{
"file": "./VegetationBending_DepthPass_WithPS.shader",
"tag": "DepthPass_WithPS"
},
{
"file": "./MeshMotionVectorVegetationBending.shader",
"tag": "MeshMotionVector"
}
],
"functors": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,27 +119,25 @@ float4 SetUpWindBending(float currentTime, float4 worldPosition)
float2 frequency = float2(MaterialSrg::m_windBendingFrequency, MaterialSrg::m_windBendingFrequency * 1.125);
// Using the world position to modify the phase makes it so different trees near each other are at similar but not equal points in the animation,
// so they appear to be reacting to the same wind but at different times as the wind moves through the vegetation.
float2 phase = float2(worldPosition.x * 0.08, worldPosition.y * 0.08);
float2 phase = worldPosition.xy * 0.08;

float2 addBending = float2(sin(currentTime * frequency.x + phase.x) * amplitude.x, sin(currentTime * frequency.y + phase.y) * amplitude.y);
float2 bendAmount = sin(currentTime * frequency + phase) * amplitude;

float4 result;
result.x = addBending.x + wind.x;
result.y = addBending.y + wind.y;
result.z = sqrt(wind.x * wind.x + wind.y * wind.y);
result *= bendingStrength * 0.08;
float2 totalBending = addBending + wind;
result.w = sqrt(totalBending.x * totalBending.x + totalBending.y * totalBending.y) * 0.3;
result.xy = bendAmount + wind;
result.z = length(wind);
result.w = 0.3 * length(result.xy);
result.xyz *= bendingStrength * 0.08;

return result;
}

float3 DetailBending(float3 objectSpacePosition, float3 normal, float4 color, float currentTime, float4 worldPosition, float bendLength)
float3 DetailBending(float3 objectSpacePosition, float3 normal, float4 detailBendingParams, float currentTime, float4 worldPosition, float bendLength)
{
// The information from the vertex colors about how to bend this vertex.
float edgeInfo = color.x;
float branchPhase = color.y;
float branchBendAmount = color.z;
float edgeInfo = detailBendingParams.x;
float branchPhase = detailBendingParams.y;
float branchBendAmount = detailBendingParams.z;

// Phases (object, vertex, branch)
float objPhase = dot(worldPosition.xyz, 2.0);
Expand Down Expand Up @@ -180,7 +178,7 @@ float3 MainBending(float3 objectSpacePosition, float4 bending)
return normalize(newPos) * len;
}

float4 ProcessBending(float currentTime, float3 objectSpacePosition, float3 normal, float4 color, float4 worldPosition, float4x4 objectToWorld)
float4 ProcessBending(float currentTime, float3 objectSpacePosition, float3 normal, float4 detailBendingParams, float4 worldPosition, float4x4 objectToWorld)
{
float4 adjustedWorldPosition = float4(worldPosition);
if (o_color_isBound)
Expand All @@ -189,7 +187,7 @@ float4 ProcessBending(float currentTime, float3 objectSpacePosition, float3 norm
float4 currentBending = SetUpWindBending(currentTime, worldPosition);

// Detail bending
float3 currentOutPosition = DetailBending(objectSpacePosition, normal, color, currentTime, worldPosition, currentBending.w);
float3 currentOutPosition = DetailBending(objectSpacePosition, normal, detailBendingParams, currentTime, worldPosition, currentBending.w);

currentOutPosition = MainBending(currentOutPosition, currentBending);

Expand Down
6 changes: 0 additions & 6 deletions atom_gems/AtomTutorials/Code/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@

# Currently we are in the Code folder: ${CMAKE_CURRENT_LIST_DIR}
# Get the platform specific folder ${pal_dir} for the current folder: ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME}
# Note: o3de_pal_dir will take care of the details for us, as this may be a restricted platform
# in which case it will see if that platform is present here or in the restricted folder.
# i.e. It could here in our gem : Gems/AtomTutorials/Code/Platform/<platorm_name> or
# <restricted_folder>/<platform_name>/Gems/AtomTutorials/Code
o3de_pal_dir(pal_dir ${CMAKE_CURRENT_LIST_DIR}/Platform/${PAL_PLATFORM_NAME} "${gem_restricted_path}" "${gem_path}" "${gem_parent_relative_path}")

# The AtomTutorials.API target declares the common interface that users of this gem should depend on in their targets
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ VSOutput MainVS(VSInput IN)

float4x4 prevObjectToWorld = SceneSrg::GetObjectToWorldMatrixPrev(ObjectSrg::m_objectId);
float4 prevWorldPosition = mul(prevObjectToWorld, float4(IN.m_position, 1.0));

float currentTime = SceneSrg::m_time;
worldPosition = ProcessBending(currentTime, IN.m_position, IN.m_normal, IN.m_optional_color, worldPosition, objectToWorld);

OUT.m_worldPos = worldPosition.xyz;
OUT.m_worldPosPrev = prevWorldPosition.xyz;
Expand Down

0 comments on commit 4c11c3c

Please sign in to comment.