forked from microsoft/MixedRealityToolkit-Unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHoloToolkitCommon.cginc
More file actions
30 lines (24 loc) · 984 Bytes
/
HoloToolkitCommon.cginc
File metadata and controls
30 lines (24 loc) · 984 Bytes
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
#ifndef HOLOTOOLKIT_COMMON
#define HOLOTOOLKIT_COMMON
float4 _NearPlaneFadeDistance;
// Helper function for focal plane fading
// Could instead be done non-linear in projected space for speed
inline float ComputeNearPlaneFadeLinear(float4 vertex)
{
float distToCamera = -(mul(UNITY_MATRIX_MV, vertex).z);
return saturate(mad(distToCamera, _NearPlaneFadeDistance.y, _NearPlaneFadeDistance.x));
}
// Diffuse lighting
inline float3 HoloTKLightingLambertian(float3 normal, float3 lightDir, float3 lightCol)
{
return lightCol * max(0, dot(normal, lightDir));
}
// Specular lighting
inline float3 HoloTKLightingBlinnPhong(float3 normal, float3 lightDir, float lightCol, float3 viewDir, float specularPower, float specularScale, float3 specularColor)
{
float3 h = normalize(lightDir + viewDir);
float nh = max(0, dot(normal, h));
float spec = pow(nh, specularPower) * specularScale;
return lightCol * specularColor * spec;
}
#endif //HOLOTOOLKIT_COMMON