1 | /************************************/
|
---|
2 | /* Common shader functions */
|
---|
3 | /************************************/
|
---|
4 |
|
---|
5 | /** Interpolate bilinearly between 2 vectors
|
---|
6 | */
|
---|
7 | inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr)
|
---|
8 | {
|
---|
9 | float3 x1 = lerp(bl, tl, w.y);
|
---|
10 | float3 x2 = lerp(br, tr, w.y);
|
---|
11 | float3 v = lerp(x1, x2, w.x);
|
---|
12 |
|
---|
13 | return v;
|
---|
14 | }
|
---|
15 |
|
---|
16 |
|
---|
17 | /** reconstruct world space position
|
---|
18 | */
|
---|
19 | inline float3 ReconstructSamplePos(uniform sampler2D tex,
|
---|
20 | float2 texcoord,
|
---|
21 | float3 bl, float3 br, float3 tl, float3 tr)
|
---|
22 | {
|
---|
23 | const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w;
|
---|
24 |
|
---|
25 | float3 viewVec = Interpol(texcoord, bl, br, tl, tr);
|
---|
26 | float3 samplePos = -viewVec * eyeSpaceDepth;
|
---|
27 |
|
---|
28 | return samplePos;
|
---|
29 | }
|
---|
30 |
|
---|
31 |
|
---|
32 | inline float SqrLen(float3 v)
|
---|
33 | {
|
---|
34 | return v.x * v.x + v.y * v.y + v.z * v.z;
|
---|
35 | }
|
---|
36 |
|
---|
37 |
|
---|
38 | inline float2 myreflect(float2 pt, float2 n)
|
---|
39 | {
|
---|
40 | // distance to plane
|
---|
41 | float d = dot(n, pt);
|
---|
42 | // reflect around plane
|
---|
43 | float2 rpt = pt - d * 2.0f * n;
|
---|
44 |
|
---|
45 | return rpt;
|
---|
46 | }
|
---|
47 |
|
---|
48 |
|
---|
49 | inline float2 myrotate(float2 pt, float angle)
|
---|
50 | {
|
---|
51 | float2 rpt;
|
---|
52 |
|
---|
53 | rpt.x = pt.x * cos(angle) - pt.y * sin(angle);
|
---|
54 | rpt.y = pt.y * cos(angle) + pt.x * sin(angle);
|
---|
55 |
|
---|
56 | //normalize(rpt);
|
---|
57 | return rpt;
|
---|
58 | }
|
---|
59 |
|
---|