Newer
Older
Hierarchical-Task-Network-Unity-3D / Assets / Shaders / HLSL / Common.hlsl
float easeOut(float x, float t)
{
    return 1.0 - pow(1.0 - x, t);
}

float easeIn(float x, float t)
{
    return pow(x, t);
}

void easeIn_float(float x, float t, out float result)
{
    result = easeIn(x, t);
}

void easeOut_float(float x, float t, out float result)
{
    result = easeOut(x, t);
}

// Rotation matrix around the X axis.
float3x3 rotateX(float theta)
{
    float c = cos(theta);
    float s = sin(theta);
    return float3x3(
        float3(1, 0, 0),
        float3(0, c, -s),
        float3(0, s, c)
    );
}

// Rotation matrix around the Y axis.
float3x3 rotateY(float theta)
{
    float c = cos(theta);
    float s = sin(theta);
    return float3x3(
        float3(c, 0, s),
        float3(0, 1, 0),
        float3(-s, 0, c)
    );
}


// Rotation matrix around the Z axis.
float3x3 rotateZ(float theta)
{
    float c = cos(theta);
    float s = sin(theta);
    return float3x3(
        float3(c, -s, 0),
        float3(s, c, 0),
        float3(0, 0, 1)
    );
}


float3x3 rotateAxis(float3 axis, float angle)
{
    axis = normalize(axis);
    float s = sin(angle);
    float c = cos(angle);
    float oc = 1.0 - c;

    return float3x3(
    oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s,
    oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s,
    oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c
  );
}

//For Custom Nodes In Shader Graph
void rotateX_float(float theta, out float3x3 rotation)
{
    rotation = rotateX(theta);
}

void rotateY_float(float theta, out float3x3 rotation)
{
    rotation = rotateY(theta);
}

void rotateZ_float(float theta, out float3x3 rotation)
{
    rotation = rotateZ(theta);
}

void rotateAxis_float(float3 axis, float angle, out float3x3 rotation)
{
    rotation = rotateAxis(axis, angle);
}