Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

122 lines
3.2 KiB

  1. // STATIC: "BASETEXTURE" "0..1"
  2. // STATIC: "ENVMAP" "0..1"
  3. // STATIC: "ENVMAPMASK" "0..1"
  4. // STATIC: "SELFILLUM" "0..1"
  5. // STATIC: "BASEALPHAENVMAPMASK" "0..1"
  6. // SKIP: !$ENVMAP && ( $BASEALPHAENVMAPMASK || $ENVMAPMASK )
  7. // SKIP: !$BASETEXTURE && $BASEALPHAENVMAPMASK
  8. // SKIP: $BASEALPHAENVMAPMASK && $ENVMAPMASK
  9. // SKIP: !$BASETEXTURE && $BASEALPHAENVMAPMASK
  10. // SKIP: $SELFILLUM && $BASEALPHAENVMAPMASK
  11. // SKIP: !$BASETEXTURE && $SELFILLUM
  12. const float3 g_OverbrightFactor : register( c0 );
  13. const float3 g_SelfIllumTint : register( c1 );
  14. const float3 g_EnvmapTint : register( c2 );
  15. sampler BaseTextureSampler : register( s0 );
  16. sampler LightmapSampler : register( s1 );
  17. sampler EnvmapSampler : register( s2 );
  18. sampler EnvmapMaskSampler : register( s3 );
  19. //sampler DetailSampler : register( s3 );
  20. struct PS_INPUT
  21. {
  22. float2 baseTexCoord : TEXCOORD0;
  23. float2 lightmapTexCoord : TEXCOORD1;
  24. float3 envmapTexCoord : TEXCOORD2;
  25. float2 envmapMaskTexCoord : TEXCOORD3;
  26. float4 vertexColor : COLOR0;
  27. };
  28. float4 main( PS_INPUT i ) : COLOR
  29. {
  30. bool bBaseTexture = BASETEXTURE ? true : false;
  31. bool bEnvmap = ENVMAP ? true : false;
  32. bool bEnvmapMask = ENVMAPMASK ? true : false;
  33. bool bSelfIllum = SELFILLUM ? true : false;
  34. bool bBaseAlphaEnvmapMask = BASEALPHAENVMAPMASK ? true : false;
  35. #if 1
  36. float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  37. if( bBaseTexture )
  38. {
  39. baseColor = tex2D( BaseTextureSampler, i.baseTexCoord );
  40. }
  41. float3 specularFactor = 1.0f;
  42. if( bEnvmapMask )
  43. {
  44. specularFactor *= tex2D( EnvmapMaskSampler, i.envmapMaskTexCoord ).xyz;
  45. }
  46. if( bBaseAlphaEnvmapMask )
  47. {
  48. specularFactor *= 1.0 - baseColor.a; // this blows!
  49. }
  50. float3 diffuseLighting = tex2D( LightmapSampler, i.lightmapTexCoord );
  51. float3 albedo = float3( 1.0f, 1.0f, 1.0f );
  52. float alpha = 1.0f;
  53. if( bBaseTexture )
  54. {
  55. albedo *= baseColor;
  56. if( !bBaseAlphaEnvmapMask && !bSelfIllum )
  57. {
  58. alpha *= baseColor.a;
  59. }
  60. }
  61. // The vertex color contains the modulation color + vertex color combined
  62. albedo *= i.vertexColor;
  63. alpha *= i.vertexColor.a; // not sure about this one
  64. float3 diffuseComponent = ( albedo * diffuseLighting * 2.0f ) * g_OverbrightFactor;
  65. if( bSelfIllum )
  66. {
  67. float3 selfIllumComponent = g_SelfIllumTint * albedo;
  68. diffuseComponent = lerp( diffuseComponent, selfIllumComponent, baseColor.a );
  69. }
  70. float3 specularLighting = float3( 0.0f, 0.0f, 0.0f );
  71. if( bEnvmap )
  72. {
  73. specularLighting = tex2D( EnvmapSampler, i.envmapTexCoord );
  74. specularLighting *= specularFactor;
  75. specularLighting *= g_EnvmapTint;
  76. }
  77. float3 result = diffuseComponent + specularLighting;
  78. return float4( result, alpha );
  79. #endif
  80. #if 0
  81. float4 baseColor = float4( 1.0f, 1.0f, 1.0f, 1.0f );
  82. float3 diffuseLighting = tex2D( LightmapSampler, i.lightmapTexCoord );
  83. float3 albedo = float3( 1.0f, 1.0f, 1.0f );
  84. float alpha = 1.0f;
  85. albedo *= i.vertexColor;
  86. alpha *= i.vertexColor.a; // not sure about this one
  87. float3 diffuseComponent = ( albedo * diffuseLighting * 2.0f ) * g_OverbrightFactor;
  88. float3 result = diffuseComponent;
  89. return float4( result, alpha );
  90. #endif
  91. #if 0
  92. float4 result;
  93. result.rgb = tex2D( LightmapSampler, i.lightmapTexCoord ).rgb * i.vertexColor.rgb;
  94. result.a = i.vertexColor.a;
  95. result.rgb = ( result.rgb * g_OverbrightFactor ) * 2.0f;
  96. return result;
  97. #endif
  98. }