www.pudn.com > 13_184353_cubemap.rar > vertex_dispersion.cg


// This binding semantic requires CG_PROFILE_ARBVP1 or higher. 
uniform float4x4 modelViewProj : state.matrix.mvp; 
 
            void main(float4 position : POSITION, 
                      float3 normal   : NORMAL, 
    
                  out float4 oPosition        : POSITION, 
                  out float  reflectionFactor : COLOR, 
                  out float3 R                : TEXCOORD0, 
                  out float3 TRed             : TEXCOORD1, 
                  out float3 TGreen           : TEXCOORD2, 
                  out float3 TBlue            : TEXCOORD3, 
 
              uniform float3 eyePositionW, 
              uniform float4x4 modelToWorld) 
{ 
  float fresnelBias = 0.1; 
  float fresnelScale = 0.3; 
  float fresnelPower = 0.2; 
  float3 etaRatio = float3(1.10, 1.12, 1.14); 
				 
  oPosition = mul(modelViewProj, position); 
 
  // Compute position and normal in world space 
  float3 positionW = mul(modelToWorld, position).xyz; 
  float3 N = mul((float3x3)modelToWorld, normal); 
  N = normalize(N); 
   
  // Compute the incident, reflected, and refracted vectors 
  float3 I = positionW - eyePositionW; 
  R = reflect(I, N);   
  I = normalize(I); 
  TRed   = refract(I, N, etaRatio.x); 
  TGreen = refract(I, N, etaRatio.y); 
  TBlue  = refract(I, N, etaRatio.z); 
 
  // Compute the reflection factor 
  reflectionFactor = fresnelBias +  
                     fresnelScale * pow(1 + dot(I, N),  
                                        fresnelPower ); 
}