A game about forced loneliness, made by TACStudios
1# Sample Gradient Node
2
3## Description
4
5Samples a **Gradient** given the input of **Time**. Returns a **Vector 4** color value for use in the shader.
6
7## Ports
8
9| Name | Direction | Type | Binding | Description |
10|:------------ |:-------------|:-----|:---|:---|
11| Gradient | Input | Gradient | None | Gradient to sample |
12| Time | Input | Float | None | Point at which to sample gradient (0.0–1.0) |
13| Out | Output | Vector 4 | None | Output value as Vector4 |
14
15## Generated Code Example
16
17The following example code represents one possible outcome of this node.
18
19```
20void Unity_SampleGradient_float(float4 Gradient, float Time, out float4 Out)
21{
22 float3 color = Gradient.colors[0].rgb;
23 [unroll]
24 for (int c = 1; c < 8; c++)
25 {
26 float colorPos = saturate((Time - Gradient.colors[c-1].w) / (Gradient.colors[c].w - Gradient.colors[c-1].w)) * step(c, Gradient.colorsLength-1);
27 color = lerp(color, Gradient.colors[c].rgb, lerp(colorPos, step(0.01, colorPos), Gradient.type));
28 }
29#ifndef UNITY_COLORSPACE_GAMMA
30 color = SRGBToLinear(color);
31#endif
32 float alpha = Gradient.alphas[0].x;
33 [unroll]
34 for (int a = 1; a < 8; a++)
35 {
36 float alphaPos = saturate((Time - Gradient.alphas[a-1].y) / (Gradient.alphas[a].y - Gradient.alphas[a-1].y)) * step(a, Gradient.alphasLength-1);
37 alpha = lerp(alpha, Gradient.alphas[a].x, lerp(alphaPos, step(0.01, alphaPos), Gradient.type));
38 }
39 Out = float4(color, alpha);
40}
41```