/************************************/ /* Common shader functions */ /************************************/ /** Interpolate bilinearly between 2 vectors */ inline float3 Interpol(float2 w, float3 bl, float3 br, float3 tl, float3 tr) { float3 x1 = lerp(bl, tl, w.y); float3 x2 = lerp(br, tr, w.y); float3 v = lerp(x1, x2, w.x); return v; } /** reconstruct world space position */ inline float3 ReconstructSamplePos(uniform sampler2D tex, float2 texcoord, float3 bl, float3 br, float3 tl, float3 tr) { const float eyeSpaceDepth = tex2Dlod(tex, float4(texcoord, 0, 0)).w; float3 viewVec = Interpol(texcoord, bl, br, tl, tr); float3 samplePos = -viewVec * eyeSpaceDepth; return samplePos; } inline float SqrLen(float3 v) { return v.x * v.x + v.y * v.y + v.z * v.z; } inline float2 myreflect(float2 pt, float2 n) { // distance to plane float d = dot(n, pt); // reflect around plane float2 rpt = pt - d * 2.0f * n; return rpt; } inline float2 myrotate(float2 pt, float angle) { float2 rpt; rpt.x = pt.x * cos(angle) - pt.y * sin(angle); rpt.y = pt.y * cos(angle) + pt.x * sin(angle); //normalize(rpt); return rpt; }