global.inc 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /*
  2. ===========================================================================
  3. Doom 3 BFG Edition GPL Source Code
  4. Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company.
  5. This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code").
  6. Doom 3 BFG Edition Source Code is free software: you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Doom 3 BFG Edition Source Code is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with Doom 3 BFG Edition Source Code. If not, see <http://www.gnu.org/licenses/>.
  16. In addition, the Doom 3 BFG Edition Source Code is also subject to certain additional terms. You should have received a copy of these additional terms immediately following the terms and conditions of the GNU General Public License which accompanied the Doom 3 BFG Edition Source Code. If not, please request a copy in writing from id Software at the address below.
  17. If you have questions concerning this license or the applicable additional terms, you may contact in writing id Software LLC, c/o ZeniMax Media Inc., Suite 120, Rockville, Maryland 20850 USA.
  18. ===========================================================================
  19. */
  20. uniform float4 rpScreenCorrectionFactor : register(c0);
  21. uniform float4 rpWindowCoord : register(c1);
  22. uniform float4 rpDiffuseModifier : register(c2);
  23. uniform float4 rpSpecularModifier : register(c3);
  24. uniform float4 rpLocalLightOrigin : register(c4);
  25. uniform float4 rpLocalViewOrigin : register(c5);
  26. uniform float4 rpLightProjectionS : register(c6);
  27. uniform float4 rpLightProjectionT : register(c7);
  28. uniform float4 rpLightProjectionQ : register(c8);
  29. uniform float4 rpLightFalloffS : register(c9);
  30. uniform float4 rpBumpMatrixS : register(c10);
  31. uniform float4 rpBumpMatrixT : register(c11);
  32. uniform float4 rpDiffuseMatrixS : register(c12);
  33. uniform float4 rpDiffuseMatrixT : register(c13);
  34. uniform float4 rpSpecularMatrixS : register(c14);
  35. uniform float4 rpSpecularMatrixT : register(c15);
  36. uniform float4 rpVertexColorModulate : register(c16);
  37. uniform float4 rpVertexColorAdd : register(c17);
  38. uniform float4 rpColor : register(c18);
  39. uniform float4 rpViewOrigin : register(c19);
  40. uniform float4 rpGlobalEyePos : register(c20);
  41. uniform float4 rpMVPmatrixX : register(c21);
  42. uniform float4 rpMVPmatrixY : register(c22);
  43. uniform float4 rpMVPmatrixZ : register(c23);
  44. uniform float4 rpMVPmatrixW : register(c24);
  45. uniform float4 rpModelMatrixX : register(c25);
  46. uniform float4 rpModelMatrixY : register(c26);
  47. uniform float4 rpModelMatrixZ : register(c27);
  48. uniform float4 rpModelMatrixW : register(c28);
  49. uniform float4 rpProjectionMatrixX : register(c29);
  50. uniform float4 rpProjectionMatrixY : register(c30);
  51. uniform float4 rpProjectionMatrixZ : register(c31);
  52. uniform float4 rpProjectionMatrixW : register(c32);
  53. uniform float4 rpModelViewMatrixX : register(c33);
  54. uniform float4 rpModelViewMatrixY : register(c34);
  55. uniform float4 rpModelViewMatrixZ : register(c35);
  56. uniform float4 rpModelViewMatrixW : register(c36);
  57. uniform float4 rpTextureMatrixS : register(c37);
  58. uniform float4 rpTextureMatrixT : register(c38);
  59. uniform float4 rpTexGen0S : register(c39);
  60. uniform float4 rpTexGen0T : register(c40);
  61. uniform float4 rpTexGen0Q : register(c41);
  62. uniform float4 rpTexGen0Enabled : register(c42);
  63. uniform float4 rpTexGen1S : register(c43);
  64. uniform float4 rpTexGen1T : register(c44);
  65. uniform float4 rpTexGen1Q : register(c45);
  66. uniform float4 rpTexGen1Enabled : register(c46);
  67. uniform float4 rpWobbleSkyX : register(c47);
  68. uniform float4 rpWobbleSkyY : register(c48);
  69. uniform float4 rpWobbleSkyZ : register(c49);
  70. uniform float4 rpOverbright : register(c50);
  71. uniform float4 rpEnableSkinning : register(c51);
  72. uniform float4 rpAlphaTest : register(c52);
  73. static float dot2( float2 a, float2 b ) { return dot( a, b ); }
  74. static float dot3( float3 a, float3 b ) { return dot( a, b ); }
  75. static float dot3( float3 a, float4 b ) { return dot( a, b.xyz ); }
  76. static float dot3( float4 a, float3 b ) { return dot( a.xyz, b ); }
  77. static float dot3( float4 a, float4 b ) { return dot( a.xyz, b.xyz ); }
  78. static float dot4( float4 a, float4 b ) { return dot( a, b ); }
  79. static float dot4( float2 a, float4 b ) { return dot( float4( a, 0, 1 ), b ); }
  80. // ----------------------
  81. // YCoCg Color Conversion
  82. // ----------------------
  83. static const half4 matrixRGB1toCoCg1YX = half4( 0.50, 0.0, -0.50, 0.50196078 ); // Co
  84. static const half4 matrixRGB1toCoCg1YY = half4( -0.25, 0.5, -0.25, 0.50196078 ); // Cg
  85. static const half4 matrixRGB1toCoCg1YZ = half4( 0.0, 0.0, 0.0, 1.0 ); // 1.0
  86. static const half4 matrixRGB1toCoCg1YW = half4( 0.25, 0.5, 0.25, 0.0 ); // Y
  87. static const half4 matrixCoCg1YtoRGB1X = half4( 1.0, -1.0, 0.0, 1.0 );
  88. static const half4 matrixCoCg1YtoRGB1Y = half4( 0.0, 1.0, -0.50196078, 1.0 ); // -0.5 * 256.0 / 255.0
  89. static const half4 matrixCoCg1YtoRGB1Z = half4( -1.0, -1.0, 1.00392156, 1.0 ); // +1.0 * 256.0 / 255.0
  90. static half3 ConvertYCoCgToRGB( half4 YCoCg ) {
  91. half3 rgbColor;
  92. YCoCg.z = ( YCoCg.z * 31.875 ) + 1.0; //z = z * 255.0/8.0 + 1.0
  93. YCoCg.z = 1.0 / YCoCg.z;
  94. YCoCg.xy *= YCoCg.z;
  95. rgbColor.x = dot4( YCoCg, matrixCoCg1YtoRGB1X );
  96. rgbColor.y = dot4( YCoCg, matrixCoCg1YtoRGB1Y );
  97. rgbColor.z = dot4( YCoCg, matrixCoCg1YtoRGB1Z );
  98. return rgbColor;
  99. }
  100. static float2 CenterScale( float2 inTC, float2 centerScale ) {
  101. float scaleX = centerScale.x;
  102. float scaleY = centerScale.y;
  103. float4 tc0 = float4( scaleX, 0, 0, 0.5 - ( 0.5f * scaleX ) );
  104. float4 tc1 = float4( 0, scaleY, 0, 0.5 - ( 0.5f * scaleY ) );
  105. float2 finalTC;
  106. finalTC.x = dot4( inTC, tc0 );
  107. finalTC.y = dot4( inTC, tc1 );
  108. return finalTC;
  109. }
  110. static float2 Rotate2D( float2 inTC, float2 cs ) {
  111. float sinValue = cs.y;
  112. float cosValue = cs.x;
  113. float4 tc0 = float4( cosValue, -sinValue, 0, ( -0.5f * cosValue ) + ( 0.5f * sinValue ) + 0.5f );
  114. float4 tc1 = float4( sinValue, cosValue, 0, ( -0.5f * sinValue ) + ( -0.5f * cosValue ) + 0.5f );
  115. float2 finalTC;
  116. finalTC.x = dot4( inTC, tc0 );
  117. finalTC.y = dot4( inTC, tc1 );
  118. return finalTC;
  119. }
  120. // better noise function available at https://github.com/ashima/webgl-noise
  121. float rand( float2 co ) {
  122. return frac( sin( dot( co.xy, float2( 12.9898, 78.233 ) ) ) * 43758.5453 );
  123. }
  124. #define _half2( x ) half2( x )
  125. #define _half3( x ) half3( x )
  126. #define _half4( x ) half4( x )
  127. #define _float2( x ) float2( x )
  128. #define _float3( x ) float3( x )
  129. #define _float4( x ) float4( x )
  130. #define VPOS WPOS
  131. static float4 idtex2Dproj( sampler2D samp, float4 texCoords ) { return tex2Dproj( samp, texCoords.xyw ); }
  132. static float4 swizzleColor( float4 c ) { return c; }
  133. static float2 vposToScreenPosTexCoord( float2 vpos ) { return vpos.xy * rpWindowCoord.xy; }
  134. #define BRANCH
  135. #define IFANY