Thu Feb 09 00:18:43 2017| 117| float len = result.r * 0.21 + result.g * 0.71 + result.b * 0.08;
Thu Feb 09 00:18:43 2017| 118|
Thu Feb 09 00:18:43 2017| 119| // pseudo-desaturate
Thu Feb 09 00:18:43 2017| 120| result = mix(vec3(len, len, len), result, 0.6);
Thu Feb 09 00:18:43 2017| 121|
Thu Feb 09 00:18:43 2017| 122| return result + ambient;
Thu Feb 09 00:18:43 2017| 123| }
Thu Feb 09 00:18:43 2017| 124|
Thu Feb 09 00:18:43 2017| 125|
Thu Feb 09 00:18:43 2017| 126| #ifdef SHADOW
Thu Feb 09 00:18:43 2017| 127| in vec4 shadowCoord;
Thu Feb 09 00:18:43 2017| 128| uniform sampler2DShadow shadowMap;
Thu Feb 09 00:18:43 2017| 129| uniform float sampleSize;
Thu Feb 09 00:18:43 2017| 130| uniform float bias;
Thu Feb 09 00:18:43 2017| 131|
Thu Feb 09 00:18:43 2017| 132| #define FADE_OUT 0.05
Thu Feb 09 00:18:43 2017| 133| #define INV_FADE_OUT (1.0 - 0.05)
Thu Feb 09 00:18:43 2017| 134|
Thu Feb 09 00:18:43 2017| 135| float factor()
Thu Feb 09 00:18:43 2017| 136| {
Thu Feb 09 00:18:43 2017| 137| // transform from 0, 1 to -1, 1
Thu Feb 09 00:18:43 2017| 138| vec2 coord = shadowCoord.xy * 2.0 - 1.0;
Thu Feb 09 00:18:43 2017| 139| coord = 1.0 - (abs(coord.xy) - vec2(INV_FADE_OUT)) / FADE_OUT;
Thu Feb 09 00:18:43 2017| 140| coord = min(vec2(1.0), max(vec2(0.0), coord));
Thu Feb 09 00:18:43 2017| 141|
Thu Feb 09 00:18:43 2017| 142| return 1.0 - clamp(coord.x * coord.y, 0.0, 1.0);
Thu Feb 09 00:18:43 2017| 143| }
Thu Feb 09 00:18:43 2017| 144|
Thu Feb 09 00:18:43 2017| 145| #ifdef SOFT_SHADOWS
Thu Feb 09 00:18:43 2017| 146| float sampleShadow()
Thu Feb 09 00:18:43 2017| 147| {
Thu Feb 09 00:18:43 2017| 148| float shadow = 0;
Thu Feb 09 00:18:43 2017| 149| float size = sampleSize * 1.0;
Thu Feb 09 00:18:43 2017| 150|
Thu Feb 09 00:18:43 2017| 151| for (float x = -2.0; x <= 2.0; x += 1.0)
Thu Feb 09 00:18:43 2017| 152| {
Thu Feb 09 00:18:43 2017| 153| for (float y = -2.0; y <= 2.0; y += 1.0)
Thu Feb 09 00:18:43 2017| 154| {
Thu Feb 09 00:18:43 2017| 155| shadow += texture(shadowMap, vec3(shadowCoord.xy + vec2(size * x, size * y), (shadowCoord.z - bias) / shadowCoord.w));
Thu Feb 09 00:18:43 2017| 156| }
Thu Feb 09 00:18:43 2017| 157| }
Thu Feb 09 00:18:43 2017| 158|
Thu Feb 09 00:18:43 2017| 159| return mix(shadow / 25.0, 1.0, factor());
Thu Feb 09 00:18:43 2017| 160| }
Thu Feb 09 00:18:43 2017| 161| #else
Thu Feb 09 00:18:43 2017| 162| float sampleShadow()
Thu Feb 09 00:18:43 2017| 163| {
Thu Feb 09 00:18:43 2017| 164| return mix(texture(shadowMap, vec3(shadowCoord.xy, (shadowCoord.z - bias) / shadowCoord.w)), 1.0, factor());
Thu Feb 09 00:18:43 2017| 165| }
Thu Feb 09 00:18:43 2017| 166| #endif
Thu Feb 09 00:18:43 2017| 167|
Thu Feb 09 00:18:43 2017| 168| #endif
Thu Feb 09 00:18:43 2017| 169|
Thu Feb 09 00:18:43 2017| 170| #ifdef NORMAL_MAPPING
Thu Feb 09 00:18:43 2017| 171| uniform sampler2D normalOverlayTexture;
Thu Feb 09 00:18:43 2017| 172| uniform sampler2D normalTexture;
Thu Feb 09 00:18:43 2017| 173| in vec3 tangent;
Thu Feb 09 00:18:43 2017| 174| in vec3 bitangent;
Thu Feb 09 00:18:43 2017| 175| #endif // NORMAL_MAPPING
Thu Feb 09 00:18:43 2017| 176|
Thu Feb 09 00:18:43 2017| 177| #ifdef REFLECTIONS
Thu Feb 09 00:18:43 2017| 178| uniform float minReflectivity;
Thu Feb 09 00:18:43 2017| 179| uniform float maxReflectivity;
Thu Feb 09 00:18:43 2017| 180| uniform samplerCube skyTexture;
Thu Feb 09 00:18:43 2017| 181| #endif // REFLECTIONS
Thu Feb 09 00:18:43 2017| 182|
Thu Feb 09 00:18:43 2017| 183| #ifdef OVERLAY
Thu Feb 09 00:18:43 2017| 184| uniform sampler2D overlayTexture;
Thu Feb 09 00:18:43 2017| 185| #endif // OVERLAY
Thu Feb 09 00:18:43 2017| 186|
Thu Feb 09 00:18:43 2017| 187| #ifdef GLOW_TEXTURE
Thu Feb 09 00:18:43 2017| 188| uniform sampler2D glowTexture;
Thu Feb 09 00:18:43 2017| 189| #endif // GLOW_TEXTURE
Thu Feb 09 00:18:43 2017| 190|
Thu Feb 09 00:18:43 2017| 191|
Thu Feb 09 00:18:43 2017| 192|
Thu Feb 09 00:18:43 2017| 193|
Thu Feb 09 00:18:43 2017| 194|
Thu Feb 09 00:18:43 2017| 195| void main()
Thu Feb 09 00:18:43 2017| 196| {
Thu Feb 09 00:18:43 2017| 197| vec4 texBase = texture(platingTexture, texWorld);
Thu Feb 09 00:18:43 2017| 198| vec4 texColor = texBase * color;
Thu Feb 09 00:18:43 2017| 199|
Thu Feb 09 00:18:43 2017| 200| #ifdef OVERLAY
Thu Feb 09 00:18:43 2017| 201| vec4 texOverlay = texture(overlayTexture, texWorld);
Thu Feb 09 00:18:43 2017| 202|
Thu Feb 09 00:18:43 2017| 203| texColor.rgb = mix(texColor.rgb, texOverlay.rgb, texOverlay.a);
Thu Feb 09 00:18:43 2017| 204| texBase.rgb = texColor.rgb;
Thu Feb 09 00:18:43 2017| 205| #endif // OVERLAY
Thu Feb 09 00:18:43 2017| 206|
Thu Feb 09 00:18:43 2017| 207| #ifdef NORMAL_MAPPING
Thu Feb 09 00:18:43 2017| 208| mat3 tangentToWorld = mat3(
Thu Feb 09 00:18:43 2017| 209| normalize(bitangent),
Thu Feb 09 00:18:43 2017| 210| normalize(tangent),
Thu Feb 09 00:18:43 2017| 211| normalize(normal)
Thu Feb 09 00:18:43 2017| 212| );
Thu Feb 09 00:18:43 2017| 213|
Thu Feb 09 00:18:43 2017| 214| vec3 normalTex = texture(normalTexture, texWorld).zyx;
Thu Feb 09 00:18:43 2017| 215| vec4 normalOverlay = texture(normalOverlayTexture, texCoord);
Thu Feb 09 00:18:43 2017| 216| normalTex = mix(normalTex, normalOverlay.xyz, normalOverlay.a);
Thu Feb 09 00:18:43 2017| 217| texColor = mix(texColor, color, normalOverlay.a);
Thu Feb 09 00:18:43 2017| 218|
Thu Feb 09 00:18:43 2017| 219| vec3 normalRead = (normalTex - vec3(0.5)) * 2.0;
Thu Feb 09 00:18:43 2017| 220| vec3 nnormal = normalize(tangentToWorld * normalRead);
Thu Feb 09 00:18:43 2017| 221| #else
Thu Feb 09 00:18:43 2017| 222| vec3 nnormal = normalize(normal);
Thu Feb 09 00:18:43 2017| 223| #endif
Thu Feb 09 00:18:43 2017| 224|
Thu Feb 09 00:18:43 2017| 225| // outFragColor.rgb = nnormal.rgb;
Thu Feb 09 00:18:43 2017| 226| // outFragColor.a = 1.0;
Thu Feb 09 00:18:43 2017| 227| // return;
Thu Feb 09 00:18:43 2017| 228|
Thu Feb 09 00:18:43 2017| 229| vec3 eyedir = normalize(position - eye);
Thu Feb 09 00:18:43 2017| 230|
Thu Feb 09 00:18:43 2017| 231| // direct lighting
Thu Feb 09 00:18:43 2017| 232| float lightIntensity = clamp(dot(nnormal, normalize(-lightDir)), 0.0, 1.0);
Thu Feb 09 00:18:43 2017| 233| vec3 lighting = lightIntensity * lightColor;
Thu Feb 09 00:18:43 2017| 234|
Thu Feb 09 00:18:43 2017| 235| // shadow
Thu Feb 09 00:18:43 2017| 236| #ifdef SHADOW
Thu Feb 09 00:18:43 2017| 237| float shadow = sampleShadow();
Thu Feb 09 00:18:43 2017| 238| lighting = lighting * shadow;
Thu Feb 09 00:18:43 2017| 239| #endif // SHADOW
Thu Feb 09 00:18:43 2017| 240|
Thu Feb 09 00:18:43 2017| 241| // ambient lighting
Thu Feb 09 00:18:43 2017| 242| lighting += getAmbientLighting(nnormal);
Thu Feb 09 00:18:43 2017| 243| lighting += ambientLight;
Thu Feb 09 00:18:43 2017| 244|
Thu Feb 09 00:18:43 2017| 245| outFragColor.rgb = texColor.rgb * lighting;
Thu Feb 09 00:18:43 2017| 246|
Thu Feb 09 00:18:43 2017| 247| // reflections
Thu Feb 09 00:18:43 2017| 248| vec3 rnormal = normalize(nnormal + ((vec3(1.0) - texBase.rgb) * aberration) - aberration / 2);
Thu Feb 09 00:18:43 2017| 249| vec3 eyeReflected = reflect(eyedir, rnormal);
Thu Feb 09 00:18:43 2017| 250|
Thu Feb 09 00:18:43 2017| 251| float reflectivity = 0.0;
Thu Feb 09 00:18:43 2017| 252| #ifdef REFLECTIONS
Thu Feb 09 00:18:43 2017| 253| reflectivity = minReflectivity + (maxReflectivity - minReflectivity) * (1.0 - dot(-eyedir, nnormal));
Thu Feb 09 00:18:43 2017| 254|
Thu Feb 09 00:18:43 2017| 255| #ifdef OVERLAY
Thu Feb 09 00:18:43 2017| 256| reflectivity += texOverlay.a * 0.3;
Thu Feb 09 00:18:43 2017| 257| #endif // OVERLAY
Thu Feb 09 00:18:43 2017| 258|
Thu Feb 09 00:18:43 2017| 259| #if !defined(DEFERRED)
Thu Feb 09 00:18:43 2017| 260| vec3 reflection = texture(skyTexture, eyeReflected).rgb;
Thu Feb 09 00:18:43 2017| 261| outFragColor.rgb += reflection * reflectivity;
Thu Feb 09 00:18:43 2017| 262| #endif
Thu Feb 09 00:18:43 2017| 263|
Thu Feb 09 00:18:43 2017| 264| #endif // REFLECTIONS
Thu Feb 09 00:18:43 2017| 265|
Thu Feb 09 00:18:43 2017| 266| // specular highlight
Thu Feb 09 00:18:43 2017| 267| float specular = clamp(dot(normalize(-lightDir), eyeReflected), 0.0, 1.0);
Thu Feb 09 00:18:43 2017| 268| #ifdef OVERLAY
Thu Feb 09 00:18:43 2017| 269| specular = pow(specular, (glossyness + texOverlay.a * 1000.0)) * (specularity + texOverlay.a * 2.0);
Thu Feb 09 00:18:43 2017| 270| #else
Thu Feb 09 00:18:43 2017| 271| specular = pow(specular, glossyness) * specularity;
Thu Feb 09 00:18:43 2017| 272| #endif
Thu Feb 09 00:18:43 2017| 273| #ifdef SHADOW
Thu Feb 09 00:18:43 2017| 274| specular *= shadow;
Thu Feb 09 00:18:43 2017| 275| #endif // SHADOW
Thu Feb 09 00:18:43 2017| 276| outFragColor.rgb += specular * texBase.r * lightColor;
Thu Feb 09 00:18:43 2017| 277|
Thu Feb 09 00:18:43 2017| 278| vec4 highlightColor = texture(highlightTexture, texCoord);
Thu Feb 09 00:18:43 2017| 279| highlightColor.rgb = highlightIntensity * (util0.rgb + vec3(0.6)) * (highlightColor.rgb + 0.3);
Thu Feb 09 00:18:43 2017| 280|
Thu Feb 09 00:18:43 2017| 281| // energy highlights
Thu Feb 09 00:18:43 2017| 282| outFragColor.rgb = mix(outFragColor.rgb, highlightColor.rgb, highlightColor.a);
Thu Feb 09 00:18:43 2017| 283|
Thu Feb 09 00:18:43 2017| 284|
Thu Feb 09 00:18:43 2017| 285| #ifdef GLOW_TEXTURE
Thu Feb 09 00:18:43 2017| 286| // glow
Thu Feb 09 00:18:43 2017| 287| vec4 glow = texture(glowTexture, texWorld);
Thu Feb 09 00:18:43 2017| 288| outFragColor.rgb += glow.rgb * 2.0f;
Thu Feb 09 00:18:43 2017| 289| #endif // GLOW
Thu Feb 09 00:18:43 2017| 290|
Thu Feb 09 00:18:43 2017| 291| outFragColor.a = 1;
Thu Feb 09 00:18:43 2017| 292|
Thu Feb 09 00:18:43 2017| 293| #if defined(DEFERRED)
Thu Feb 09 00:18:43 2017| 294| outNormalColor.rgb = rnormal;
Thu Feb 09 00:18:43 2017| 295| outNormalColor.a = reflectivity;
Thu Feb 09 00:18:43 2017| 296| outPositionColor.rgb = position;
Thu Feb 09 00:18:43 2017| 297| outPositionColor.a = gl_FragCoord.z / gl_FragCoord.w;
Thu Feb 09 00:18:43 2017| 298| #else
Thu Feb 09 00:18:43 2017| 299| // fog
Thu Feb 09 00:18:43 2017| 300| vec3 fogColor = texture(fogTexture, eyedir).rgb;
Thu Feb 09 00:18:43 2017| 301| float fogDistance = gl_FragCoord.z / gl_FragCoord.w;
Thu Feb 09 00:18:43 2017| 302| float fogAmount = min(maxFoggyness, 1.0 - exp(-fogDistance * fogStrength));
Thu Feb 09 00:18:43 2017| 303| outFragColor.rgb = mix(outFragColor.rgb, fogColor.rgb, fogAmount);
Thu Feb 09 00:18:43 2017| 304| #endif
Thu Feb 09 00:18:43 2017| 305|
Thu Feb 09 00:18:43 2017| 306| }
Thu Feb 09 00:18:43 2017| 307|
Thu Feb 09 00:18:43 2017| Error:
Thu Feb 09 00:18:43 2017| Vertex shader(s) linked, fragment shader(s) linked.
Thu Feb 09 00:18:43 2017|
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glClear failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void Rendering::clear(const Color&):383: GLError in glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT): GL_INVALID_FRAMEBUFFER_OPERATION
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 1000: glDrawElements has generated an error (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glDrawElements failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void IndexedSubSet<Vertex>::render() const [with Vertex = cp::BlockVertex]:66: GLError in glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0): GL_INVALID_FRAMEBUFFER_OPERATION
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glDrawElements failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void IndexedSubSet<Vertex>::render() const [with Vertex = cp::BlockVertexEx]:66: GLError in glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0): GL_INVALID_FRAMEBUFFER_OPERATION
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glDrawElements failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void IndexedSubSet<Vertex>::render() const [with Vertex = cp::BlockVertex]:66: GLError in glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0): GL_INVALID_FRAMEBUFFER_OPERATION
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glDrawElements failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void IndexedSubSet<Vertex>::render() const [with Vertex = cp::BlockVertex]:66: GLError in glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0): GL_INVALID_FRAMEBUFFER_OPERATION
Thu Feb 09 00:18:43 2017| GL DBG: HIGH TYPE_ERROR API 2162: glDrawElements failed because the currently set GL_DRAW_FRAMEBUFFER binding has incomplete status 'GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER' (GL_INVALID_FRAMEBUFFER_OPERATION)
Thu Feb 09 00:18:43 2017| void IndexedSubSet<Vertex>::render() const [with Vertex = cp::BlockVertexEx]:66: GLError in glDrawElements(GL_TRIANGLES, numIndices, GL_UNSIGNED_INT, 0): GL_INVALID_FRAMEBUFFER_OPERATION