www.pudn.com > fluid.rar > substance.fx, change:2006-10-28,size:1834b


#include "util.fxh" 
 
float4 g_srcColor; 
float2 g_srcPos_rt; 
float  g_srcR; 
float2 g_unit; //1/(d *velocity field texture size) 
float  g_dt; //delta time 
 
float2 g_sTexSize;   //substance texture size 
float2 g_sTexelSize;//substance texel size 
float2 g_vTexSize;   //velocity texture size 
float2 g_vTexelSize; //velocity textel size 
 
float  g_dis; //dissipate; 
texture substanceTex; 
sampler substanceSam = sampler_state 
{ 
   texture =<substanceTex>; 
   addressU = clamp; 
   addressV =clamp; 
   minfilter =linear; 
   mipfilter =linear; 
   magfilter =linear; 
}; 
 
texture velFieldTex; //velocity field 
sampler velFieldSam = sampler_state 
{ 
  texture = <velFieldTex>; 
  AddressU =clamp; 
  AddressV =clamp; 
  MinFilter =point; 
  MipFilter =point; 
  MagFilter =point; 
}; 
 
void injectSourcePS(float2 pos_rt:TEXCOORD0, 
            out float4 oCol:COLOR) 
{ 
   oCol = tex2D(substanceSam,pos_rt); 
    
   float dist = distance(pos_rt,g_srcPos_rt); 
   float amount = max(0.0,sign(g_srcR-dist)); 
   oCol +=amount*g_srcColor; 
 
} 
 
void timeStep(float2 pos_rt:TEXCOORD0, 
          out float4 oSubs:COLOR) 
{ 
 
  float2 vel = tex2D_bilinear(velFieldSam,pos_rt,g_vTexSize,g_vTexelSize.x,g_vTexelSize.y).xy; 
  float2 dp = -vel*g_dt*g_unit; 
  dp.y = -dp.y; 
  oSubs = g_dis*tex2DRect_bilinear(substanceSam,pos_rt+dp,g_sTexSize,g_sTexelSize); 
   
  //oSubs = float4((vel+1.0)/2.0,0,1); 
      
} 
technique substance 
{ 
   pass p0 
   {  
      cullmode= none; 
      zenable=false; 
  
      VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
      PixelShader = compile ps_3_0 injectSourcePS(); 
   } 
   pass timeStep 
   {  
      cullmode= none; 
      zenable=false; 
  
      VertexShader = compile vs_3_0 screenAlignedQuadFVS(); 
      PixelShader = compile ps_3_0 timeStep(); 
   } 
    
}