summaryrefslogtreecommitdiff
path: root/Other/AstarPathfindingDemo/Packages/com.arongranberg.astar/Drawing/Resources/aline_common.cginc
blob: 00642406c55e2be325cf6024d0c64d62471837e8 (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

#ifdef UNITY_HDRP
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Common.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
#include "Packages/com.unity.render-pipelines.high-definition/Runtime/ShaderLibrary/ShaderVariables.hlsl"
#include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"

// Unity does not define the UNITY_DECLARE_TEX2D macro when using HDRP, at least at the time of writing this.
// But luckily HDRP is only supported on platforms where separate sampler states are supported, so we can define it like this.
#if !defined(UNITY_DECLARE_TEX2D)
// This is copied from com.unity.shadergraph@14.0.6/Editor/Generation/Targets/BuiltIn/ShaderLibrary/Shim/HLSLSupportShim.hlsl
#define UNITY_DECLARE_TEX2D(tex) TEXTURE2D(tex); SAMPLER(sampler##tex)
#endif

#if !defined(UNITY_SAMPLE_TEX2D)
#define UNITY_SAMPLE_TEX2D(tex,coord) SAMPLE_TEXTURE2D(tex, sampler##tex, coord)
#endif

// This is not defined in HDRP either, but we do know that HDRP only supports these platforms (at least I think so...)
#define UNITY_SEPARATE_TEXTURE_SAMPLER

#else
#include "UnityCG.cginc"

// These exist in the render pipelines, but not in UnityCG
float4 TransformObjectToHClip(float3 x) {
	return UnityObjectToClipPos(float4(x, 1.0));
}

half3 FastSRGBToLinear(half3 sRGB) {
	return GammaToLinearSpace(sRGB);
}
#endif

// Tranforms a direction from object to homogenous space
inline float4 UnityObjectToClipDirection(in float3 pos) {
	// More efficient than computing M*VP matrix product
	return mul(UNITY_MATRIX_VP, mul(UNITY_MATRIX_M, float4(pos, 0)));
}

float lengthsq(float3 v) {
	return dot(v,v);
}

float4 ComputeScreenPos (float4 pos, float projectionSign)
{
  float4 o = pos * 0.5f;
  o.xy = float2(o.x, o.y * projectionSign) + o.w;
  o.zw = pos.zw;
  return o;
}


// Converts to linear space from sRGB if linear is the current color space
inline float3 ConvertSRGBToDestinationColorSpace(float3 sRGB) {
#ifdef UNITY_COLORSPACE_GAMMA
	return sRGB;
#else
	return FastSRGBToLinear(sRGB);
#endif
}

struct appdata_color {
	float4 vertex : POSITION;
	half4 color : COLOR;
	float3 normal : NORMAL;
	float2 uv : TEXCOORD0;
	UNITY_VERTEX_INPUT_INSTANCE_ID
};

// Unity sadly does not include a bias macro for texture sampling.
#if defined(UNITY_SEPARATE_TEXTURE_SAMPLER)
#define UNITY_SAMPLE_TEX2D_BIAS(tex, uv, bias) tex.SampleBias(sampler##tex, uv, bias)
#else
#define UNITY_SAMPLE_TEX2D_BIAS(tex, uv, bias) tex2Dbias(float4(uv, 0, bias))
#endif