Advertisement
illwieckz

material glsl error, radeonsi, 916eb9231

May 1st, 2024
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 30.91 KB | None | 0 0
  1. Debug: building liquid shader permutation with macro: none
  2. Warn: Source for shader program liquidMaterial:
  3. 0: #version 460 core
  4. 1: #define HAVE_ARB_texture_gather 1
  5. 2: #define HAVE_EXT_gpu_shader4 1
  6. 3: #define HAVE_ARB_gpu_shader5 1
  7. 4: #define HAVE_ARB_uniform_buffer_object 1
  8. 5: #extension GL_ARB_bindless_texture : require
  9. 6: #define HAVE_ARB_bindless_texture 1
  10. 7: #extension GL_ARB_shader_draw_parameters : require
  11. 8: #define HAVE_ARB_shader_draw_parameters 1
  12. 9: #define HAVE_ARB_shader_storage_buffer_object 1
  13. 10: #extension GL_ARB_gpu_shader_int64 : require
  14. 11: #define HAVE_ARB_gpu_shader_int64 1
  15. 12: #define IN(mode) mode in
  16. 13: #define DECLARE_OUTPUT(type) out type outputColor;
  17. 14: #define textureCube texture
  18. 15: #define texture2D texture
  19. 16: #define texture2DProj textureProj
  20. 17: #define texture3D texture
  21. 18: layout(bindless_sampler) uniform;
  22. 19: IN(flat) int in_drawID;
  23. 20: IN(flat) int in_baseInstance;
  24. 21: #ifndef r_precomputedLighting
  25. 22: #define r_precomputedLighting 1
  26. 23: #endif
  27. 24: #ifndef r_vertexSkinning
  28. 25: #define r_vertexSkinning 1
  29. 26: #endif
  30. 27: const int MAX_GLSL_BONES = 256;
  31. 28: #ifndef r_halfLambertLighting
  32. 29: #define r_halfLambertLighting 1
  33. 30: #endif
  34. 31: #ifndef r_liquidMapping
  35. 32: #define r_liquidMapping 1
  36. 33: #endif
  37. 34: #ifndef r_glowMapping
  38. 35: #define r_glowMapping 1
  39. 36: #endif
  40. 37:
  41. 38: struct DrawcallState {
  42. 39: mat4 u_TextureMatrix;
  43. 40: mat4 u_UnprojectMatrix;
  44. 41: vec3 u_NormalScale;
  45. 42: int u_NormalScale_padding;
  46. 43: vec3 u_FogColor;
  47. 44: int u_FogColor_padding;
  48. 45: uvec2 u_CurrentMap;
  49. 46: uvec2 u_DepthMap;
  50. 47: uvec2 u_NormalMap;
  51. 48: uvec2 u_PortalMap;
  52. 49: uvec2 u_LightGrid1;
  53. 50: uvec2 u_LightGrid2;
  54. 51: uvec2 u_HeightMap;
  55. 52: vec2 u_SpecularExponent;
  56. 53: float u_RefractionIndex;
  57. 54: float u_FresnelPower;
  58. 55: float u_FresnelScale;
  59. 56: float u_FresnelBias;
  60. 57: float u_ReliefDepthScale;
  61. 58: float u_ReliefOffsetBias;
  62. 59: float u_FogDensity;
  63. 60: int drawcallState_padding0;
  64. 61: };
  65. 62:
  66. 63: layout(std430, binding = 0) readonly buffer drawcallStateSSBO {
  67. 64: DrawcallState drawcallStates[];
  68. 65: };
  69. 66:
  70. 67: #define drawID in_drawID
  71. 68: #define baseInstance in_baseInstance
  72. 69:
  73. 70: #define u_TextureMatrix drawcallStates[baseInstance].u_TextureMatrix
  74. 71: #define u_UnprojectMatrix drawcallStates[baseInstance].u_UnprojectMatrix
  75. 72: #define u_NormalScale drawcallStates[baseInstance].u_NormalScale
  76. 73: #define u_FogColor drawcallStates[baseInstance].u_FogColor
  77. 74: #define u_CurrentMap_initial uvec2( drawcallStates[baseInstance].u_CurrentMap )
  78. 75: #define u_DepthMap_initial uvec2( drawcallStates[baseInstance].u_DepthMap )
  79. 76: #define u_NormalMap_initial uvec2( drawcallStates[baseInstance].u_NormalMap )
  80. 77: #define u_PortalMap_initial uvec2( drawcallStates[baseInstance].u_PortalMap )
  81. 78: #define u_LightGrid1_initial uvec2( drawcallStates[baseInstance].u_LightGrid1 )
  82. 79: #define u_LightGrid2_initial uvec2( drawcallStates[baseInstance].u_LightGrid2 )
  83. 80: #define u_HeightMap_initial uvec2( drawcallStates[baseInstance].u_HeightMap )
  84. 81: #define u_SpecularExponent drawcallStates[baseInstance].u_SpecularExponent
  85. 82: #define u_RefractionIndex drawcallStates[baseInstance].u_RefractionIndex
  86. 83: #define u_FresnelPower drawcallStates[baseInstance].u_FresnelPower
  87. 84: #define u_FresnelScale drawcallStates[baseInstance].u_FresnelScale
  88. 85: #define u_FresnelBias drawcallStates[baseInstance].u_FresnelBias
  89. 86: #define u_ReliefDepthScale drawcallStates[baseInstance].u_ReliefDepthScale
  90. 87: #define u_ReliefOffsetBias drawcallStates[baseInstance].u_ReliefOffsetBias
  91. 88: #define u_FogDensity drawcallStates[baseInstance].u_FogDensity
  92. 89:
  93. 90: uniform vec3 u_ViewOrigin;
  94. 91: uniform mat4 u_ModelMatrix;
  95. 92: uniform mat4 u_ModelViewProjectionMatrix;
  96. 93: uniform vec3 u_LightGridOrigin;
  97. 94: uniform vec3 u_LightGridScale;
  98. 95:
  99. 96: #ifndef TEXTURE_RG
  100. 97: #define TEXTURE_RG 1
  101. 98: #endif
  102. 99: #ifndef UNIFORM_BUFFER_OBJECT
  103. 100: #define UNIFORM_BUFFER_OBJECT 1
  104. 101: #endif
  105. 102: #ifndef TEXTURE_INTEGER
  106. 103: #define TEXTURE_INTEGER 1
  107. 104: #endif
  108. 105: #ifndef r_AmbientScale
  109. 106: #define r_AmbientScale 1.00000000e+00
  110. 107: #endif
  111. 108: #ifndef r_SpecularScale
  112. 109: #define r_SpecularScale 1.00000000e+00
  113. 110: #endif
  114. 111: #ifndef r_zNear
  115. 112: #define r_zNear 3.00000000e+00
  116. 113: #endif
  117. 114: #ifndef M_PI
  118. 115: #define M_PI 3.14159274e+00
  119. 116: #endif
  120. 117: #ifndef MAX_SHADOWMAPS
  121. 118: #define MAX_SHADOWMAPS 5
  122. 119: #endif
  123. 120: #ifndef MAX_REF_LIGHTS
  124. 121: #define MAX_REF_LIGHTS 1024
  125. 122: #endif
  126. 123: #ifndef TILE_SIZE
  127. 124: #define TILE_SIZE 16
  128. 125: #endif
  129. 126: #ifndef r_FBufSize
  130. 127: #define r_FBufSize vec2(6.40000000e+02, 4.80000000e+02)
  131. 128: #endif
  132. 129: #ifndef r_tileStep
  133. 130: #define r_tileStep vec2(2.49999985e-02, 3.33333313e-02)
  134. 131: #endif
  135. 132: /*
  136. 133: ===========================================================================
  137. 134: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
  138. 135:
  139. 136: This file is part of XreaL source code.
  140. 137:
  141. 138: XreaL source code is free software; you can redistribute it
  142. 139: and/or modify it under the terms of the GNU General Public License as
  143. 140: published by the Free Software Foundation; either version 2 of the License,
  144. 141: or (at your option) any later version.
  145. 142:
  146. 143: XreaL source code is distributed in the hope that it will be
  147. 144: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  148. 145: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  149. 146: GNU General Public License for more details.
  150. 147:
  151. 148: You should have received a copy of the GNU General Public License
  152. 149: along with XreaL source code; if not, write to the Free Software
  153. 150: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  154. 151: ===========================================================================
  155. 152: */
  156. 153: // computeLight_fp.glsl - Light computing helper functions
  157. 154:
  158. 155: #if !defined(USE_BSP_SURFACE)
  159. 156: #define USE_MODEL_SURFACE
  160. 157: #endif
  161. 158:
  162. 159: #if !defined(USE_GRID_LIGHTING)
  163. 160: #define USE_LIGHT_MAPPING
  164. 161: #endif
  165. 162:
  166. 163: #if defined(USE_REFLECTIVE_SPECULAR)
  167. 164: #endif // USE_REFLECTIVE_SPECULAR
  168. 165:
  169. 166: #ifdef HAVE_ARB_uniform_buffer_object
  170. 167: struct light {
  171. 168: vec4 center_radius;
  172. 169: vec4 color_type;
  173. 170: vec4 direction_angle;
  174. 171: };
  175. 172:
  176. 173: layout(std140) uniform u_Lights {
  177. 174: light lights[ MAX_REF_LIGHTS ];
  178. 175: };
  179. 176: #define GetLight(idx, component) lights[idx].component
  180. 177: #else // !HAVE_ARB_uniform_buffer_object
  181. 178: #define idxToTC( idx, w, h ) vec2( floor( ( idx * ( 1.0 / w ) ) + 0.5 ) * ( 1.0 / h ), \
  182. 179: fract( ( idx + 0.5 ) * (1.0 / w ) ) )
  183. 180: const struct GetLightOffsets {
  184. 181: int center_radius;
  185. 182: int color_type;
  186. 183: int direction_angle;
  187. 184: } getLightOffsets = GetLightOffsets(0, 1, 2);
  188. 185: #define GetLight(idx, component) texture2D( u_LightsTexture, idxToTC(3 * idx + getLightOffsets.component, 64.0, float( 3 * MAX_REF_LIGHTS / 64 ) ) )
  189. 186: #endif // HAVE_ARB_uniform_buffer_object
  190. 187:
  191. 188:
  192. 189:
  193. 190: // lighting helper functions
  194. 191:
  195. 192: void ReadLightGrid(in vec4 texel, out vec3 ambientColor, out vec3 lightColor) {
  196. 193: float ambientScale = 2.0 * texel.a;
  197. 194: float directedScale = 2.0 - ambientScale;
  198. 195: ambientColor = ambientScale * texel.rgb;
  199. 196: lightColor = directedScale * texel.rgb;
  200. 197: }
  201. 198:
  202. 199: void computeLight(in vec3 lightColor, vec4 diffuseColor, inout vec4 color) {
  203. 200: color.rgb += lightColor.rgb * diffuseColor.rgb;
  204. 201: }
  205. 202:
  206. 203: void computeDeluxeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
  207. 204: vec4 diffuseColor, vec4 materialColor,
  208. 205: inout vec4 color ) {
  209. 206: vec3 H = normalize( lightDir + viewDir );
  210. 207:
  211. 208: #if defined(USE_PHYSICAL_MAPPING) || defined(r_specularMapping)
  212. 209: float NdotH = clamp( dot( normal, H ), 0.0, 1.0 );
  213. 210: #endif // USE_PHYSICAL_MAPPING || r_specularMapping
  214. 211:
  215. 212: // clamp( NdotL, 0.0, 1.0 ) is done below
  216. 213: float NdotL = dot( normal, lightDir );
  217. 214:
  218. 215: #if !defined(USE_BSP_SURFACE) && defined(r_halfLambertLighting)
  219. 216: // http://developer.valvesoftware.com/wiki/Half_Lambert
  220. 217: NdotL = NdotL * 0.5 + 0.5;
  221. 218: NdotL *= NdotL;
  222. 219: #endif
  223. 220:
  224. 221: NdotL = clamp( NdotL, 0.0, 1.0 );
  225. 222:
  226. 223: #if defined(USE_PHYSICAL_MAPPING)
  227. 224: // Daemon PBR packing defaults to ORM like glTF 2.0 defines
  228. 225: // https://www.khronos.org/blog/art-pipeline-for-gltf
  229. 226: // > ORM texture for Occlusion, Roughness, and Metallic
  230. 227: // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/material.pbrMetallicRoughness.schema.json
  231. 228: // > The metalness values are sampled from the B channel. The roughness values are sampled from the G channel.
  232. 229: // > These values are linear. If other channels are present (R or A), they are ignored for metallic-roughness calculations.
  233. 230: // https://docs.blender.org/manual/en/2.80/addons/io_scene_gltf2.html
  234. 231: // > glTF stores occlusion in the red (R) channel, allowing it to optionally share the same image
  235. 232: // > with the roughness and metallic channels.
  236. 233: float roughness = materialColor.g;
  237. 234: float metalness = materialColor.b;
  238. 235:
  239. 236: float NdotV = clamp( dot( normal, viewDir ), 0.0, 1.0);
  240. 237: float VdotH = clamp( dot( viewDir, H ), 0.0, 1.0);
  241. 238:
  242. 239: float alpha = roughness * roughness;
  243. 240: float k = 0.125 * (roughness + 1.0) * (roughness + 1.0);
  244. 241:
  245. 242: float D = alpha / ((NdotH * NdotH) * (alpha * alpha - 1.0) + 1.0);
  246. 243: D *= D;
  247. 244:
  248. 245: float FexpNH = pow(1.0 - NdotH, 5.0);
  249. 246: float FexpNV = pow(1.0 - NdotV, 5.0);
  250. 247: vec3 F = mix(vec3(0.04), diffuseColor.rgb, metalness);
  251. 248: F = F + (1.0 - F) * FexpNH;
  252. 249:
  253. 250: float G = NdotL / (NdotL * (1.0 - k) + k);
  254. 251: G *= NdotV / (NdotV * (1.0 - k) + k);
  255. 252:
  256. 253: color.rgb += lightColor.rgb * NdotL * diffuseColor.rgb * (1.0 - metalness);
  257. 254: color.rgb += lightColor.rgb * vec3((D * F * G) / (4.0 * NdotV));
  258. 255: color.a = mix(diffuseColor.a, 1.0, FexpNV);
  259. 256: #else // !USE_PHYSICAL_MAPPING
  260. 257:
  261. 258: #if defined(USE_REFLECTIVE_SPECULAR)
  262. 259: // not implemented for PBR yet
  263. 260: vec4 envColor0 = textureCube(u_EnvironmentMap0, reflect(-viewDir, normal));
  264. 261: vec4 envColor1 = textureCube(u_EnvironmentMap1, reflect(-viewDir, normal));
  265. 262:
  266. 263: materialColor.rgb *= mix(envColor0, envColor1, u_EnvironmentInterpolation).rgb;
  267. 264: #endif // USE_REFLECTIVE_SPECULAR
  268. 265:
  269. 266: color.rgb += lightColor.rgb * NdotL * diffuseColor.rgb;
  270. 267: #if defined(r_specularMapping)
  271. 268: // The minimal specular exponent should preferably be nonzero to avoid the undefined pow(0, 0)
  272. 269: color.rgb += lightColor.rgb * materialColor.rgb * pow( NdotH, u_SpecularExponent.x * materialColor.a + u_SpecularExponent.y) * r_SpecularScale;
  273. 270: #endif // r_specularMapping
  274. 271: #endif // !USE_PHYSICAL_MAPPING
  275. 272: }
  276. 273:
  277. 274: #if defined(TEXTURE_INTEGER)
  278. 275: const int lightsPerLayer = 16;
  279. 276: #define idxs_t uvec4
  280. 277: idxs_t fetchIdxs( in vec3 coords ) {
  281. 278: return texture3D( u_LightTilesInt, coords );
  282. 279: }
  283. 280: int nextIdx( inout idxs_t idxs ) {
  284. 281: uvec4 tmp = ( idxs & uvec4( 3 ) ) * uvec4( 0x40, 0x10, 0x04, 0x01 );
  285. 282: idxs = idxs >> 2;
  286. 283: return int( tmp.x + tmp.y + tmp.z + tmp.w );
  287. 284: }
  288. 285: #else // !TEXTURE INTEGER
  289. 286: const int lightsPerLayer = 4;
  290. 287: #define idxs_t vec4
  291. 288: idxs_t fetchIdxs( in vec3 coords ) {
  292. 289: return texture3D( u_LightTiles, coords ) * 255.0;
  293. 290: }
  294. 291: int nextIdx( inout idxs_t idxs ) {
  295. 292: vec4 tmp = idxs;
  296. 293: idxs = floor(idxs * 0.25);
  297. 294: tmp -= 4.0 * idxs;
  298. 295: return int( dot( tmp, vec4( 64.0, 16.0, 4.0, 1.0 ) ) );
  299. 296: }
  300. 297: #endif // TEXTURE_INTEGER
  301. 298:
  302. 299: const int numLayers = MAX_REF_LIGHTS / 256;
  303. 300:
  304. 301: #if defined(r_dynamicLight)
  305. 302: void computeDynamicLight( int idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse,
  306. 303: vec4 material, inout vec4 color ) {
  307. 304: vec4 center_radius = GetLight( idx, center_radius );
  308. 305: vec4 color_type = GetLight( idx, color_type );
  309. 306: vec3 L;
  310. 307: float attenuation;
  311. 308:
  312. 309: if( color_type.w == 0.0 ) {
  313. 310: // point light
  314. 311: L = center_radius.xyz - P;
  315. 312: attenuation = 1.0 / (1.0 + 8.0 * length(L) / center_radius.w);
  316. 313: L = normalize(L);
  317. 314: } else if( color_type.w == 1.0 ) {
  318. 315: // spot light
  319. 316: vec4 direction_angle = GetLight( idx, direction_angle );
  320. 317: L = center_radius.xyz - P;
  321. 318: attenuation = 1.0 / (1.0 + 8.0 * length(L) / center_radius.w);
  322. 319: L = normalize( L );
  323. 320:
  324. 321: if( dot( L, direction_angle.xyz ) <= direction_angle.w ) {
  325. 322: attenuation = 0.0;
  326. 323: }
  327. 324: } else if( color_type.w == 2.0 ) {
  328. 325: // sun (directional) light
  329. 326: L = GetLight( idx, direction_angle ).xyz;
  330. 327: attenuation = 1.0;
  331. 328: }
  332. 329: computeDeluxeLight( L, normal, viewDir,
  333. 330: attenuation * attenuation * color_type.xyz,
  334. 331: diffuse, material, color );
  335. 332: }
  336. 333:
  337. 334: void computeDynamicLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4 material,
  338. 335: inout vec4 color ) {
  339. 336: vec2 tile = floor( gl_FragCoord.xy * (1.0 / float( TILE_SIZE ) ) ) + 0.5;
  340. 337: vec3 tileScale = vec3( r_tileStep, 1.0/numLayers );
  341. 338:
  342. 339: #if defined(r_showLightTiles)
  343. 340: float numLights = 0.0;
  344. 341: #endif
  345. 342:
  346. 343: for( int layer = 0; layer < numLayers; layer++ ) {
  347. 344: idxs_t idxs = fetchIdxs( tileScale * vec3( tile, float( layer ) + 0.5 ) );
  348. 345: for( int i = 0; i < lightsPerLayer; i++ ) {
  349. 346: int idx = numLayers * nextIdx( idxs ) + layer;
  350. 347:
  351. 348: if( idx >= u_numLights )
  352. 349: {
  353. 350: break;
  354. 351: }
  355. 352:
  356. 353: computeDynamicLight( idx, P, normal, viewDir, diffuse, material, color );
  357. 354:
  358. 355: #if defined(r_showLightTiles)
  359. 356: numLights++;
  360. 357: #endif
  361. 358: }
  362. 359: }
  363. 360:
  364. 361: #if defined(r_showLightTiles)
  365. 362: if (numLights > 0.0)
  366. 363: {
  367. 364: color = vec4(numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), 1.0);
  368. 365: }
  369. 366: #endif
  370. 367: }
  371. 368: #endif
  372. 369: /*
  373. 370: ===========================================================================
  374. 371: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
  375. 372:
  376. 373: This file is part of XreaL source code.
  377. 374:
  378. 375: XreaL source code is free software; you can redistribute it
  379. 376: and/or modify it under the terms of the GNU General Public License as
  380. 377: published by the Free Software Foundation; either version 2 of the License,
  381. 378: or (at your option) any later version.
  382. 379:
  383. 380: XreaL source code is distributed in the hope that it will be
  384. 381: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  385. 382: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  386. 383: GNU General Public License for more details.
  387. 384:
  388. 385: You should have received a copy of the GNU General Public License
  389. 386: along with XreaL source code; if not, write to the Free Software
  390. 387: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  391. 388: ===========================================================================
  392. 389: */
  393. 390: // reliefMapping_fp.glsl - Relief mapping helper functions
  394. 391:
  395. 392: #if defined(r_normalMapping) || defined(USE_HEIGHTMAP_IN_NORMALMAP)
  396. 393: #endif // r_normalMapping || USE_HEIGHTMAP_IN_NORMALMAP
  397. 394:
  398. 395: #if defined(r_normalMapping)
  399. 396: #endif // r_normalMapping
  400. 397:
  401. 398: #if defined(USE_RELIEF_MAPPING)
  402. 399: #if !defined(USE_HEIGHTMAP_IN_NORMALMAP)
  403. 400: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
  404. 401: #endif // USE_RELIEF_MAPPING
  405. 402:
  406. 403: // compute normal in tangent space
  407. 404: vec3 NormalInTangentSpace(vec2 texNormal)
  408. 405: {
  409. 406: vec3 normal;
  410. 407:
  411. 408: #if defined(r_normalMapping)
  412. 409: #if defined(USE_HEIGHTMAP_IN_NORMALMAP)
  413. 410: // alpha channel contains the height map so do not try to reconstruct normal map from it
  414. 411: sampler2D u_NormalMap = sampler2D(u_NormalMap_initial);
  415. 412: normal = texture2D(u_NormalMap, texNormal).rgb;
  416. 413: normal = 2.0 * normal - 1.0;
  417. 414: #else // !USE_HEIGHTMAP_IN_NORMALMAP
  418. 415: // the Capcom trick abusing alpha channel of DXT1/5 formats to encode normal map
  419. 416: // https://github.com/DaemonEngine/Daemon/issues/183#issuecomment-473691252
  420. 417: //
  421. 418: // the algorithm also works with normal maps in rgb format without alpha channel
  422. 419: // but we still must be sure there is no height map in alpha channel hence the test
  423. 420: //
  424. 421: // crunch -dxn seems to produce such files, since alpha channel is abused such format
  425. 422: // is unsuitable to embed height map, then height map must be distributed as loose file
  426. 423: sampler2D u_NormalMap = sampler2D(u_NormalMap_initial);
  427. 424: normal = texture2D(u_NormalMap, texNormal).rga;
  428. 425: normal.x *= normal.z;
  429. 426: normal.xy = 2.0 * normal.xy - 1.0;
  430. 427: // In a perfect world this code must be enough:
  431. 428: // normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
  432. 429: //
  433. 430: // Unvanquished texture known to trigger black normalmap artifacts
  434. 431: // when doing Z reconstruction:
  435. 432: // textures/shared_pk02_src/rock01_n
  436. 433: //
  437. 434: // Although the normal vector is supposed to have a length of 1,
  438. 435: // dot(normal.xy, normal.xy) may be greater than 1 due to compression
  439. 436: // artifacts: values as large as 1.27 have been observed with crunch -dxn.
  440. 437: // https://github.com/DaemonEngine/Daemon/pull/260#issuecomment-571010935
  441. 438: //
  442. 439: // This might happen with other formats too. So we must take care not to
  443. 440: // take the square root of a negative number here.
  444. 441: normal.z = sqrt(max(0, 1.0 - dot(normal.xy, normal.xy)));
  445. 442: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
  446. 443: /* Disable normal map scaling when normal Z scale is set to zero.
  447. 444:
  448. 445: This happens when r_normalScale is set to zero because
  449. 446: u_NormalScale.z is premultiplied with r_normalScale. User can
  450. 447: disable normal map scaling by setting r_normalScale to zero.
  451. 448:
  452. 449: Normal Z component equal to zero would be wrong anyway.
  453. 450: */
  454. 451: if (u_NormalScale.z != 0)
  455. 452: {
  456. 453: normal *= u_NormalScale;
  457. 454: }
  458. 455:
  459. 456: // HACK: the GLSL code is currently assuming
  460. 457: // DirectX normal map format (+X -Y +Z)
  461. 458: // but engine is assuming the OpenGL way (+X +Y +Z)
  462. 459: normal.y *= -1;
  463. 460: #else // !r_normalMapping
  464. 461: // Flat normal map is {0.5, 0.5, 1.0} in [ 0.0, 1.0]
  465. 462: // which is stored as {0.0, 0.0, 1.0} in [-1.0, 1.0].
  466. 463: normal = vec3(0.0, 0.0, 1.0);
  467. 464: #endif // !r_normalMapping
  468. 465:
  469. 466: return normal;
  470. 467: }
  471. 468:
  472. 469: // compute normal in worldspace from normalmap
  473. 470: vec3 NormalInWorldSpace(vec2 texNormal, mat3 tangentToWorldMatrix)
  474. 471: {
  475. 472: // compute normal in tangent space from normalmap
  476. 473: vec3 normal = NormalInTangentSpace(texNormal);
  477. 474: // transform normal into world space
  478. 475: return normalize(tangentToWorldMatrix * normal);
  479. 476: }
  480. 477:
  481. 478: #if defined(USE_RELIEF_MAPPING)
  482. 479: // compute texcoords offset from heightmap
  483. 480: // most of the code doing somewhat the same is likely to be named
  484. 481: // RayIntersectDisplaceMap in other id tech3-based engines
  485. 482: // so please keep the comment above to enable cross-tree look-up
  486. 483: vec2 ReliefTexOffset(vec2 rayStartTexCoords, vec3 viewDir, mat3 tangentToWorldMatrix)
  487. 484: {
  488. 485: // compute view direction in tangent space
  489. 486: vec3 tangentViewDir = normalize(viewDir * tangentToWorldMatrix);
  490. 487:
  491. 488: vec2 displacement = tangentViewDir.xy * -u_ReliefDepthScale / tangentViewDir.z;
  492. 489:
  493. 490: const int linearSearchSteps = 16;
  494. 491: const int binarySearchSteps = 6;
  495. 492:
  496. 493: float depthStep = 1.0 / float(linearSearchSteps);
  497. 494: float topDepth = 1.0 - u_ReliefOffsetBias;
  498. 495:
  499. 496: // current size of search window
  500. 497: float currentSize = depthStep;
  501. 498:
  502. 499: // current depth position
  503. 500: float currentDepth = 0.0;
  504. 501:
  505. 502: // best match found (starts with last position 1.0)
  506. 503: float bestDepth = 1.0;
  507. 504:
  508. 505: // search front to back for first point inside object
  509. 506: for(int i = 0; i < linearSearchSteps - 1; ++i)
  510. 507: {
  511. 508: currentDepth += currentSize;
  512. 509:
  513. 510: #if defined(USE_HEIGHTMAP_IN_NORMALMAP)
  514. 511: sampler2D u_NormalMap = sampler2D(u_NormalMap_initial);
  515. 512: float depth = texture2D(u_NormalMap, rayStartTexCoords + displacement * currentDepth).a;
  516. 513: #else // !USE_HEIGHTMAP_IN_NORMALMAP
  517. 514: sampler2D u_HeightMap = sampler2D(u_HeightMap_initial);
  518. 515: float depth = texture2D(u_HeightMap, rayStartTexCoords + displacement * currentDepth).g;
  519. 516: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
  520. 517:
  521. 518: float heightMapDepth = topDepth - depth;
  522. 519:
  523. 520: if(bestDepth > 0.996) // if no depth found yet
  524. 521: {
  525. 522: if(currentDepth >= heightMapDepth)
  526. 523: {
  527. 524: bestDepth = currentDepth;
  528. 525: }
  529. 526: }
  530. 527: }
  531. 528:
  532. 529: currentDepth = bestDepth;
  533. 530:
  534. 531: // recurse around first point (depth) for closest match
  535. 532: for(int i = 0; i < binarySearchSteps; ++i)
  536. 533: {
  537. 534: currentSize *= 0.5;
  538. 535:
  539. 536: #if defined(USE_HEIGHTMAP_IN_NORMALMAP)
  540. 537: sampler2D u_NormalMap = sampler2D(u_NormalMap_initial);
  541. 538: float depth = texture2D(u_NormalMap, rayStartTexCoords + displacement * currentDepth).a;
  542. 539: #else // !USE_HEIGHTMAP_IN_NORMALMAP
  543. 540: sampler2D u_HeightMap = sampler2D(u_HeightMap_initial);
  544. 541: float depth = texture2D(u_HeightMap, rayStartTexCoords + displacement * currentDepth).g;
  545. 542: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
  546. 543:
  547. 544: float heightMapDepth = topDepth - depth;
  548. 545:
  549. 546: if(currentDepth >= heightMapDepth)
  550. 547: {
  551. 548: bestDepth = currentDepth;
  552. 549: currentDepth -= 2.0 * currentSize;
  553. 550: }
  554. 551:
  555. 552: currentDepth += currentSize;
  556. 553: }
  557. 554:
  558. 555: return bestDepth * displacement;
  559. 556: }
  560. 557: #endif // USE_RELIEF_MAPPING
  561. 558: /*
  562. 559: ===========================================================================
  563. 560: Copyright (C) 2007-2009 Robert Beckebans <trebor_7@users.sourceforge.net>
  564. 561:
  565. 562: This file is part of XreaL source code.
  566. 563:
  567. 564: XreaL source code is free software; you can redistribute it
  568. 565: and/or modify it under the terms of the GNU General Public License as
  569. 566: published by the Free Software Foundation; either version 2 of the License,
  570. 567: or (at your option) any later version.
  571. 568:
  572. 569: XreaL source code is distributed in the hope that it will be
  573. 570: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
  574. 571: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  575. 572: GNU General Public License for more details.
  576. 573:
  577. 574: You should have received a copy of the GNU General Public License
  578. 575: along with XreaL source code; if not, write to the Free Software
  579. 576: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  580. 577: ===========================================================================
  581. 578: */
  582. 579:
  583. 580: /* liquid_fp.glsl */
  584. 581:
  585. 582:
  586. 583:
  587. 584: IN(smooth) vec3 var_Position;
  588. 585: IN(smooth) vec2 var_TexCoords;
  589. 586: IN(smooth) vec3 var_Tangent;
  590. 587: IN(smooth) vec3 var_Binormal;
  591. 588: IN(smooth) vec3 var_Normal;
  592. 589:
  593. 590: DECLARE_OUTPUT(vec4)
  594. 591:
  595. 592: void main()
  596. 593: {
  597. 594: // compute incident ray
  598. 595: vec3 viewDir = normalize(u_ViewOrigin - var_Position);
  599. 596:
  600. 597: mat3 tangentToWorldMatrix = mat3(var_Tangent.xyz, var_Binormal.xyz, var_Normal.xyz);
  601. 598: if(gl_FrontFacing)
  602. 599: {
  603. 600: tangentToWorldMatrix = -tangentToWorldMatrix;
  604. 601: }
  605. 602:
  606. 603: // calculate the screen texcoord in the 0.0 to 1.0 range
  607. 604: vec2 texScreen = gl_FragCoord.st / r_FBufSize;
  608. 605: vec2 texNormal = var_TexCoords;
  609. 606:
  610. 607: #if defined(USE_RELIEF_MAPPING)
  611. 608: // ray intersect in view direction
  612. 609:
  613. 610: // compute texcoords offset from heightmap
  614. 611: vec2 texOffset = ReliefTexOffset(texNormal, viewDir, tangentToWorldMatrix);
  615. 612:
  616. 613: texScreen += texOffset;
  617. 614: texNormal += texOffset;
  618. 615: #endif
  619. 616:
  620. 617: // compute normal in world space from normalmap
  621. 618: vec3 normal = NormalInWorldSpace(texNormal, tangentToWorldMatrix);
  622. 619:
  623. 620: // compute fresnel term
  624. 621: float fresnel = clamp(u_FresnelBias + pow(1.0 - dot(viewDir, normal), u_FresnelPower) *
  625. 622: u_FresnelScale, 0.0, 1.0);
  626. 623:
  627. 624: vec3 refractColor;
  628. 625: vec4 reflectColor;
  629. 626: vec4 color;
  630. 627:
  631. 628: #if defined(r_liquidMapping)
  632. 629: sampler2D u_CurrentMap = sampler2D(u_CurrentMap_initial);
  633. 630: refractColor = texture2D(u_CurrentMap, texScreen).rgb;
  634. 631: sampler2D u_PortalMap = sampler2D(u_PortalMap_initial);
  635. 632: reflectColor.rgb = texture2D(u_PortalMap, texScreen).rgb;
  636. 633: reflectColor.a = 1.0;
  637. 634: #else // !r_liquidMapping
  638. 635: // dummy fallback color
  639. 636: refractColor = vec3(0.7, 0.7, 0.7);
  640. 637: reflectColor = vec4(0.7, 0.7, 0.7, 1.0);
  641. 638: #endif // !r_liquidMapping
  642. 639:
  643. 640: color.rgb = mix(refractColor, reflectColor.rgb, fresnel);
  644. 641: color.a = 1.0;
  645. 642:
  646. 643: if(u_FogDensity > 0.0)
  647. 644: {
  648. 645: // reconstruct vertex position in world space
  649. 646: sampler2D u_DepthMap = sampler2D(u_DepthMap_initial);
  650. 647: float depth = texture2D(u_DepthMap, texScreen).r;
  651. 648: vec4 P = u_UnprojectMatrix * vec4(gl_FragCoord.xy, depth, 1.0);
  652. 649: P.xyz /= P.w;
  653. 650:
  654. 651: // calculate fog distance
  655. 652: float fogDistance = distance(P.xyz, var_Position);
  656. 653:
  657. 654: // calculate fog exponent
  658. 655: float fogExponent = fogDistance * u_FogDensity;
  659. 656:
  660. 657: // calculate fog factor
  661. 658: float fogFactor = exp2(-abs(fogExponent));
  662. 659:
  663. 660: color.rgb = mix(u_FogColor, color.rgb, fogFactor);
  664. 661: }
  665. 662:
  666. 663: vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
  667. 664:
  668. 665: // compute light color from light grid
  669. 666: vec3 ambientColor, lightColor;
  670. 667: sampler3D u_LightGrid1 = sampler3D(u_LightGrid1_initial);
  671. 668: ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);
  672. 669:
  673. 670: // compute light direction in world space
  674. 671: sampler3D u_LightGrid2 = sampler3D(u_LightGrid2_initial);
  675. 672: vec4 texel = texture3D(u_LightGrid2, lightGridPos);
  676. 673: vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
  677. 674:
  678. 675: vec4 diffuse = vec4(0.0, 0.0, 0.0, 1.0);
  679. 676:
  680. 677: // compute the specular term
  681. 678: computeDeluxeLight(lightDir, normal, viewDir, lightColor, diffuse, reflectColor, color);
  682. 679:
  683. 680: outputColor = color;
  684. 681:
  685. 682: #if defined(r_showNormalMaps)
  686. 683: // convert normal to [0,1] color space
  687. 684: normal = normal * 0.5 + 0.5;
  688. 685: outputColor = vec4(normal, 1.0);
  689. 686: #endif
  690. 687: }
  691.  
  692. Warn: Compile log:
  693. 0:279(18): error: `u_LightTilesInt' undeclared
  694. 0:279(9): error: no matching function for call to `texture(error, vec3)'; candidates are:
  695. 0:279(9): error: vec4 texture(sampler1D, float)
  696. 0:279(9): error: ivec4 texture(isampler1D, float)
  697. 0:279(9): error: uvec4 texture(usampler1D, float)
  698. 0:279(9): error: vec4 texture(sampler2D, vec2)
  699. 0:279(9): error: ivec4 texture(isampler2D, vec2)
  700. 0:279(9): error: uvec4 texture(usampler2D, vec2)
  701. 0:279(9): error: vec4 texture(sampler3D, vec3)
  702. 0:279(9): error: ivec4 texture(isampler3D, vec3)
  703. 0:279(9): error: uvec4 texture(usampler3D, vec3)
  704. 0:279(9): error: vec4 texture(samplerCube, vec3)
  705. 0:279(9): error: ivec4 texture(isamplerCube, vec3)
  706. 0:279(9): error: uvec4 texture(usamplerCube, vec3)
  707. 0:279(9): error: float texture(sampler1DShadow, vec3)
  708. 0:279(9): error: float texture(sampler2DShadow, vec3)
  709. 0:279(9): error: float texture(samplerCubeShadow, vec4)
  710. 0:279(9): error: vec4 texture(sampler1DArray, vec2)
  711. 0:279(9): error: ivec4 texture(isampler1DArray, vec2)
  712. 0:279(9): error: uvec4 texture(usampler1DArray, vec2)
  713. 0:279(9): error: vec4 texture(sampler2DArray, vec3)
  714. 0:279(9): error: ivec4 texture(isampler2DArray, vec3)
  715. 0:279(9): error: uvec4 texture(usampler2DArray, vec3)
  716. 0:279(9): error: vec4 texture(samplerCubeArray, vec4)
  717. 0:279(9): error: ivec4 texture(isamplerCubeArray, vec4)
  718. 0:279(9): error: uvec4 texture(usamplerCubeArray, vec4)
  719. 0:279(9): error: float texture(sampler1DArrayShadow, vec3)
  720. 0:279(9): error: float texture(sampler2DArrayShadow, vec4)
  721. 0:279(9): error: float texture(samplerCubeArrayShadow, vec4, float)
  722. 0:279(9): error: vec4 texture(sampler2DRect, vec2)
  723. 0:279(9): error: ivec4 texture(isampler2DRect, vec2)
  724. 0:279(9): error: uvec4 texture(usampler2DRect, vec2)
  725. 0:279(9): error: float texture(sampler2DRectShadow, vec3)
  726. 0:279(9): error: vec4 texture(sampler1D, float, float)
  727. 0:279(9): error: ivec4 texture(isampler1D, float, float)
  728. 0:279(9): error: uvec4 texture(usampler1D, float, float)
  729. 0:279(9): error: vec4 texture(sampler2D, vec2, float)
  730. 0:279(9): error: ivec4 texture(isampler2D, vec2, float)
  731. 0:279(9): error: uvec4 texture(usampler2D, vec2, float)
  732. 0:279(9): error: vec4 texture(sampler3D, vec3, float)
  733. 0:279(9): error: ivec4 texture(isampler3D, vec3, float)
  734. 0:279(9): error: uvec4 texture(usampler3D, vec3, float)
  735. 0:279(9): error: vec4 texture(samplerCube, vec3, float)
  736. 0:279(9): error: ivec4 texture(isamplerCube, vec3, float)
  737. 0:279(9): error: uvec4 texture(usamplerCube, vec3, float)
  738. 0:279(9): error: float texture(sampler1DShadow, vec3, float)
  739. 0:279(9): error: float texture(sampler2DShadow, vec3, float)
  740. 0:279(9): error: float texture(samplerCubeShadow, vec4, float)
  741. 0:279(9): error: vec4 texture(sampler1DArray, vec2, float)
  742. 0:279(9): error: ivec4 texture(isampler1DArray, vec2, float)
  743. 0:279(9): error: uvec4 texture(usampler1DArray, vec2, float)
  744. 0:279(9): error: vec4 texture(sampler2DArray, vec3, float)
  745. 0:279(9): error: ivec4 texture(isampler2DArray, vec3, float)
  746. 0:279(9): error: uvec4 texture(usampler2DArray, vec3, float)
  747. 0:279(9): error: vec4 texture(samplerCubeArray, vec4, float)
  748. 0:279(9): error: ivec4 texture(isamplerCubeArray, vec4, float)
  749. 0:279(9): error: uvec4 texture(usamplerCubeArray, vec4, float)
  750. 0:279(9): error: float texture(sampler1DArrayShadow, vec3, float)
  751. 0:279(2): error: could not implicitly convert return value to uvec4, in function `fetchIdxs'
  752.  
  753. Warn: Unhandled exception (15ShaderException): Couldn't compile fragment shader: liquidMaterial
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement