-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathLightProbeUtility.cs
More file actions
72 lines (61 loc) · 2.05 KB
/
LightProbeUtility.cs
File metadata and controls
72 lines (61 loc) · 2.05 KB
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
using UnityEngine;
using UnityEngine.Rendering;
public static class LightProbeUtility
{
// Set SH coefficients to MaterialPropertyBlock
public static void SetSHCoefficients(
Vector3 position, MaterialPropertyBlock properties
)
{
SphericalHarmonicsL2 sh;
LightProbes.GetInterpolatedProbe(position, null, out sh);
// Constant + Linear
for (var i = 0; i < 3; i++)
properties.SetVector(_idSHA[i], new Vector4(
sh[i, 3], sh[i, 1], sh[i, 2], sh[i, 0] - sh[i, 6]
));
// Quadratic polynomials
for (var i = 0; i < 3; i++)
properties.SetVector(_idSHB[i], new Vector4(
sh[i, 4], sh[i, 6], sh[i, 5] * 3, sh[i, 7]
));
// Final quadratic polynomial
properties.SetVector(_idSHC, new Vector4(
sh[0, 8], sh[2, 8], sh[1, 8], 1
));
}
// Set SH coefficients to Material
public static void SetSHCoefficients(
Vector3 position, Material material
)
{
SphericalHarmonicsL2 sh;
LightProbes.GetInterpolatedProbe(position, null, out sh);
// Constant + Linear
for (var i = 0; i < 3; i++)
material.SetVector(_idSHA[i], new Vector4(
sh[i, 3], sh[i, 1], sh[i, 2], sh[i, 0] - sh[i, 6]
));
// Quadratic polynomials
for (var i = 0; i < 3; i++)
material.SetVector(_idSHB[i], new Vector4(
sh[i, 4], sh[i, 6], sh[i, 5] * 3, sh[i, 7]
));
// Final quadratic polynomial
material.SetVector(_idSHC, new Vector4(
sh[0, 8], sh[2, 8], sh[1, 8], 1
));
}
static int[] _idSHA = {
Shader.PropertyToID("unity_SHAr"),
Shader.PropertyToID("unity_SHAg"),
Shader.PropertyToID("unity_SHAb")
};
static int[] _idSHB = {
Shader.PropertyToID("unity_SHBr"),
Shader.PropertyToID("unity_SHBg"),
Shader.PropertyToID("unity_SHBb")
};
static int _idSHC =
Shader.PropertyToID("unity_SHC");
}