#version 150 in vec2 vertTexCoord; in vec4 vertColor; in float vertTextureIndex; uniform sampler2D textures[5]; uniform float colorRamp; uniform float colorRampWidth; uniform float colorRampRangeMin; uniform float colorRampRangeMax; uniform float depthMin; uniform float veil; // From -1.0 to 1.0 out vec4 fragColor; // Textures: // 0: Drawn with vertex color only // 1: Drawn with color ramp // 2: Drawn with color ramp and texture 2 alpha // 3: Drawn with color ramp // 4: Color ramp float adjustDepth(float depth) { return (depth - colorRampRangeMin) / (colorRampRangeMax - colorRampRangeMin) * (colorRampWidth - 1.0) / colorRampWidth + (0.5 / colorRampWidth); } void main() { float actualDepth = texture(textures[1], vertTexCoord).r; if (actualDepth < depthMin) { discard; } float depth1 = adjustDepth(actualDepth * vertColor.r); vec4 textureSample2 = texture(textures[2], vertTexCoord); float depth2 = adjustDepth(textureSample2.r * vertColor.r); float depth3 = adjustDepth(texture(textures[3], vertTexCoord).r * vertColor.r); fragColor = vec4(0, 0, 0, 0); fragColor += texture(textures[0], vertTexCoord) * int(vertTextureIndex == 0) * vertColor; ivec2 texSize = textureSize(textures[1], 0); float insideVeil = 1.0 - smoothstep(mod(vertTexCoord.x * texSize.x, 1.0) - 0.02, mod(vertTexCoord.x * texSize.x, 1.0) + 0.02, mod(vertTexCoord.y * texSize.y, 1.0) + veil); fragColor += texture(textures[4], vec2(depth1, colorRamp)) * int(vertTextureIndex == 1) * vec4(insideVeil) * vertColor.aaaa; fragColor += texture(textures[4], vec2(depth2, colorRamp)) * int(vertTextureIndex == 2) * vec4(vertColor.a * textureSample2.a); fragColor += texture(textures[4], vec2(depth3, colorRamp)) * int(vertTextureIndex == 3) * vertColor.aaaa; }