#version 410 uniform sampler2D fontTexture; uniform sampler2D termTexture; uniform vec2 termSize; uniform float textConsoleAlpha = 1.0; in vec3 colV; in vec3 worldPos; in vec2 uvV; // 0..1 across the terminal window out vec4 fragColor; vec3 mf(vec3 x) { return x - floor(x); } void main (void) { vec2 uv = uvV.xy; // termTexture has the character data as ascii/255 in red, termSize grid uv.y = 1.0 - uv.y; uv *= termSize; vec2 charPart = fract(uv); uv = (floor(uv) + vec2(0.5, 0.5)) / termSize; // charF == ascii char 0x00 to 0xff. vec4 termPixel = texture(termTexture, uv); float charF = termPixel.r * 255.0; int charColorRrrGggBb = int(termPixel.g * 255); int flags = int(termPixel.b * 255); if((flags & 2) != 0) { // double the font size (show appropriate quarter-char in this cell) uv = uvV.xy; uv.y = 1.0 - uv.y; uv *= (termSize / 2.0); charPart = fract(uv); } // let hight-bit indicate highlighting vec4 backGround = vec4(0.1, 0.1, 0.5, 0.5); // blue transparency if((flags & 1) != 0) backGround = vec4(0.6, 0.6, 0.2, 0.6); // or yellowish if high bit set // if(charF >=128.0) // { // backGround = vec4(0.6, 0.6, 0.2, 0.6); // or yellowish if high bit set // charF -= 128.0; // } // textureFont is a 16 x 6 of char pictures, 0x20..0x7f float charLeft = mod(charF , 16.0) / 16.0; float charWidth = 1.0 / 16.0; float charTop = float(floor(charF / 16.0) - 2.0) / 6.0; float charHeight = 1.0 / 6.0; vec2 charSpot = vec2(charLeft, charTop) + charPart * vec2(charWidth, charHeight); float charVal = texture(fontTexture, charSpot).r; // pixel from character charVal = 1.0 - charVal; vec4 c = vec4(charVal, charVal, charVal, charVal); // color is white, premul c = max(c, backGround); if(charF < 1.0) discard; c.a *= textConsoleAlpha; fragColor = c; }