Guest User

Doom 3 BFG Edition - Sample Shader

a guest
Oct 23rd, 2012
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.22 KB | None | 0 0
  1.  
  2. //== PROGRAM LINK STATUS = TRUE
  3. //== PROGRAM VALIDATE STATUS = TRUE
  4.  
  5. //======================================================
  6. // Vertex Shader 25
  7. //======================================================
  8.  
  9. //== SHADER COMPILE STATUS = TRUE
  10. #version 150
  11. #define PC
  12.  
  13. float saturate( float v ) { return clamp( v, 0.0, 1.0 ); }
  14. vec2 saturate( vec2 v ) { return clamp( v, 0.0, 1.0 ); }
  15. vec3 saturate( vec3 v ) { return clamp( v, 0.0, 1.0 ); }
  16. vec4 saturate( vec4 v ) { return clamp( v, 0.0, 1.0 ); }
  17. vec4 tex2Dlod( sampler2D sampler, vec4 texcoord ) { return textureLod( sampler, texcoord.xy, texcoord.w ); }
  18.  
  19.  
  20. uniform vec4 _va_[16];
  21.  
  22. float dot3 (vec3 a , vec3 b ) {return dot ( a , b ) ; }
  23. float dot3 (vec3 a , vec4 b ) {return dot ( a , b. xyz ) ; }
  24. float dot3 (vec4 a , vec3 b ) {return dot ( a. xyz , b ) ; }
  25. float dot3 (vec4 a , vec4 b ) {return dot ( a. xyz , b. xyz ) ; }
  26. float dot4 (vec4 a , vec4 b ) {return dot ( a , b ) ; }
  27. float dot4 (vec2 a , vec4 b ) {return dot ( vec4 ( a , 0 , 1 ) , b ) ; }
  28. uniform matrices_ubo {vec4 matrices [ 408 ] ; } ;
  29.  
  30. in vec4 in_Position;
  31. in vec2 in_TexCoord;
  32. in vec4 in_Normal;
  33. in vec4 in_Tangent;
  34. in vec4 in_Color;
  35. in vec4 in_Color2;
  36.  
  37. out vec4 gl_Position;
  38. out vec4 vofi_TexCoord0;
  39. out vec4 vofi_TexCoord1;
  40. out vec4 vofi_TexCoord2;
  41. out vec4 vofi_TexCoord3;
  42. out vec4 vofi_TexCoord4;
  43. out vec4 vofi_TexCoord5;
  44. out vec4 vofi_TexCoord6;
  45. out vec4 gl_FrontColor;
  46.  
  47. void main() {
  48. vec4 vNormal = in_Normal * 2.0 - 1.0 ;
  49. vec4 vTangent = in_Tangent * 2.0 - 1.0 ;
  50. vec3 vBinormal = cross ( vNormal. xyz , vTangent. xyz ) * vTangent. w ;
  51. float w0 = in_Color2 . x ;
  52. float w1 = in_Color2 . y ;
  53. float w2 = in_Color2 . z ;
  54. float w3 = in_Color2 . w ;
  55. vec4 matX , matY , matZ ;
  56. float joint = in_Color . x * 255.1 * 3 ;
  57. matX = matrices [ int ( joint + 0 ) ] * w0 ;
  58. matY = matrices [ int ( joint + 1 ) ] * w0 ;
  59. matZ = matrices [ int ( joint + 2 ) ] * w0 ;
  60. joint = in_Color . y * 255.1 * 3 ;
  61. matX += matrices [ int ( joint + 0 ) ] * w1 ;
  62. matY += matrices [ int ( joint + 1 ) ] * w1 ;
  63. matZ += matrices [ int ( joint + 2 ) ] * w1 ;
  64. joint = in_Color . z * 255.1 * 3 ;
  65. matX += matrices [ int ( joint + 0 ) ] * w2 ;
  66. matY += matrices [ int ( joint + 1 ) ] * w2 ;
  67. matZ += matrices [ int ( joint + 2 ) ] * w2 ;
  68. joint = in_Color . w * 255.1 * 3 ;
  69. matX += matrices [ int ( joint + 0 ) ] * w3 ;
  70. matY += matrices [ int ( joint + 1 ) ] * w3 ;
  71. matZ += matrices [ int ( joint + 2 ) ] * w3 ;
  72. vec3 normal ;
  73. normal. x = dot3 ( matX , vNormal ) ;
  74. normal. y = dot3 ( matY , vNormal ) ;
  75. normal. z = dot3 ( matZ , vNormal ) ;
  76. normal = normalize ( normal ) ;
  77. vec3 tangent ;
  78. tangent. x = dot3 ( matX , vTangent ) ;
  79. tangent. y = dot3 ( matY , vTangent ) ;
  80. tangent. z = dot3 ( matZ , vTangent ) ;
  81. tangent = normalize ( tangent ) ;
  82. vec3 binormal ;
  83. binormal. x = dot3 ( matX , vBinormal ) ;
  84. binormal. y = dot3 ( matY , vBinormal ) ;
  85. binormal. z = dot3 ( matZ , vBinormal ) ;
  86. binormal = normalize ( binormal ) ;
  87. vec4 modelPosition ;
  88. modelPosition. x = dot4 ( matX , in_Position ) ;
  89. modelPosition. y = dot4 ( matY , in_Position ) ;
  90. modelPosition. z = dot4 ( matZ , in_Position ) ;
  91. modelPosition. w = 1.0 ;
  92. gl_Position . x = dot4 ( modelPosition , _va_[12 /* rpMVPmatrixX */] ) ;
  93. gl_Position . y = dot4 ( modelPosition , _va_[13 /* rpMVPmatrixY */] ) ;
  94. gl_Position . z = dot4 ( modelPosition , _va_[14 /* rpMVPmatrixZ */] ) ;
  95. gl_Position . w = dot4 ( modelPosition , _va_[15 /* rpMVPmatrixW */] ) ;
  96. vec4 defaultTexCoord = vec4 ( 0.0 , 0.5 , 0.0 , 1.0 ) ;
  97. vec4 toLight = _va_[0 /* rpLocalLightOrigin */] - modelPosition ;
  98. vofi_TexCoord0 . x = dot3 ( tangent , toLight ) ;
  99. vofi_TexCoord0 . y = dot3 ( binormal , toLight ) ;
  100. vofi_TexCoord0 . z = dot3 ( normal , toLight ) ;
  101. vofi_TexCoord0 . w = 1.0 ;
  102. vofi_TexCoord1 = defaultTexCoord ;
  103. vofi_TexCoord1 . x = dot4 ( in_TexCoord . xy , _va_[6 /* rpBumpMatrixS */] ) ;
  104. vofi_TexCoord1 . y = dot4 ( in_TexCoord . xy , _va_[7 /* rpBumpMatrixT */] ) ;
  105. vofi_TexCoord2 = defaultTexCoord ;
  106. vofi_TexCoord2 . x = dot4 ( modelPosition , _va_[5 /* rpLightFalloffS */] ) ;
  107. vofi_TexCoord3 . x = dot4 ( modelPosition , _va_[2 /* rpLightProjectionS */] ) ;
  108. vofi_TexCoord3 . y = dot4 ( modelPosition , _va_[3 /* rpLightProjectionT */] ) ;
  109. vofi_TexCoord3 . z = 0.0 ;
  110. vofi_TexCoord3 . w = dot4 ( modelPosition , _va_[4 /* rpLightProjectionQ */] ) ;
  111. vofi_TexCoord4 = defaultTexCoord ;
  112. vofi_TexCoord4 . x = dot4 ( in_TexCoord . xy , _va_[8 /* rpDiffuseMatrixS */] ) ;
  113. vofi_TexCoord4 . y = dot4 ( in_TexCoord . xy , _va_[9 /* rpDiffuseMatrixT */] ) ;
  114. vofi_TexCoord5 = defaultTexCoord ;
  115. vofi_TexCoord5 . x = dot4 ( in_TexCoord . xy , _va_[10 /* rpSpecularMatrixS */] ) ;
  116. vofi_TexCoord5 . y = dot4 ( in_TexCoord . xy , _va_[11 /* rpSpecularMatrixT */] ) ;
  117. toLight = normalize ( toLight ) ;
  118. vec4 toView = normalize ( _va_[1 /* rpLocalViewOrigin */] - modelPosition ) ;
  119. vec4 halfAngleVector = toLight + toView ;
  120. vofi_TexCoord6 . x = dot3 ( tangent , halfAngleVector ) ;
  121. vofi_TexCoord6 . y = dot3 ( binormal , halfAngleVector ) ;
  122. vofi_TexCoord6 . z = dot3 ( normal , halfAngleVector ) ;
  123. vofi_TexCoord6 . w = 1.0 ;
  124. gl_FrontColor = vec4 ( 1.0 , 1.0 , 1.0 , 1.0 ) ;
  125. }
  126. //======================================================
  127. // Fragment Shader 26
  128. //======================================================
  129.  
  130. //== SHADER COMPILE STATUS = TRUE
  131. #version 150
  132. #define PC
  133.  
  134. void clip( float v ) { if ( v < 0.0 ) { discard; } }
  135. void clip( vec2 v ) { if ( any( lessThan( v, vec2( 0.0 ) ) ) ) { discard; } }
  136. void clip( vec3 v ) { if ( any( lessThan( v, vec3( 0.0 ) ) ) ) { discard; } }
  137. void clip( vec4 v ) { if ( any( lessThan( v, vec4( 0.0 ) ) ) ) { discard; } }
  138.  
  139. float saturate( float v ) { return clamp( v, 0.0, 1.0 ); }
  140. vec2 saturate( vec2 v ) { return clamp( v, 0.0, 1.0 ); }
  141. vec3 saturate( vec3 v ) { return clamp( v, 0.0, 1.0 ); }
  142. vec4 saturate( vec4 v ) { return clamp( v, 0.0, 1.0 ); }
  143.  
  144. vec4 tex2D( sampler2D sampler, vec2 texcoord ) { return texture( sampler, texcoord.xy ); }
  145. vec4 tex2D( sampler2DShadow sampler, vec3 texcoord ) { return vec4( texture( sampler, texcoord.xyz ) ); }
  146.  
  147. vec4 tex2D( sampler2D sampler, vec2 texcoord, vec2 dx, vec2 dy ) { return textureGrad( sampler, texcoord.xy, dx, dy ); }
  148. vec4 tex2D( sampler2DShadow sampler, vec3 texcoord, vec2 dx, vec2 dy ) { return vec4( textureGrad( sampler, texcoord.xyz, dx, dy ) ); }
  149.  
  150. vec4 texCUBE( samplerCube sampler, vec3 texcoord ) { return texture( sampler, texcoord.xyz ); }
  151. vec4 texCUBE( samplerCubeShadow sampler, vec4 texcoord ) { return vec4( texture( sampler, texcoord.xyzw ) ); }
  152.  
  153. vec4 tex1Dproj( sampler1D sampler, vec2 texcoord ) { return textureProj( sampler, texcoord ); }
  154. vec4 tex2Dproj( sampler2D sampler, vec3 texcoord ) { return textureProj( sampler, texcoord ); }
  155. vec4 tex3Dproj( sampler3D sampler, vec4 texcoord ) { return textureProj( sampler, texcoord ); }
  156.  
  157. vec4 tex1Dbias( sampler1D sampler, vec4 texcoord ) { return texture( sampler, texcoord.x, texcoord.w ); }
  158. vec4 tex2Dbias( sampler2D sampler, vec4 texcoord ) { return texture( sampler, texcoord.xy, texcoord.w ); }
  159. vec4 tex3Dbias( sampler3D sampler, vec4 texcoord ) { return texture( sampler, texcoord.xyz, texcoord.w ); }
  160. vec4 texCUBEbias( samplerCube sampler, vec4 texcoord ) { return texture( sampler, texcoord.xyz, texcoord.w ); }
  161.  
  162. vec4 tex1Dlod( sampler1D sampler, vec4 texcoord ) { return textureLod( sampler, texcoord.x, texcoord.w ); }
  163. vec4 tex2Dlod( sampler2D sampler, vec4 texcoord ) { return textureLod( sampler, texcoord.xy, texcoord.w ); }
  164. vec4 tex3Dlod( sampler3D sampler, vec4 texcoord ) { return textureLod( sampler, texcoord.xyz, texcoord.w ); }
  165. vec4 texCUBElod( samplerCube sampler, vec4 texcoord ) { return textureLod( sampler, texcoord.xyz, texcoord.w ); }
  166.  
  167.  
  168. uniform vec4 _fa_[2];
  169.  
  170. float dot3 (vec3 a , vec3 b ) {return dot ( a , b ) ; }
  171. float dot3 (vec3 a , vec4 b ) {return dot ( a , b. xyz ) ; }
  172. float dot3 (vec4 a , vec3 b ) {return dot ( a. xyz , b ) ; }
  173. float dot3 (vec4 a , vec4 b ) {return dot ( a. xyz , b. xyz ) ; }
  174. float dot4 (vec4 a , vec4 b ) {return dot ( a , b ) ; }
  175. float dot4 (vec2 a , vec4 b ) {return dot ( vec4 ( a , 0 , 1 ) , b ) ; }
  176. const vec4 matrixCoCg1YtoRGB1X = vec4( 1.0, -1.0, 0.0, 1.0 );
  177. const vec4 matrixCoCg1YtoRGB1Y = vec4( 0.0, 1.0, -0.50196078, 1.0 );
  178. const vec4 matrixCoCg1YtoRGB1Z = vec4( -1.0, -1.0, 1.00392156, 1.0 );
  179. vec3 ConvertYCoCgToRGB (vec4 YCoCg ) {
  180. vec3 rgbColor ;
  181. YCoCg. z = ( YCoCg. z * 31.875 ) + 1.0 ;
  182. YCoCg. z = 1.0 / YCoCg. z ;
  183. YCoCg. xy *= YCoCg. z ;
  184. rgbColor. x = dot4 ( YCoCg , matrixCoCg1YtoRGB1X ) ;
  185. rgbColor. y = dot4 ( YCoCg , matrixCoCg1YtoRGB1Y ) ;
  186. rgbColor. z = dot4 ( YCoCg , matrixCoCg1YtoRGB1Z ) ;
  187. return rgbColor ;
  188. }
  189. vec4 idtex2Dproj (sampler2D samp , vec4 texCoords ) {return tex2Dproj ( samp , texCoords. xyw ) ; }
  190. uniform sampler2D samp0;
  191. uniform sampler2D samp1;
  192. uniform sampler2D samp2;
  193. uniform sampler2D samp3;
  194. uniform sampler2D samp4;
  195.  
  196. in vec4 gl_FragCoord;
  197. in vec4 vofi_TexCoord0;
  198. in vec4 vofi_TexCoord1;
  199. in vec4 vofi_TexCoord2;
  200. in vec4 vofi_TexCoord3;
  201. in vec4 vofi_TexCoord4;
  202. in vec4 vofi_TexCoord5;
  203. in vec4 vofi_TexCoord6;
  204. in vec4 gl_Color;
  205.  
  206. out vec4 gl_FragColor;
  207.  
  208. void main() {
  209. vec4 bumpMap = tex2D ( samp0 , vofi_TexCoord1 . xy ) ;
  210. vec4 lightFalloff = idtex2Dproj ( samp1 , vofi_TexCoord2 ) ;
  211. vec4 lightProj = idtex2Dproj ( samp2 , vofi_TexCoord3 ) ;
  212. vec4 YCoCG = tex2D ( samp3 , vofi_TexCoord4 . xy ) ;
  213. vec4 specMap = tex2D ( samp4 , vofi_TexCoord5 . xy ) ;
  214. vec3 lightVector = normalize ( vofi_TexCoord0 . xyz ) ;
  215. vec3 diffuseMap = ConvertYCoCgToRGB ( YCoCG ) ;
  216. vec3 localNormal ;
  217. localNormal. xy = bumpMap. wy - 0.5 ;
  218. localNormal. z = sqrt ( abs ( dot ( localNormal. xy , localNormal. xy ) - 0.25 ) ) ;
  219. localNormal = normalize ( localNormal ) ;
  220. float specularPower = 10.0 ;
  221. float hDotN = dot3 ( normalize ( vofi_TexCoord6 . xyz ) , localNormal ) ;
  222. vec3 specularContribution = vec3 ( pow ( hDotN , specularPower ) ) ;
  223. vec3 diffuseColor = diffuseMap * _fa_[0 /* rpDiffuseModifier */] . xyz ;
  224. vec3 specularColor = specMap. xyz * specularContribution * _fa_[1 /* rpSpecularModifier */] . xyz ;
  225. vec3 lightColor = dot3 ( lightVector , localNormal ) * lightProj. xyz * lightFalloff. xyz ;
  226. gl_FragColor . xyz = ( diffuseColor + specularColor ) * lightColor * gl_Color . xyz ;
  227. gl_FragColor . w = 1.0 ;
  228. }
Advertisement
Add Comment
Please, Sign In to add comment