home *** CD-ROM | disk | FTP | other *** search
/ GameStar 2006 April / Gamestar_83_2006-04_dvd.iso / Dema / demowot_english.exe / InfDX / x / notused / deferred-point2-pixel.hlsl < prev    next >
Text File  |  2005-03-22  |  2KB  |  57 lines

  1. struct VS_OUTPUT
  2. {
  3.     float4 Transformed    : TEXCOORD0;
  4.     float4 Attrib        : TEXCOORD1;
  5.     float4 Color        : TEXCOORD2;
  6.     float3 LightInView  : TEXCOORD3;
  7.     float4 FustrumPos   : TEXCOORD4;
  8.     float4 ViewToLight0 : TEXCOORD5;
  9.     float4 ViewToLight1 : TEXCOORD6;
  10.     float4 ViewToLight2 : TEXCOORD7;
  11. };
  12.  
  13. float4x4 TDX_CONST_INVPROJ;
  14. float4x4 TDX_CONST_INVVIEW;
  15. float4x4 TDX_CONST_INVVIEWPROJ;
  16. float4 TDX_CONST_LIGHTCONTRIB;
  17.  
  18. sampler sampler_normal : register(s0); // normal
  19. sampler sampler_position : register(s1); // position
  20. sampler sampler_projector : register(s3); // projector
  21.  
  22. float4 main(VS_OUTPUT In) : COLOR
  23. {
  24.     float4 FinalColor;
  25.     
  26.     // normalvector
  27.     float4 Normal=tex2Dproj(sampler_normal, In.Transformed)*2-1;
  28.  
  29.     // extracting view space position
  30.     float4 Depth=tex2Dproj(sampler_position, In.Transformed);
  31.     float3 ViewSpacePos=(In.FustrumPos/In.FustrumPos.w)*Depth.r;
  32.  
  33.     // lighting parameters
  34.     float3 LightToFragment=ViewSpacePos-In.LightInView;
  35.     
  36.     float Distance=length(LightToFragment);
  37.     float3 LightToFragmentNorm=LightToFragment/Distance;
  38.     float4 Factor=(1-saturate(Distance/In.Attrib.y*1.75-0.75))*In.Color;
  39.     float DotProduct=saturate(dot(Normal, -LightToFragmentNorm));
  40.     
  41.     FinalColor=DotProduct*Factor;
  42.  
  43. /*#if TDX_SHADERFLAG_SPECULAR
  44.     float3 Reflected=normalize(reflect(ViewSpacePos, Normal.xyz));
  45.     float Specular=pow(saturate(dot(Reflected, -LightToFragmentNorm)),Normal.w*100);
  46.     FinalColor.rgb+=Factor*Specular*Albedo.a;
  47. #endif*/
  48.  
  49.     float3 LightToFragmentLS;
  50.     LightToFragmentLS.x=mul(LightToFragmentNorm, In.ViewToLight0);
  51.     LightToFragmentLS.y=mul(LightToFragmentNorm, In.ViewToLight1);
  52.     LightToFragmentLS.z=mul(LightToFragmentNorm, In.ViewToLight2);
  53.     FinalColor*=texCUBE(sampler_projector, LightToFragmentLS);
  54.  
  55.     return FinalColor*0.25;
  56. }  
  57.