www.pudn.com > fluid.rar > textureViewer.fx, change:2006-10-29,size:4636b


#include "util.fxh" 
 
float g_texSize; 
float g_dx; // 1/texture width 
float g_dy; // 1/texture height 
float2 g_magScale ={1.0f,1.0f}; // magnitude scale 
 
float2 g_RTTexSize; 
float2 g_RTTexelSize; 
 
texture vectorFieldTex; 
sampler g_vectorFieldSam = sampler_state 
{ 
  texture = <vectorFieldTex>; 
  addressU = clamp; 
  addressV = clamp; 
  magfilter = point; 
  minfilter = point; 
  mipfilter = point; 
}; 
 
 
texture magTex; 
sampler g_magSam = sampler_state 
{ 
  texture = <magTex>; 
  addressU = clamp; 
  addressV = clamp; 
  magfilter = linear; 
  minfilter = linear; 
  mipfilter = linear; 
}; 
//pos_rt : (x,y,z) x,y is vector, z = 0 indicate it is origin. 
//oColIndex   : vector's  magnitude. 
void quiverVectorFieldVS( 
                         float3 pos_rt:POSITION, 
                     out float4 oPos_rp:POSITION, 
                     out float  oColIndex:COLOR0 
                    )  
{ 
 
   float mag; //vector magnitude 
    //get color index  
    //---------------------------------------- 
    // /|\ y 
    //  |______\x 
    //         / 
    float2 vec = tex2Dlod_bilinear(g_vectorFieldSam,float4(pos_rt.xy,0,0), 
                                   g_texSize,g_dx,g_dy);//look up vector field 
    vec *=g_magScale; //scale vector to (-1,1) 
    mag = length(vec);//get magnitude 
    oColIndex = mag; 
    //get projection position 
    //----------------------------------------- 
    oPos_rp.xy = relTex2RelProj(pos_rt,g_dx,g_dy); 
    //oPos_rp.xy = relTex2RelProj(pos_rt+float2(g_dx,g_dy)*0.5f,g_dx,g_dy); 
         
    if(pos_rt.z > 0.5f) 
    { 
       //it is not origin, so displace it 
       oPos_rp.xy += vec; 
    } 
    oPos_rp.zw = float2(0.0,1.0); 
     
 
 
} 
 
void quiverVectorFieldPS( 
//                     float2 texcoord:TEXCOORD, 
                     float colIndex:COLOR0, 
//                     float4 col:COLOR1, 
                     out float4 oCol:COLOR0) 
{ 
 
  oCol = tex2D(g_magSam,float2(colIndex,0.5)); 
   
} 
 
texture srcTex; //source texture 
sampler srcSam = sampler_state 
{ 
  texture = <srcTex>; 
  addressU = clamp; 
  addressV = clamp; 
  magfilter = linear; 
  minfilter = linear; 
  mipfilter = linear; 
}; 
 
void colorVectorFieldPS(float2 texcoord:TEXCOORD, 
                 out float4 oCol:COLOR) 
{ 
  oCol = float4(tex2D_bilinear(g_vectorFieldSam,texcoord,g_texSize,g_dx,g_dy).xy *g_magScale , 
         0,1); 
  oCol = (oCol+1.0)/2.0; 
 
} 
 
void colorScalarFieldPS(float2 texcoord:TEXCOORD, 
                 out float4 oCol:COLOR) 
{ 
  float fMag =tex2D_bilinear(g_vectorFieldSam,texcoord, 
                             g_texSize,g_dx,g_dy).x *g_magScale; 
  fMag = fMag; 
  float4 col = float4(1,0,0,1); 
  if(fMag<0.0f) 
  { 
     col = float4(0,0,1,1); 
  } 
 
   
  oCol = abs(fMag)*col; 
   
  //oCol = float4(fMag.xxx,1); 
 
//  oCol = float4(tex2D(g_vectorFieldSam,texcoord).x *g_magScale , 
//         0,0,1); 
} 
 
void copyTexturePS(float2 texcoord:TEXCOORD, 
                 out float4 oCol:COLOR) 
{ 
  oCol = tex2D(srcSam,texcoord); 
} 
 
void smoothTexturePS(float2 texcoord:TEXCOORD, 
                 out float4 oCol:COLOR) 
{ 
 oCol = tex2D_bilinear(srcSam,texcoord,g_texSize,g_dx,g_dy); 
} 
 
 
 
 
technique quiverVectorField 
{ 
    pass copyTexture 
    { 
        cullmode = none; 
        ZEnable = false; 
        VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
        PixelShader = compile ps_3_0 copyTexturePS(); 
    } 
    pass drawVecField 
    { 
 
        VertexShader = compile vs_3_0 quiverVectorFieldVS(); 
        PixelShader = compile ps_3_0 quiverVectorFieldPS(); 
    } 
} 
 
technique colorVectorField 
{ 
    pass p0 
    { 
        cullmode = none; 
        ZEnable = false; 
        VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
        PixelShader = compile ps_3_0 colorVectorFieldPS(); 
    } 
} 
 
technique colorScalarField 
{ 
    pass p0 
    { 
        cullmode = none; 
        ZEnable = false; 
        VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
        PixelShader = compile ps_3_0 colorScalarFieldPS(); 
    } 
} 
 
technique viewColor 
{ 
    pass copyTexture 
    { 
        cullmode = none; 
        ZEnable = false; 
        VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
        PixelShader = compile ps_3_0 copyTexturePS(); 
    } 
     
    pass smoothTexture 
    { 
        cullmode = none; 
        ZEnable = false; 
        VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
        PixelShader = compile ps_3_0 smoothTexturePS(); 
    } 
} 
//-------------------------------------------------------------------------