Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: Source for shader program lightMapping:
0: #version 410 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: #define IN(mode) mode in
6: #define DECLARE_OUTPUT(type) out type outputColor;
7: #define textureCube texture
8: #define texture2D texture
9: #define texture2DProj textureProj
10: #define texture3D texture
11: #ifndef r_dynamicLight
12: #define r_dynamicLight 2
13: #endif
14: #ifndef r_precomputedLighting
15: #define r_precomputedLighting 1
16: #endif
17: #ifndef r_vertexSkinning
18: #define r_vertexSkinning 1
19: #endif
20: const int MAX_GLSL_BONES = 233;
21: const float r_wrapAroundLighting 24: #endif
25: #ifndef r_normalMapping
26: #define r_normalMapping 1
27: #endif
28: #ifndef r_specularMapping
29: #define r_specularMapping 1
30: #endif
31: #ifndef r_physicalMapping
32: #define r_physicalMapping 1
33: #endif
34: #ifndef r_glowMapping
35: #define r_glowMapping 1
36: #endif
37: #ifndef TEXTURE_RG
38: #define TEXTURE_RG 1
39: #endif
40: #ifndef UNIFORM_BUFFER_OBJECT
41: #define UNIFORM_BUFFER_OBJECT 1
42: #endif
43: #ifndef TEXTURE_INTEGER
44: #define TEXTURE_INTEGER 1
45: #endif
46: #ifndef r_AmbientScale
47: #define r_AmbientScale 1.00000000e+00
48: #endif
49: #ifndef r_SpecularScale
50: #define r_SpecularScale 1.00000000e+00
51: #endif
52: #ifn 53: #define r_zNear 3.00000000e+00
54: #endif
55: #ifndef M_PI
56: #define M_PI 3.14159274e+00
57: #endif
58: #ifndef MAX_SHADOWMAPS
59: #define MAX_SHADOWMAPS 5
60: #endif
61: #ifndef MAX_REF_LIGHTS
62: #define MAX_REF_LIGHTS 1024
63: #endif
64: #ifndef TILE_SIZE
65: #define TILE_SIZE 16
66: #endif
67: #ifndef r_FBufSize
68: #define r_FBufSize vec2(1.72800000e+03, 1.11700000e+03)
69: #endif
70: #ifndef r_tileStep
71: #define r_tileStep vec2(9.25925933e-03, 1.43240821e-02)
72: #endif
0: #line 0
1: /*
2: ===========================================================================
3: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
4:
5: This file is part of XreaL source code.
6:
7: XreaL source code is free software; you can redistribute it
8: and/or modify it under the terms of the GNU General Public License as
9: published by the Free Software Foundation; either version 2 of the License,
10: or (at your option) any later version.
11:
12: XreaL source code is distributed in the hope that it will be
13: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with XreaL source code; if not, write to the Free Software
19: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: ===========================================================================
21: */
22: // computeLight_fp.glsl - Light computing helper function 155: #else // !TEXTURE INTEGER
156: const int lightsPerLayer = 4;
157: uniform sampler3D u_LightTiles;
158: #define idxs_t vec4
159: idxs_t fetchIdxs( in vec3 coords ) {
160: return texture3D( u_LightTiles, coords ) * 255.0;
161: }
162: int nextIdx( inout idxs_t idxs ) {
163: vec4 tmp = idxs;
164: idxs = floor(idxs * 0.25);
165: tmp -= 4.0 * idxs;
166: return int( dot( tmp, vec4( 64.0, 16.0, 4.0, 1.0 ) ) );
167: }
168: #endif // TEXTURE_INTEGER
169:
170: const int numLayers = MAX_REF_LIGHTS / 256;
171:
172: #if defined(r_dynamicLight)
173: void computeDLight( int idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse,
174: vec4 material, inout vec4 color ) {
175: vec4 center_radius = GetLight( idx, center_radius );
176: vec4 color_type = GetLight( idx, color_type );
177: vec3 L;
178: float attenuation;
179:
180: if( color_type.w == 0.0 ) {
181: // point light
182: L = center_radius.xyz - P;
183: attenuation = 1.0 / (1.0 + 8.0 * length(L) / center_radius.w);
184: L = normalize(L);
185: } else if( color_type.w == 1.0 ) {
186: // spot light
187: vec4 direction_angle = GetLight( idx, direction_angle );
188: L = center_radius.xyz - P;
189: attenuation = 1.0 / (1.0 + 8.0 * length(L) / c
199: }
200: computeLight( L, normal, viewDir,
201: attenuation * attenuation * color_type.xyz,
202: diffuse, material, color );
203: }
204:
205: void computeDLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4 material,
206: inout vec4 color ) {
207: vec2 tile = floor( gl_FragCoord.xy * (1.0 / float( TILE_SIZE ) ) ) + 0.5;
208: vec3 tileScale = vec3( r_tileStep, 1.0/numLayers );
209:
210: #if defined(r_showLightTiles)
211: float numLights = 0.0;
212: #endif
213:
214: for( int layer = 0; layer < numLayers; layer++ ) {
215: idxs_t idxs = fetchIdxs( tileScale * vec3( tile, float( layer ) + 0.5 ) );
216: for( int i = 0; i < lightsPerLayer; i++ ) {
217: int idx = numLayers * nextIdx( idxs ) + layer;
218:
219: if( idx >= u 2: ===========================================================================
3: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
4:
5: This file is part of XreaL source code.
6:
7: XreaL source code is free software; you can redistribute it
8: and/or modify it under the terms of the GNU General Public License as
9: published by the Free Software Foundation; either version 2 of the License,
10: or (at your option) any later version.
11:
12: XreaL source code is distributed in the hope that it will be
13: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: al
31:
32: #if defined(USE_RELIEF_MAPPING)
33: #if !defined(USE_HEIGHTMAP_IN_NORMALMAP)
34: uniform sampler2D u_HeightMap;
35: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
36: uniform float u_ReliefDepthScale;
37: uniform float u_ReliefOffsetBias;
38: #endif // USE_RELIEF_MAPPING
39:
40: // compute normal in tangent space
41: vec3 NormalInTangentSpace(vec2 texNormal)
42: {
43: vec3 normal;
44:
45: #if defined(r_normalMapping)
46: #if defined(USE_HEIGHTMAP_IN_NORMALMAP)
47: // alpha channel contains the height map so do not try to reconstruct normal map from it
48: normal = texture2D(u_NormalMap, texNormal).rgb;
49: normal = 2.0 * normal - 1.0;
50: #else // !USE_HEIGHTMAP_IN_NORMALMAP
51: // the Capcom trick abusing alpha channel of DXT1/5 formats to encode normal map
52: // https://github.com/DaemonEngine/Daemon/issues/183#issuecomment-473691252
53: //
54: // the algorithm also works with normal maps in rgb format without alpha channel
55: // but we still must be sure there is no height map in alpha channel hence the test
56: //
57: // crunch -dxn seems to produce such files, since alpha channel is abused such format
58: // is unsuitable to embed height map, then height map must be distributed as loose file
59: normal = texture2D(u_NormalMap, texNormal).rga;
60: normal.x *= normal.z;
61: normal.xy = 2.0 * normal.xy - 1.0;
62: // In a perfect world this code must be enough:
63: // normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
64: //
115: #if !defined(USE_LIGHT_MAPPING) || !defined(USE_DELUXE_MAPPING)
116: #if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
117: // Compute light grid position.
118: vec3 lightGridPos = (var_Position - u_LightGridOrigin) * u_LightGridScale;
119: #endif
120: #endif
121:
122: #if defined(USE_DELUXE_MAPPING)
123: // Compute light direction in world space from deluxe map.
124: vec4 deluxe = texture2D(u_DeluxeMap, var_TexLight);
125: vec3 lightDir = normalize(2.0 * deluxe.xyz - 1.0);
126: #else
127: #if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
128: // Compute light direction in world space from light grid.
129: vec4 texel = texture3D(u_LightGrid2, lightGridPos);
130: vec3 lightDir = normalize(texel.xyz - (128.0 / 255.0));
131: #endif
132: #endif
133:
134: #if defined(USE_LIGHT_MAPPING)
135: // Compute light color from world space lightmap.
136: vec3 lightColor = texture2D(u_LightMap, var_TexLight).rgb;
137:
138: #if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
139: color.rgb = vec3(0.0);
140: #else
141: color.rgb = lightColor.rgb * diffuse.rgb;
142: #endif
143: #else
144: // Compute light color from lightgrid.
145: vec3 ambientColor, lightColor;
146: ReadLightGrid(texture3D(u_LightGrid1, lightGridPos), ambientColor, lightColor);
147:
148: color.rgb = ambientColor * r_AmbientScale * diffuse.rgb;
149: #endif
150:
151: #if defined(USE_LIGHT_MAPPING)
152: /* Lightmaps generated by q3map2 don't store the raw light value, but
153: they store light premultiplied with the dot product of the ligh 157: The lightmap stores the light in this way because for the diffuse
158: lighting formula the outgoing light is equal to the incoming light
159: multiplied by the above dot product multiplied by the surface albedo.
160: So this premultiplication means that the diffuse lighting value can
161: be calculated with a single multiply operation.
162:
163: But specular lighting and/or normal mapping formulas are more complex,
164: and so you need the true light value to get correct lighting.
165: Obviously the data is not good enough to recover the original color
166: in all cases. The lower bound was an arbitrary chose factor to
167: prevent too small divisors resulting in too bright lights.
168:
169: Increasing the value should reduce these artifacts. -- gimhael
170: https://github.com/DaemonEngine/Daemon/issues/299#issuecomment-606186347
171: */
172:
173: #if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
174: // Divide by cosine term to restore original light color.
175: lightColor /= clamp(dot(normalize(var_Normal), lightDir), 0.3, 1.0);
176: #endif
177: #endif
178:
179: #if !defined(HACK_NO_BSP_GRID_LIGHTDIR)
180: // Blend static light.
181: computeLight(lightDir, normal, viewDir, lightColor, diffuse, material, color);
182: #endif
183:
184: #if defined(r_dynamicLight)
185: // Blend dynamic lights.
186: computeDLights(var_Position, normal, viewDir, diffuse, material, color);
187: #endif
188:
189: // Add Rim Lighting to highlight the edges on model entities.
190: #if defined(r_rimLighting) && !defined(USE_BSP_SURFACE) && !defined(USE_LIGHT_MAPPING)
191: float rim = pow(1.0 - clamp(dot(normal, viewDir), 0.0, 1.0), r_RimExponent);
192: vec3 emission = ambientColor * rim * rim * 0.2;
193: color.rgb += 0.7 * emission;
194: #endif
195:
196: #if defined(r_glowMapping)
197: // Blend gl
Warn: Compile log:
ERROR: 0:135: '+=' : syntax error: syntax error
Warn: Unhandled exception (15ShaderException): Couldn't compile fragment shader: lightMapping
@illwieckz got that on Intel+Nvidia mac:
Client 0 connecting
Calling GetRefAPI…
GL_VENDOR: NVIDIA Corporation
GL_RENDERER: NVIDIA GeForce GT 640M OpenGL Engine
GL_VERSION: 4.1 NVIDIA-14.0.32 355.11.11.10.10.143
GL_MAX_TEXTURE_SIZE: 16384
GL_SHADING_LANGUAGE_VERSION: 4.10
GL_MAX_VERTEX_UNIFORM_COMPONENTS 4096
GL_MAX_VERTEX_ATTRIBS 16
Occlusion query bits: 32
GL_MAX_DRAW_BUFFERS: 8
GL_MAX_RENDERBUFFER_SIZE: 16384
GL_MAX_COLOR_ATTACHMENTS: 8
PIXELFORMAT: color(24-bits)
MODE: -1, 1344 x 756 windowed hz: N/A
Using OpenGL version 4.1, requested: 3.2
Using OpenGL 3.x context.
Using an OpenGL core profile.
OpenGL 3.x context is forward compatible.
Using OpenGL extensions: GL_ARB_half_float_pixel GL_ARB_texture_float GL_EXT_gpu_shader4 GL_EXT_texture_integer GL_ARB_texture_rg GL_ARB_texture_gather GL_EXT_texture_compression_s3tc GL_ARB_texture_compression_rgtc GL_ARB_half_float_vertex GL_ARB_framebuffer_object GL_ARB_uniform_buffer_object GL_ARB_map_buffer_range GL_ARB_sync
Missing OpenGL extensions: GL_ARB_debug_output GL_ARB_get_program_binary GL_ARB_buffer_storage
Using S3TC (DXTC) texture compression.
Using GPU vertex skinning with max 233 bones in a single pass, models are hardware accelerated.
Extracting VM module cgame-x86_64.nexe from /Users/demo/Desktop/unvanquished_0.52.1-20220730-212637-57e726b/pkg/unvanquished_0.52.1-20220730-212637-57e726b.dpk...
Loading VM module cgame-x86_64.nexe...
Using loader args: /Users/demo/Desktop/unvanquished_0.52.1-20220730-212637-57e726b/Unvanquished.app/Contents/MacOS/nacl_loader -v -B /Users/demo/Desktop/unvanquished_0.52.1-20220730-212637-57e726b/Unvanquished.app/Contents/MacOS/irt_core-x86_64.nexe -e -i 100:45 -- /Users/demo/Library/Application Support/Unvanquished/cgame-x86_64.nexe 100
Loaded VM module in 139 msec
Loading Lua interpreter
Loaded font face unifont (from fonts/unifont.ttf).
Loaded font face Roboto (from fonts/Roboto-Bold.ttf).
Loaded font face Roboto (from fonts/Roboto-BoldItalic.ttf).
Loaded font face Roboto (from fonts/Roboto-Italic.ttf).
Loaded font face Roboto (from fonts/Roboto-Regular.ttf).
Loaded font face FontAwesome (from fonts/fontawesome-webfont.ttf).
Loaded font face DejaVu Sans (from fonts/DejaVuSansCondensed.ttf).
Loaded font face Material Icons (from fonts/MaterialIcons-Regular.ttf).
Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: CM_AddFacetBevels... invalid bevel
Warn: Source for shader program lightMapping:
0: #version 410 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: #define IN(mode) mode in
6: #define DECLARE_OUTPUT(type) out type outputColor;
7: #define textureCube texture
8: #define texture2D texture
9: #define texture2DProj textureProj
10: #define texture3D texture
11: #ifndef r_precomputedLighting
12: #define r_precomputedLighting 1
13: #endif
14: #ifndef r_vertexSkinning
15: #define r_vertexSkinning 1
16: #endif
17: const int MAX_GLSL_BONES = 233;
18: const float r_wrapAroundLighting = 6.99999988e-01;
19: #ifndef r_halfLambertLighting
20: #define r_halfLambertLighting 1
21: #endif
22: #ifndef r_glowMapping
23: #define r_glowMapping 1
24: #endif
25: #ifndef TEXTURE_RG
26: #define TEXTURE_RG 1
27: #endif
28: #ifndef UNIFORM_BUFFER_OBJECT
29: #define UNIFORM_BUFFER_OBJECT 1
30: #endif
31: #ifndef TEXTURE_INTEGER
32: #define TEXTURE_INTEGER 1
33: #endif
34: #ifndef r_AmbientScale
35: #define r_AmbientScale 1.00000000e+00
36: #endif
37: #ifndef r_SpecularScale
38: #define r_SpecularScale 1.00000000e+00
39: #endif
40: #ifndef r_zNear
41: #define r_zNear 3.00000000e+00
42: #endif
43: #ifndef M_PI
44: #define M_PI 3.14159274e+00
45: #endif
46: #ifndef MAX_SHADOWMAPS
47: #define MAX_SHADOWMAPS 5
48: #endif
49: #ifndef MAX_REF_LIGHTS
50: #define MAX_REF_LIGHTS 1024
51: #endif
52: #ifndef TILE_SIZE
53: #define TILE_SIZE 16
54: #endif
55: #ifndef r_FBufSize
56: #define r_FBufSize vec2(1.34400000e+03, 7.56000000e+02)
57: #endif
58: #ifndef r_tileStep
59: #define r_tileStep vec2(1.19047621e-02, 2.11640205e-02)
60: #endif
0: #line 0
1: /*
2: ===========================================================================
3: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
4:
5: This file is part of XreaL source code.
6:
7: XreaL source code is free software; you can redistribute it
8: and/or modify it under the terms of the GNU General Public License as
9: published by the Free Software Foundation; either version 2 of the License,
10: or (at your option) any later version.
11:
12: XreaL source code is distributed in the hope that it will be
13: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with XreaL source code; if not, write to the Free Software
19: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: ===========================================================================
21: */
22: // computeLight_fp.glsl - Light computing helper functions
23:
24: #if defined(USE_REFLECTIVE_SPECULAR)
25: uniform samplerCube u_EnvironmentMap0;
26: uniform samplerCube u_EnvironmentMap1;
27: uniform float u_EnvironmentInterpolation;
28: #endif // USE_REFLECTIVE_SPECULAR
29:
30: #ifdef HAVE_ARB_uniform_buffer_object
31: struct light {
32: vec4 center_radius;
33: vec4 color_type;
34: vec4 direction_angle;
35: };
36:
37: layout(std140) uniform u_Lights {
38: light lights[ MAX_REF_LIGHTS ];
39: };
40: #define GetLight(idx, component) lights[idx].component
41: #else // !HAVE_ARB_uniform_buffer_object
42: uniform sampler2D u_Lights;
43: #define idxToTC( idx, w, h ) vec2( floor( ( idx * ( 1.0 / w ) ) + 0.5 ) * ( 1.0 / h ), \
44: fract( ( idx + 0.5 ) * (1.0 / w ) ) )
45: const struct GetLightOffsets {
46: int center_radius;
47: int color_type;
48: int direction_angle;
49: } getLightOffsets = GetLightOffsets(0, 1, 2);
50: #define GetLight(idx, component) texture2D( u_Lights, idxToTC(3 * idx + getLightOffsets.component, 64.0, float( 3 * MAX_REF_LIGHTS / 64 ) ) )
51: #endif // HAVE_ARB_uniform_buffer_object
52:
53: uniform int u_numLights;
54:
55: uniform vec2 u_SpecularExponent;
56:
57: // lighting helper functions
58:
59: void ReadLightGrid(in vec4 texel, out vec3 ambientColor, out vec3 lightColor) {
60: float ambientScale = 2.0 * texel.a;
61: float directedScale = 2.0 - ambientScale;
62: ambientColor = ambientScale * texel.rgb;
63: lightColor = directedScale * texel.rgb;
64: }
65:
66: void computeLight( vec3 lightDir, vec3 normal, vec3 viewDir, vec3 lightColor,
67: vec4 diffuseColor, vec4 materialColor,
68: inout vec4 color ) {
69: vec3 H = normalize( lightDir + viewDir );
70:
71: #if defined(USE_PHYSICAL_MAPPING) || defined(r_specularMapping)
72: float NdotH = clamp( dot( normal, H ), 0.0, 1.0 );
73: #endif // USE_PHYSICAL_MAPPING || r_specularMapping
74:
75: // clamp( NdotL, 0.0, 1.0 ) is done below
76: // if no r_halfLambertLighting and no r_wrapAroundLighting.
77: float NdotL = dot( normal, lightDir );
78:
79: #if defined(r_halfLambertLighting)
80: // http://developer.valvesoftware.com/wiki/Half_Lambert
81: NdotL = NdotL * 0.5 + 0.5;
82: NdotL *= NdotL;
83: #elif defined(r_wrapAroundLighting)
84: NdotL = clamp( NdotL + r_wrapAroundLighting, 0.0, 1.0) / clamp(1.0 + r_wrapAroundLighting, 0.0, 1.0);
85: #else
86: NdotL = clamp( NdotL, 0.0, 1.0 );
87: #endif
88:
89: vec3 light = lightColor.rgb * NdotL * diffuseColor.rgb;
90:
91: #if defined(USE_PHYSICAL_MAPPING)
92: // Daemon PBR packing defaults to ORM like glTF 2.0 defines
93: // https://www.khronos.org/blog/art-pipeline-for-gltf
94: // > ORM texture for Occlusion, Roughness, and Metallic
95: // https://github.com/KhronosGroup/glTF/blob/master/specification/2.0/schema/material.pbrMetallicRoughness.schema.json
96: // > The metalness values are sampled from the B channel. The roughness values are sampled from the G channel.
97: // > These values are linear. If other channels are present (R or A), they are ignored for metallic-roughness calculations.
98: // https://docs.blender.org/manual/en/2.80/addons/io_scene_gltf2.html
99: // > glTF stores occlusion in the red (R) channel, allowing it to optionally share the same image
100: // > with the roughness and metallic channels.
101: float roughness = materialColor.g;
102: float metalness = materialColor.b;
103:
104: float NdotV = clamp( dot( normal, viewDir ), 0.0, 1.0);
105: float VdotH = clamp( dot( viewDir, H ), 0.0, 1.0);
106:
107: float alpha = roughness * roughness;
108: float k = 0.125 * (roughness + 1.0) * (roughness + 1.0);
109:
110: float D = alpha / ((NdotH * NdotH) * (alpha * alpha - 1.0) + 1.0);
111: D *= D;
112:
113: float FexpNH = pow(1.0 - NdotH, 5.0);
114: float FexpNV = pow(1.0 - NdotV, 5.0);
115: vec3 F = mix(vec3(0.04), diffuseColor.rgb, metalness);
116: F = F + (1.0 - F) * FexpNH;
117:
118: float G = NdotL / (NdotL * (1.0 - k) + k);
119: G *= NdotV / (NdotV * (1.0 - k) + k);
120:
121: light *= (1.0 - metalness);
122: light += lightColor.rgb * vec3((D * F * G) / (4.0 * NdotV));
123: color.a = mix(diffuseColor.a, 1.0, FexpNV);
124: #else // !USE_PHYSICAL_MAPPING
125:
126: #if defined(USE_REFLECTIVE_SPECULAR)
127: // not implemented for PBR yet
128: vec4 envColor0 = textureCube(u_EnvironmentMap0, reflect(-viewDir, normal));
129: vec4 envColor1 = textureCube(u_EnvironmentMap1, reflect(-viewDir, normal));
130:
131: materialColor.rgb *= mix(envColor0, envColor1, u_EnvironmentInterpolation).rgb;
132: #endif // USE_REFLECTIVE_SPECULAR
133:
134: #if defined(r_specularMapping)
135: // The minimal specular exponent should preferably be nonzero to avoid the undefined pow(0, 0)
136: light += lightColor.rgb * materialColor.rgb * pow(NdotH, u_SpecularExponent.x * materialColor.a + u_SpecularExponent.y) * r_SpecularScale;
137: #endif // r_specularMapping
138: #endif // !USE_PHYSICAL_MAPPING
139:
140: color.rgb += light;
141: }
142:
143: #if defined(TEXTURE_INTEGER)
144: const int lightsPerLayer = 16;
145: uniform usampler3D u_LightTiles;
146: #define idxs_t uvec4
147: idxs_t fetchIdxs( in vec3 coords ) {
148: return texture3D( u_LightTiles, coords );
149: }
150: int nextIdx( inout idxs_t idxs ) {
151: uvec4 tmp = ( idxs & uvec4( 3 ) ) * uvec4( 0x40, 0x10, 0x04, 0x01 );
152: idxs = idxs >> 2;
153: return int( tmp.x + tmp.y + tmp.z + tmp.w );
154: }
155: #else // !TEXTURE INTEGER
156: const int lightsPerLayer = 4;
157: uniform sampler3D u_LightTiles;
158: #define idxs_t vec4
159: idxs_t fetchIdxs( in vec3 coords ) {
160: return texture3D( u_LightTiles, coords ) * 255.0;
161: }
162: int nextIdx( inout idxs_t idxs ) {
163: vec4 tmp = idxs;
164: idxs = floor(idxs * 0.25);
165: tmp -= 4.0 * idxs;
166: return int( dot( tmp, vec4( 64.0, 16.0, 4.0, 1.0 ) ) );
167: }
168: #endif // TEXTURE_INTEGER
169:
170: const int numLayers = MAX_REF_LIGHTS / 256;
171:
172: #if defined(r_dynamicLight)
173: void computeDLight( int idx, vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse,
174: vec4 material, inout vec4 color ) {
175: vec4 center_radius = GetLight( idx, center_radius );
176: vec4 color_type = GetLight( idx, color_type );
177: vec3 L;
178: float attenuation;
179:
180: if( color_type.w == 0.0 ) {
181: // point light
182: L = center_radius.xyz - P;
183: attenuation = 1.0 / (1.0 + 8.0 * length(L) / center_radius.w);
184: L = normalize(L);
185: } else if( color_type.w == 1.0 ) {
186: // spot light
187: vec4 direction_angle = GetLight( idx, direction_angle );
188: L = center_radius.xyz - P;
189: attenuation = 1.0 / (1.0 + 8.0 * length(L) / center_radius.w);
190: L = normalize( L );
191:
192: if( dot( L, direction_angle.xyz ) <= direction_angle.w ) {
193: attenuation = 0.0;
194: }
195: } else if( color_type.w == 2.0 ) {
196: // sun (directional) light
197: L = GetLight( idx, direction_angle ).xyz;
198: attenuation = 1.0;
199: }
200: computeLight( L, normal, viewDir,
201: attenuation * attenuation * color_type.xyz,
202: diffuse, material, color );
203: }
204:
205: void computeDLights( vec3 P, vec3 normal, vec3 viewDir, vec4 diffuse, vec4 material,
206: inout vec4 color ) {
207: vec2 tile = floor( gl_FragCoord.xy * (1.0 / float( TILE_SIZE ) ) ) + 0.5;
208: vec3 tileScale = vec3( r_tileStep, 1.0/numLayers );
209:
210: #if defined(r_showLightTiles)
211: float numLights = 0.0;
212: #endif
213:
214: for( int layer = 0; layer < numLayers; layer++ ) {
215: idxs_t idxs = fetchIdxs( tileScale * vec3( tile, float( layer ) + 0.5 ) );
216: for( int i = 0; i < lightsPerLayer; i++ ) {
217: int idx = numLayers * nextIdx( idxs ) + layer;
218:
219: if( idx >= u_numLights )
220: {
221: #if defined(r_showLightTiles)
222: if (numLights > 0.0)
223: {
224: color = vec4(numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), 1.0);
225: }
226: #endif
227: return;
228: }
229:
230: computeDLight( idx, P, normal, viewDir, diffuse, material, color );
231:
232: #if defined(r_showLightTiles)
233: numLights++;
234: #endif
235: }
236: }
237:
238: #if defined(r_showLightTiles)
239: if (numLights > 0.0)
240: {
241: color = vec4(numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), numLights/(lightsPerLayer*numLayers), 1.0);
242: }
243: #endif
244: }
245: #endif
0: #line 0
1: /*
2: ===========================================================================
3: Copyright (C) 2009-2011 Robert Beckebans <trebor_7@users.sourceforge.net>
4:
5: This file is part of XreaL source code.
6:
7: XreaL source code is free software; you can redistribute it
8: and/or modify it under the terms of the GNU General Public License as
9: published by the Free Software Foundation; either version 2 of the License,
10: or (at your option) any later version.
11:
12: XreaL source code is distributed in the hope that it will be
13: useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15: GNU General Public License for more details.
16:
17: You should have received a copy of the GNU General Public License
18: along with XreaL source code; if not, write to the Free Software
19: Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20: ===========================================================================
21: */
22: // reliefMapping_fp.glsl - Relief mapping helper functions
23:
24: #if defined(r_normalMapping) || defined(USE_HEIGHTMAP_IN_NORMALMAP)
25: uniform sampler2D u_NormalMap;
26: #endif // r_normalMapping || USE_HEIGHTMAP_IN_NORMALMAP
27:
28: #if defined(r_normalMapping)
29: uniform vec3 u_NormalScale;
30: #endif // r_normalMapping
31:
32: #if defined(USE_RELIEF_MAPPING)
33: #if !defined(USE_HEIGHTMAP_IN_NORMALMAP)
34: uniform sampler2D u_HeightMap;
35: #endif // !USE_HEIGHTMAP_IN_NORMALMAP
36: uniform float u_ReliefDepthScale;
37: uniform float u_ReliefOffsetBias;
38: #endif // USE_RELIEF_MAPPING
39:
40: // compute normal in tangent space
41: vec3 NormalInTangentSpace(vec2 texNormal)
42: {
43: vec3 normal;
44:
45: #if defined(r_normalMapping)
46: #if defined(USE_HEIGHTMAP_IN_NORMALMAP)
47: // alpha channel contains the height map so do not try to reconstruct normal map from it
48: normal = texture2D(u_NormalMap, texNormal).rgb;
49: normal = 2.0 * normal - 1.0;
50: #else // !USE_HEIGHTMAP_IN_NORMALMAP
51: // the Capcom trick abusing alpha channel of DXT1/5 formats to encode normal map
52: // https://github.com/DaemonEngine/Daemon/issues/183#issuecomment-473691252
53: //
54: // the algorithm also works with normal maps in rgb format without alpha channel
55: // but we still must be sure there is no height map in alpha channel hence the test
56: //
57: // crunch -dxn seems to produce such files, since alpha channel is abused such format
58: // is unsuitable to embed height map, then height map must be distributed as loose file
59: normal = texture2D(u_NormalMap, texNormal).rga;
60: normal.x *= normal.z;
61: normal.xy = 2.0 * normal.xy - 1.0;
62: // In a perfect world this code must be enough:
63: // normal.z = sqrt(1.0 - dot(normal.xy, normal.xy));
64: //
65: // Unvanquished texture known to trigger black normalmap artifacts
66: // when doing Z reconstruction:
67: // textures/shared_pk02_src/rock01_n
68: //
69: // Although the normal vector is supposed to have a length of 1,
70: // dot(normal.xy, normal.xy) may be greater than 1 due to compression
71: // artifacts: values as large as 1.27 have been observed with crunch -dx .
Warn: Compile log:
ERROR: 0:139: ';' : syntax error: syntax error
Warn: Unhandled exception (15ShaderException): Couldn't compile fragment shader: lightMapping
@DolceTriade got this on mac M1:
@illwieckz got that on Intel+Nvidia mac: