[3213] | 1 | /************************************/
|
---|
| 2 | /* Common shader functions */
|
---|
| 3 | /************************************/
|
---|
| 4 |
|
---|
| 5 | /** Interpolate bilinearly between 2 vectors
|
---|
| 6 | */
|
---|
[3170] | 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 |
|
---|
[3213] | 17 | /** reconstruct world space position
|
---|
| 18 | */
|
---|
[3170] | 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 | }
|
---|