summaryrefslogtreecommitdiffstats
path: root/shear_math.cginc
blob: a2eded2fdc722cef6bbbc1e068cc8633bcae26cf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#ifndef __SHEAR_MATH_INC
#define __SHEAR_MATH_INC

#if defined(_GIMMICK_SHEAR_LOCATION)

void getMeshRendererMatrices(bool invert, out float3x3 rot_fix,
    out float4x4 ts_fix) {
  if (_Gimmick_Shear_Location_Mesh_Renderer_Fix) {
    float3 theta = float3(
        _Gimmick_Shear_Location_Mesh_Renderer_Rotation.x,
        _Gimmick_Shear_Location_Mesh_Renderer_Rotation.y,
        _Gimmick_Shear_Location_Mesh_Renderer_Rotation.z);
    theta = invert ? -theta : theta;
    float3x3 rotate_x = float3x3(
        1, 0, 0,
        0, cos(theta.x), -sin(theta.x),
        0, sin(theta.x), cos(theta.x));
    float3x3 rotate_y = float3x3(
        cos(theta.y), 0, sin(theta.y),
        0, 1, 0,
        -sin(theta.y), 0, cos(theta.y));
    float3x3 rotate_z = float3x3(
        cos(theta.z), -sin(theta.z), 0,
        sin(theta.z), cos(theta.z), 0,
        0, 0, 1);
    rot_fix = invert ?
      mul(rotate_x, mul(rotate_y, rotate_z)) :
      mul(rotate_z, mul(rotate_y, rotate_x));
    float3 scale = float3(
        _Gimmick_Shear_Location_Mesh_Renderer_Scale.x,
        _Gimmick_Shear_Location_Mesh_Renderer_Scale.y,
        _Gimmick_Shear_Location_Mesh_Renderer_Scale.z);
    scale = invert ? 1 / scale : scale;
    float3 offset = float3(
        _Gimmick_Shear_Location_Mesh_Renderer_Offset.x,
        _Gimmick_Shear_Location_Mesh_Renderer_Offset.y,
        _Gimmick_Shear_Location_Mesh_Renderer_Offset.z);
    offset = invert ? -offset : offset;
    ts_fix = float4x4(
        scale.x, 0, 0, offset.x,
        0, scale.y, 0, offset.y,
        0, 0, scale.z, offset.z,
        0, 0, 0, 1);
  } else {
    rot_fix = float3x3(
        1, 0, 0,
        0, 1, 0,
        0, 0, 1);
    ts_fix = float4x4(
        1, 0, 0, 0,
        0, 1, 0, 0,
        0, 0, 1, 0,
        0, 0, 0, 1);
  }
}

#endif  // _GIMMICK_SHEAR_LOCATION

#endif  // __SHEAR_MATH_INC