Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifdef FLAG_DIFFUSE_MAP
- uniform sampler2D sBasemap;
- #endif
- #ifdef FLAG_GLOW_MAP
- uniform sampler2D sGlowmap;
- #endif
- #ifdef FLAG_SPEC_MAP
- uniform sampler2D sSpecmap;
- #endif
- #ifdef FLAG_ENV_MAP
- uniform samplerCube sEnvmap;
- uniform bool alpha_spec;
- out vec3 envReflect;
- #endif
- #ifdef FLAG_NORMAL_MAP
- uniform sampler2D sNormalmap;
- out mat3 tbnMatrix;
- #endif
- #ifdef FLAG_FOG
- out float fogDist;
- #endif
- in vec3 Surface_normal;
- in vec4 Position;
- out vec4 Diffuse_color = vec4(0.0, 0.0, 0.0, 1.0);
- out vec4 Surface_Normal = vec4(0.0, 0.0, 0.0, 1.0);
- out vec4 Specular_color = vec4(0.0, 0.0, 0.0, 1.0);
- out vec4 Glow_color = vec4(0.0, 0.0, 0.0, 1.0);
- #define SPECULAR_FACTOR 1.75
- #define SPECULAR_ALPHA 0.1
- #define SPEC_FACTOR_NO_SPEC_MAP 0.6
- #define ENV_ALPHA_FACTOR 0.3
- #define GLOW_MAP_INTENSITY 1.5
- #define AMBIENT_LIGHT_BOOST 1.0
- void main() {
- vec2 texCoord = gl_TexCoord[0].xy;
- #ifdef FLAG_NORMAL_MAP
- // Normal map - convert from DXT5nm
- vec3 normal;
- normal.rg = (texture2D(sNormalmap, texCoord).ag * 2.0) - 1.0;
- #ifdef FLAG_ENV_MAP
- vec3 envOffset = vec3(0.0);
- envOffset.xy = normal.xy;
- #endif
- normal.b = sqrt(1.0 - dot(normal.rg, normal.rg));
- normal = normalize(tbnMatrix * normal);
- #else
- vec3 normal = lNormal;
- #endif
- //Write result to normal buffer
- Surface_Normal = vec4(normal, 1.0);
- //Write diffuse color to difuse buffer
- #ifdef FLAG_DIFFUSE_MAP
- Diffuse_color = texture2D(sBasemap, texCoord);
- #else
- Diffuse_color = gl_Color;
- #endif
- //Write glow color to glow buffer
- #ifdef FLAG_GLOW_MAP
- Glow_Color = texture2D(sGlowmap, texCoord).rgb * GLOW_MAP_INTENSITY;
- #endif
- //Write spec color to spec buffer
- #ifdef FLAG_SPEC_MAP
- Specular_color.rgb += lightSpecular.rgb * (texture2D(sSpecmap, texCoord).rgb * SPECULAR_FACTOR);
- Specular_color.a += (dot(lightSpecular.a, lightSpecular.a) * SPECULAR_ALPHA);
- #else
- Specular_color.rgb += lightSpecular.rgb * (baseColor.rgb * SPEC_FACTOR_NO_SPEC_MAP);
- #endif
- //Write env color to spec as well
- #ifdef FLAG_ENV_MAP
- // Env color
- #ifdef FLAG_NORMAL_MAP
- vec3 envReflectNM = envReflect + envOffset;
- vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
- Specular_color.a += (dot(textureCube(sEnvmap, envReflectNM).rgb, textureCube(sEnvmap, envReflectNM).rgb) * ENV_ALPHA_FACTOR);
- Specular_color.rgb += textureCube(sEnvmap, envReflectNM).rgb * envIntensity;
- #else
- vec3 envIntensity = (alpha_spec) ? vec3(texture2D(sSpecmap, texCoord).a) : texture2D(sSpecmap, texCoord).rgb;
- Specular_color.a += (dot(textureCube(sEnvmap, envReflect).rgb, textureCube(sEnvmap, envReflect).rgb) * ENV_ALPHA_FACTOR);
- Specular_color.rgb += textureCube(sEnvmap, envReflect).rgb * envIntensity;
- #endif
- #endif
- //Mix fog into diffuse
- #ifdef FLAG_FOG
- Diffuse_color.rgb = mix(Diffuse_color.rgb, gl_Fog.color.rgb, fogDist);
- #endif
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement