source: GTP/trunk/App/Demos/Vis/FriendlyCulling/src/shaders/common.h @ 3230

Revision 3230, 1.2 KB checked in by mattausch, 16 years ago (diff)

fast and cool
not using kernel for high convergence

Line 
1/************************************/
2/*     Common shader functions      */
3/************************************/
4
5/** Interpolate bilinearly between 2 vectors
6*/
7inline 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*/
19inline 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
32inline float SqrLen(float3 v)
33{
34        return v.x * v.x + v.y * v.y + v.z * v.z;
35}
36
37
38inline 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
50
51inline float2 myrotate(float2 pt, float angle)
52{
53        float2 rpt;
54
55        rpt.x = pt.x * cos(angle) - pt.y * sin(angle);
56        rpt.y = pt.y * cos(angle) + pt.x * sin(angle);
57
58        //normalize(rpt);
59        return rpt;
60}
61
62
63#define USE_GTX
Note: See TracBrowser for help on using the repository browser.