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