Advertisement
mrDIMAS

Shader

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