summaryrefslogtreecommitdiffstats
path: root/vertex.cginc
blob: eba7031421fd46879d9a67f09fa084a42ca22581 (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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#ifndef __VERTEX_INC
#define __VERTEX_INC

#include "vertex_deformation.hlsl"

#define FOO(x) (x)

void deform(inout float3 objPos) {
#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
  {
    float t = _Vertex_Deformation_XZ_Tube_t;
    objPos = plane_to_tube(objPos.xyz, t);
  }
#endif  // _VERTEX_DEFORMATION_XZ_TUBE
#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
  {
    float t = _Vertex_Deformation_YZ_Tube_t;
    objPos = plane_to_tube(objPos.yxz, t);
    objPos = objPos.yxz;
  }
#endif  // _VERTEX_DEFORMATION_YZ_TUBE
#if defined(_VERTEX_DEFORMATION_XY_TUBE)
  {
    float t = _Vertex_Deformation_XY_Tube_t;
    objPos = plane_to_tube(objPos.xzy, t);
    objPos = objPos.xzy;
  }
#endif  // _VERTEX_DEFORMATION_XY_TUBE
#if defined(_VERTEX_DEFORMATION_SEAL)
  {
    float A = _Vertex_Deformation_Seal_A;
    float k = _Vertex_Deformation_Seal_k;
    float t = _Time[3] * _Vertex_Deformation_Seal_t;
    objPos = seal(objPos.xyz, A, k, t);
  }
#endif  // _VERTEX_DEFORMATION_SEAL
#if defined(_VERTEX_DEFORMATION_SINE_WAVES)
  {
    float t = _Time[3];
    float3 amplitude = _Vertex_Deformation_Sine_Waves_Amplitude;
    float3 direction = _Vertex_Deformation_Sine_Waves_Direction;
    float3 k = _Vertex_Deformation_Sine_Waves_k;
    float3 omega = _Vertex_Deformation_Sine_Waves_omega;
    objPos = sine_wave(objPos.xyz, amplitude, direction, k, omega, t);
  }
#endif  // _VERTEX_DEFORMATION_SINE_WAVES
#if defined(_VERTEX_DEFORMATION_FBM)
  {
    float t = _Time[3];
    float amplitude = _Vertex_Deformation_FBM_Amplitude;
    float gain = _Vertex_Deformation_FBM_Gain;
    float lacunarity = _Vertex_Deformation_FBM_Lacunarity;
    float scale = _Vertex_Deformation_FBM_Scale;
    float octaves = _Vertex_Deformation_FBM_Octaves;
    float3 velocity = _Vertex_Deformation_FBM_Velocity;
    objPos = fbm(
        objPos,
        t,
        amplitude,
        gain,
        lacunarity,
        scale,
        octaves,
        velocity);
  }
#endif  // _VERTEX_DEFORMATION_FBM
}

void deform_normal(float3 objPos, inout float3 objNorm, inout float3 objTan) {
#if defined(_VERTEX_DEFORMATION_XZ_TUBE)
  {
    float t = _Vertex_Deformation_XZ_Tube_t;
    plane_to_tube_normal(objPos, objNorm, objTan, t);
  }
#endif  // _VERTEX_DEFORMATION_XZ_TUBE
#if defined(_VERTEX_DEFORMATION_YZ_TUBE)
  {
    float t = _Vertex_Deformation_YZ_Tube_t;
    plane_to_tube_normal(objPos.yxz, objNorm.yxz, objTan.yxz, t);
  }
#endif  // _VERTEX_DEFORMATION_YZ_TUBE
#if defined(_VERTEX_DEFORMATION_XY_TUBE)
  {
    float t = _Vertex_Deformation_XY_Tube_t;
    plane_to_tube_normal(objPos.xzy, objNorm.xzy, objTan.xzy, t);
  }
#endif  // _VERTEX_DEFORMATION_XY_TUBE
#if defined(_VERTEX_DEFORMATION_SEAL)
  {
    float A = _Vertex_Deformation_Seal_A;
    float k = _Vertex_Deformation_Seal_k;
    float t = _Time[3] * _Vertex_Deformation_Seal_t;
    seal_normal(objPos, objNorm, objTan, A, k, t);
  }
#endif  // _VERTEX_DEFORMATION_SEAL
#if defined(_VERTEX_DEFORMATION_SINE_WAVES)
  {
    float t = _Time[3];
    float3 amplitude = _Vertex_Deformation_Sine_Waves_Amplitude;
    float3 direction = _Vertex_Deformation_Sine_Waves_Direction;
    float3 k = _Vertex_Deformation_Sine_Waves_k;
    float3 omega = _Vertex_Deformation_Sine_Waves_omega;
    sine_wave_normal(objPos, objNorm, objTan, amplitude, direction, k, omega, t);
  }
#endif  // _VERTEX_DEFORMATION_SINE_WAVES
#if defined(_VERTEX_DEFORMATION_FBM)
  {
    float t = _Time[3];
    float amplitude = _Vertex_Deformation_FBM_Amplitude;
    float gain = _Vertex_Deformation_FBM_Gain;
    float lacunarity = _Vertex_Deformation_FBM_Lacunarity;
    float scale = _Vertex_Deformation_FBM_Scale;
    float octaves = _Vertex_Deformation_FBM_Octaves;
    float3 velocity = _Vertex_Deformation_FBM_Velocity;
    fbm_normal(
        objPos,
        objNorm,
        objTan,
        t,
        amplitude,
        gain,
        lacunarity,
        scale,
        octaves,
        velocity);
  }
#endif  // _VERTEX_DEFORMATION_FBM
}

void propagateObjPos(inout v2f i) {
  i.worldPos = mul(unity_ObjectToWorld, float4(i.objPos, 1));
  i.pos = UnityObjectToClipPos(i.objPos);
  i.eyeVec.xyz = i.worldPos - _WorldSpaceCameraPos;
}

#endif  // __VERTEX_INC