Advertisement
mrDIMAS

Shader 2

May 31st, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. float4x4 wvp : register( c0 );
  2. float4x4 world : register( c5 );
  3.  
  4. #ifdef USE_LIGHTING
  5.  
  6. #define MAX_LIGHTS 16
  7.  
  8.     float3 lightPosition[ MAX_LIGHTS ] : register( c[10] );
  9.     float3 lightColor[ MAX_LIGHTS ] : register( c[27] );
  10.     float lightRange[ MAX_LIGHTS ] : register( c[44] );
  11.     float3 ambientColor : register( c[61] );
  12.     float lightCount : register( c[62] );
  13. #endif
  14.  
  15. struct VS_INPUT {
  16.     float4 position : POSITION;
  17.     float2 texcoord : TEXCOORD0;
  18.     float4 color : COLOR0;
  19. };
  20.  
  21. struct VS_OUTPUT {
  22.     float4 position : POSITION;
  23.     float2 texcoord : TEXCOORD0;
  24.     float4 color : TEXCOORD1;
  25. };
  26.  
  27. VS_OUTPUT main( VS_INPUT input ) {
  28.     VS_OUTPUT output;
  29.    
  30.     output.position = mul( wvp, input.position );
  31.     output.texcoord = input.texcoord;
  32.    
  33. #ifdef USE_LIGHTING
  34.     float4 worldPos = mul( world, input.position );
  35.     output.color = float4( ambientColor.xyz * input.color.xyz, 1.0f );
  36.     for( int i = 0; i < (int)lightCount; i++ ) {       
  37.         float distance = length( worldPos - lightPosition[i] );
  38.         float attenuation = saturate( lightRange[i].x * 1.25f / ( 1 + distance * distance ));
  39.         output.color.xyz += lightColor[i].xyz * attenuation;
  40.     }
  41.     output.color = saturate( output.color );
  42. #else
  43.     output.color = input.color;
  44. #endif
  45.    
  46.     return output;
  47. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement