Skip to content

Commit

Permalink
refactor: add namespace to GrassCollision
Browse files Browse the repository at this point in the history
  • Loading branch information
FlayaN committed Aug 18, 2024
1 parent f020ed7 commit 2414413
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,27 @@ cbuffer GrassCollisionPerFrame : register(b5)
uint numCollisions;
}

float3 GetDisplacedPosition(float3 position, float alpha, uint eyeIndex = 0)
namespace GrassCollision
{
float3 worldPosition = mul(World[eyeIndex], float4(position, 1.0)).xyz;
float3 GetDisplacedPosition(float3 position, float alpha, uint eyeIndex = 0)
{
float3 worldPosition = mul(World[eyeIndex], float4(position, 1.0)).xyz;

if (length(worldPosition) < 1024.0 && alpha > 0.0) {
float3 displacement = 0.0;
if (length(worldPosition) < 1024.0 && alpha > 0.0) {
float3 displacement = 0.0;

for (uint i = 0; i < numCollisions; i++) {
float dist = distance(collisionData[i].centre[eyeIndex], worldPosition);
float power = 1.0 - saturate(dist / collisionData[i].centre[0].w);
float3 direction = worldPosition - collisionData[i].centre[eyeIndex];
float3 shift = power * direction;
displacement += shift;
displacement.z -= length(shift.xy);
for (uint i = 0; i < numCollisions; i++) {
float dist = distance(collisionData[i].centre[eyeIndex], worldPosition);
float power = 1.0 - saturate(dist / collisionData[i].centre[0].w);
float3 direction = worldPosition - collisionData[i].centre[eyeIndex];
float3 shift = power * direction;
displacement += shift;
displacement.z -= length(shift.xy);
}

return displacement * alpha;
}

return displacement * alpha;
return 0.0;
}

return 0.0;
}
2 changes: 1 addition & 1 deletion package/Shaders/RunGrass.hlsl
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ VS_OUTPUT main(VS_INPUT input)
float4 msPosition = GetMSPosition(input, WindTimer, world3x3);

# ifdef GRASS_COLLISION
float3 displacement = GetDisplacedPosition(msPosition.xyz, input.Color.w, eyeIndex);
float3 displacement = GrassCollision::GetDisplacedPosition(msPosition.xyz, input.Color.w, eyeIndex);
msPosition.xyz += displacement;
# endif // GRASS_COLLISION

Expand Down

0 comments on commit 2414413

Please sign in to comment.