www.pudn.com > GPU-KLT-1.0.zip > pyramid_with_derivative_pass1v.cg


/*
Copyright (c) 2008 University of North Carolina at Chapel Hill

This file is part of GPU-KLT.

GPU-KLT is free software: you can redistribute it and/or modify it under the
terms of the GNU Lesser General Public License as published by the Free
Software Foundation, either version 3 of the License, or (at your option) any
later version.

GPU-KLT is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
details.

You should have received a copy of the GNU Lesser General Public License along
with GPU-KLT. If not, see .
*/

void main(uniform sampler2D src_tex : TEXUNIT0,
                            float4 st0 : TEXCOORD0,
                            float4 st1 : TEXCOORD1,
                            float4 st2 : TEXCOORD2,
                            float4 st3 : TEXCOORD3,
                        out float4 color : COLOR)
{
#if 0
   // This is the (odd) binomial kernel [0 1 6 15 20 15 6 1 0]
   float4 const f1 = float4(0, 1, 6, 15) / 64.0f;
   float4 const f2 = float4(20, 15, 6, 1) / 64.0f;

   float4 const df = float4(1, 6, 14, 14) / 128.0f;

   float2 ds = st0.zw - st0.xy;

   float4 g1, g2;
   float  g3;
   g1.x = tex2D(src_tex, st0.xy - ds).x;
   g1.y = tex2D(src_tex, st0.xy).x;
   g1.z = tex2D(src_tex, st0.zw).x;
   g1.w = tex2D(src_tex, st1.xy).x;
   g2.x = tex2D(src_tex, st1.zw).x;
   g2.y = tex2D(src_tex, st2.xy).x;
   g2.z = tex2D(src_tex, st2.zw).x;
   g2.w = tex2D(src_tex, st3.xy).x;
   g3   = tex2D(src_tex, st3.zw).x;

   g1 *= 255.0f;
   g2 *= 255.0f;
   g3 *= 255.0f;

   float v = dot(f1, g1) + dot(f2, g2);
   float dv = -dot(df, g1) + dot(df, float4(g2.yzw, g3));
#elif 0
   // This is the (odd) binomial kernel [0 1 4 6 4 1 0]
   float4 const f1 = float4(0, 1, 4, 6) / 16.0f;
   float3 const f2 = float3(4, 1, 0) / 16.0f;

   float4 const df1 = float4(-1, -4, -5, 0) / 32.0f;
   float3 const df2 = float3(5, 4, 1) / 32.0f;

   float4 g1;
   float3 g2;

   g1.x = tex2D(src_tex, st0.xy).x;
   g1.y = tex2D(src_tex, st0.zw).x;
   g1.z = tex2D(src_tex, st1.xy).x;
   g1.w = tex2D(src_tex, st1.zw).x;
   g2.x = tex2D(src_tex, st2.xy).x;
   g2.y = tex2D(src_tex, st2.zw).x;
   g2.z = tex2D(src_tex, st3.xy).x;

   g1 *= 255.0f;
   g2 *= 255.0f;

   float v = dot(f1, g1) + dot(f2, g2);
   float dv = dot(df1, g1) + dot(df2, g2);
#else
   // This is the (odd) binomial kernel [0 1 2 1 0]
   float4 const f1 = float4(0, 1, 2, 1) / 4.0f;

   float4 const df1 = float4(-1, -2, 0, 2) / 8.0f;
   float  const df2 = 1.0 / 8.0f;

   float4 g1;
   float  g2;

   g1.x = tex2D(src_tex, st0.zw);
   g1.y = tex2D(src_tex, st1.xy);
   g1.z = tex2D(src_tex, st1.zw);
   g1.w = tex2D(src_tex, st2.xy);
   g2   = tex2D(src_tex, st2.zw);

   g1 *= 255.0f;
   g2 *= 255.0f;

   float v = dot(f1, g1);
   float dv = dot(df1, g1) + df2*g2;
#endif

   color.xy = unpack_2half(v);
   color.zw = unpack_2half(dv);
}