Vertex animation base.

Vertex animation base shader with interpolation.
This commit is contained in:
max
2020-11-02 23:49:30 +01:00
parent ebe4eb14bd
commit 8220f80d0e
30 changed files with 1700 additions and 12 deletions

View File

@ -0,0 +1,23 @@
Copyright (c) 2020
Side Effects Software Inc. All rights reserved.
Redistribution and use of in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. The name of Side Effects Software may not be used to endorse or
promote products derived from this software without specific prior
written permission.
THIS SOFTWARE IS PROVIDED BY SIDE EFFECTS SOFTWARE `AS IS' AND ANY EXPRESS
OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
NO EVENT SHALL SIDE EFFECTS SOFTWARE BE LIABLE FOR ANY DIRECT, INDIRECT,
INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

View File

@ -0,0 +1,7 @@
fileFormatVersion: 2
guid: 1caf0f5dc0fa19b4a961e254dd6e44ee
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,10 @@
fileFormatVersion: 2
guid: 446663e7b10741549a76b3c09a9554c8
ScriptedImporter:
internalIDToNameTable: []
externalObjects: {}
serializedVersion: 2
userData:
assetBundleName:
assetBundleVariant:
script: {fileID: 11500000, guid: 60072b568d64c40a485e0fc55012dc9f, type: 3}

View File

@ -0,0 +1,192 @@
float3 VAT_unpackAlpha(float alpha)
{
//decode float to float2
alpha *= 1024;
// alpha = 0.8286 * 1024;
float2 f2;
f2.x = floor(alpha / 32.0) / 31.5;
f2.y = (alpha - (floor(alpha / 32.0)*32.0)) / 31.5;
//decode float2 to float3
float3 f3;
f2 *= 4;
f2 -= 2;
float f2dot = dot(f2,f2);
f3.xy = sqrt(1 - (f2dot/4.0)) * f2;
f3.z = 1 - (f2dot/2.0);
f3 = clamp(f3, -1.0, 1.0);
return f3;
}
float2 VAT_uvPosition(float2 uvIndex, int numOfFrames, float speed, float time, float2 paddedRatio)
{
float2 uvPosition;
float FPS = 24.0;
float FPS_div_Frames = FPS / numOfFrames;
float timeInFrames = frac(speed * time);
timeInFrames = ceil(timeInFrames * numOfFrames);
timeInFrames /= numOfFrames;
timeInFrames += (1/numOfFrames);
uvPosition.x = uvIndex.x * paddedRatio.x;
uvPosition.y = (1 - (timeInFrames * paddedRatio.y)) + (1 - ((1 - uvIndex.y) * paddedRatio.y));
return uvPosition;
}
// Rigid VAT
void VAT_Rigid_float(
float3 restPosition,
float3 restNormal,
float3 vertexColor,
float2 uvIndex,
SamplerState texSampler,
Texture2D positionMap,
Texture2D rotationMap,
float2 positionBounds,
float2 pivotBounds,
float time,
float speed,
int numOfFrames,
float2 paddedRatio,
out float3 outPosition,
out float3 outNormal
)
{
float2 uvPosition = VAT_uvPosition(uvIndex, numOfFrames, speed, time, paddedRatio);
float4 texturePos = positionMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureRot = rotationMap.SampleLevel(texSampler, uvPosition, 0);
texturePos.xyz = lerp(positionBounds.x, positionBounds.y, texturePos.xyz);
float3 pivot = lerp(pivotBounds.x, pivotBounds.y, vertexColor.xyz);
float3 atOrigin = restPosition - pivot;
//calculate rotation
textureRot *= 2.0;
textureRot -= 1.0;
float4 quat = 0;
quat = textureRot;
float3 rotated = 2.0 * cross(quat.xyz, cross(quat.xyz, atOrigin) + quat.w * atOrigin);
float3 rotatedNormal = restNormal + 2.0 * cross(quat.xyz, cross(quat.xyz, restNormal) + quat.w * restNormal);
outPosition = atOrigin + rotated + texturePos;
outNormal = rotatedNormal;
}
// Soft VAT
void VAT_Soft_float(
float3 restPosition,
float2 uvIndex,
SamplerState texSampler,
Texture2D positionMap,
Texture2D normalMap,
Texture2D colorMap,
float2 positionBounds,
float time,
float speed,
int numOfFrames,
float2 paddedRatio,
bool packNorm,
out float3 outPosition,
out float3 outNormal,
out float3 outColor
)
{
float2 uvPosition = VAT_uvPosition(uvIndex, numOfFrames, speed, time, paddedRatio);
float4 texturePos = positionMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureN = normalMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureCd = colorMap.SampleLevel(texSampler, uvPosition, 0);
texturePos.xyz = lerp(positionBounds.x, positionBounds.y, texturePos.xyz);
//calculate normal
if (packNorm){
outNormal = VAT_unpackAlpha(texturePos.w);
} else {
outNormal = textureN * 2 - 1;
}
outPosition = restPosition + texturePos;
outColor = textureCd.xyz;
}
// Fluid VAT
void VAT_Fluid_float(
float2 uvIndex,
SamplerState texSampler,
Texture2D positionMap,
Texture2D normalMap,
Texture2D colorMap,
float2 positionBounds,
float time,
float speed,
int numOfFrames,
float2 paddedRatio,
bool packNorm,
out float3 outPosition,
out float3 outNormal,
out float3 outColor
)
{
float2 uvPosition = VAT_uvPosition(uvIndex, numOfFrames, speed, time, paddedRatio);
float4 texturePos = positionMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureN = normalMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureCd = colorMap.SampleLevel(texSampler, uvPosition, 0);
texturePos.xyz = lerp(positionBounds.x, positionBounds.y, texturePos.xyz);
//calculate normal
if (packNorm){
outNormal = VAT_unpackAlpha(texturePos.w);
} else {
outNormal = textureN * 2 - 1;
}
outPosition = texturePos;
outColor = textureCd.xyz;
}
// Sprite VAT
void VAT_Sprite_float(
float2 uvIndex,
float2 uv,
SamplerState texSampler,
Texture2D positionMap,
Texture2D colorMap,
float2 positionBounds,
float2 widthHeight,
float time,
float speed,
int numOfFrames,
float2 paddedRatio,
bool packNorm,
matrix MV,
out float3 outPosition,
out float3 outNormal,
out float3 outColor
)
{
float2 uvPosition = VAT_uvPosition(uvIndex, numOfFrames, speed, time, paddedRatio);
float4 texturePos = positionMap.SampleLevel(texSampler, uvPosition, 0);
float4 textureCd = colorMap.SampleLevel(texSampler, uvPosition, 0);
texturePos.xyz = lerp(positionBounds.x, positionBounds.y, texturePos.xyz);
outNormal = float3(1.0, 0.0, 0.0);
//create camera facing billboard based on uv coordinates
float3 cameraF = float3(0.5 - uv.x, uv.y - 0.5, 0);
cameraF *= float3(widthHeight.x, widthHeight.y, 1);
cameraF = mul(cameraF, MV);
outPosition = cameraF + texturePos.xyz;
outColor = textureCd.xyz;
}

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 02d1c270a9fbbbb409ce4b0951c20c65
ShaderImporter:
externalObjects: {}
defaultTextures: []
nonModifiableTextures: []
userData:
assetBundleName:
assetBundleVariant: