2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
#ifndef VERTEXANIMATIONUTILS_INCLUDED
|
|
|
|
#define VERTEX_ANIMATION_INCLUDED
|
|
|
|
|
2022-12-04 04:18:35 +01:00
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
#include "SampleTexture2DArrayLOD.hlsl"
|
|
|
|
|
2022-12-04 04:18:35 +01:00
|
|
|
void CALC_VA_UV_float(float2 uv, int maxFrames, float time, out float2 uvPosition)
|
|
|
|
{
|
|
|
|
float timeInFrames = frac(time);
|
|
|
|
timeInFrames = ceil(timeInFrames * maxFrames);
|
|
|
|
timeInFrames /= maxFrames;
|
|
|
|
timeInFrames += round(1.0f / maxFrames);
|
|
|
|
|
|
|
|
uvPosition.x = uv.x;
|
|
|
|
|
|
|
|
#ifdef VA_FLIP_UVS_ON
|
|
|
|
uvPosition.y = (1.0f - (timeInFrames)) + (1.0f - (1.0f - uv.y));
|
|
|
|
#else
|
|
|
|
uvPosition.y = (1.0f - (1.0f - uv.y) - (1.0f - (timeInFrames)));
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
float2 VA_UV_float(float2 uv, int maxFrames, float time)
|
|
|
|
{
|
|
|
|
float2 uvPosition;
|
|
|
|
float timeInFrames = frac(time);
|
|
|
|
timeInFrames = ceil(timeInFrames * maxFrames);
|
|
|
|
timeInFrames /= maxFrames;
|
2020-12-14 20:27:44 +01:00
|
|
|
timeInFrames += round(1.0f / maxFrames);
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
uvPosition.x = uv.x;
|
2021-01-09 15:56:38 +01:00
|
|
|
|
2021-01-13 19:31:54 +01:00
|
|
|
#ifdef VA_FLIP_UVS_ON
|
|
|
|
uvPosition.y = (1.0f - (timeInFrames)) + (1.0f - (1.0f - uv.y));
|
|
|
|
#else
|
2021-01-09 15:56:38 +01:00
|
|
|
uvPosition.y = (1.0f - (1.0f - uv.y) - (1.0f - (timeInFrames)));
|
2021-01-13 19:31:54 +01:00
|
|
|
#endif
|
2021-01-09 15:56:38 +01:00
|
|
|
|
|
|
|
return uvPosition;
|
|
|
|
}
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
void VA_float(float2 uv, SamplerState texSampler, Texture2D positionMap, float time, int maxFrames,
|
2021-02-03 22:13:59 +01:00
|
|
|
out float3 position, out float alpha)
|
2020-12-06 02:36:15 +01:00
|
|
|
{
|
|
|
|
float2 uvPosition = VA_UV_float(uv, maxFrames, time);
|
|
|
|
|
|
|
|
// Position.
|
|
|
|
float4 texturePos = positionMap.SampleLevel(texSampler, uvPosition, 0);
|
2020-12-08 00:33:06 +01:00
|
|
|
position = texturePos.xyz;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
// Normal.
|
2020-12-08 00:33:06 +01:00
|
|
|
//FloatToFloat3_float(texturePos.w, outNormal);
|
|
|
|
alpha = texturePos.w;
|
2020-12-06 02:36:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void VA_ARRAY_float(float2 uv, SamplerState texSampler, Texture2DArray positionMap, float positionMapIndex, float time, int maxFrames,
|
2021-02-03 22:13:59 +01:00
|
|
|
out float3 position, out float alpha)
|
2020-12-06 02:36:15 +01:00
|
|
|
{
|
|
|
|
float2 uvPosition = VA_UV_float(uv, maxFrames, time);
|
|
|
|
|
|
|
|
// Position.
|
|
|
|
float4 texturePos;
|
|
|
|
SampleTexture2DArrayLOD_float(positionMap, uvPosition, texSampler, positionMapIndex, 0, texturePos);
|
2020-12-08 00:33:06 +01:00
|
|
|
position = texturePos.xyz;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
// Normal.
|
2020-12-08 00:33:06 +01:00
|
|
|
//FloatToFloat3_float(texturePos.w, outNormal);
|
|
|
|
alpha = texturePos.w;
|
2020-12-06 02:36:15 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|