@@ -11,7 +11,7 @@ const std::unordered_map<std::string, std::string> shaders = {
11
11
{ " screenquad_vert" , " #version 330\n layout(location = 0) in vec3 v;\n out INTERFACE {\n vec2 uv;\n } Out ;\n void main(){\n \n // We directly output the position.\n gl_Position = vec4(v, 1.0);\n // Output the UV coordinates computed from the positions.\n Out.uv = v.xy * 0.5 + 0.5;\n \n }\n " },
12
12
{ " screenquad_frag" , " #version 330\n in INTERFACE {\n vec2 uv;\n } In ;\n uniform sampler2D screenTexture;\n uniform vec2 inverseScreenSize;\n out vec4 fragColor;\n void main(){\n \n fragColor = texture(screenTexture,In.uv);\n \n }\n " },
13
13
{ " majorKeys_vert" , " #version 330\n layout(location = 0) in vec2 v;\n out INTERFACE {\n vec2 uv;\n } Out ;\n uniform bool horizontalMode = false;\n uniform float keyboardHeight = 0.25;\n vec2 flipIfNeeded(vec2 inPos){\n return horizontalMode ? vec2(inPos.y, -inPos.x) : inPos;\n }\n void main(){\n // Input are in -0.5,0.5\n // We directly output the position.\n // [-0.5, 0.5] to [-1, -1+2.0*keyboardHeight]\n float yShift = keyboardHeight * (2.0 * v.y + 1.0) - 1.0;\n vec2 pos2D = vec2(v.x * 2.0, yShift);\n gl_Position.xy = flipIfNeeded(pos2D);\n gl_Position.zw = vec2(0.0, 1.0);\n // Output the UV coordinates computed from the positions.\n Out.uv = v.xy + 0.5;\n \n }\n " },
14
- { "majorKeys_frag", "#version 330\n in INTERFACE {\n vec2 uv;\n } In ;\n #define SETS_COUNT 12\n #define MAJOR_COUNT 75\n uniform bool highlightKeys;\n uniform bool horizontalMode = false;\n uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)\n uniform int actives[128];\n uniform int minNoteMajor;\n uniform vec2 inverseScreenSize;\n uniform vec3 edgeColor = vec3(0.0);\n uniform vec3 majorColor[SETS_COUNT];\n const int majorIds[MAJOR_COUNT] = int[](0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24, 26, 28, 29, 31, 33, 35, 36, 38, 40, 41, 43, 45, 47, 48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83, 84, 86, 88, 89, 91, 93, 95, 96, 98, 100, 101, 103, 105, 107, 108, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127);\n out vec4 fragColor;\n void main(){\n // White keys, and separators.\n float widthScaling = horizontalMode ? inverseScreenSize.y : inverseScreenSize.x;\n float majorUvX = fract(In.uv.x * notesCount);\n // Edges on the sides\n float centerIntensity = 1.0 - step( 1.0 - 2.0 * notesCount * widthScaling, abs(majorUvX * 2.0 - 1.0));\n // If the current major key is active, the majorColor is specific.\n int majorId = majorIds[clamp(int(In.uv.x * notesCount) + minNoteMajor, 0, 74)];\n int cidMajor = actives[majorId];\n vec3 frontColor = (highlightKeys && cidMajor >= 0) ? majorColor[cidMajor] : vec3(1.0);\n // Mix.\n fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);\n fragColor.a = 1.0;\n }\n "},
14
+ { "majorKeys_frag", "#version 330\n in INTERFACE {\n vec2 uv;\n } In ;\n #define SETS_COUNT 12\n #define MAJOR_COUNT 75\n uniform bool highlightKeys;\n uniform bool horizontalMode = false;\n uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)\n uniform int actives[128];\n uniform int minNoteMajor;\n uniform vec2 inverseScreenSize;\n uniform vec3 edgeColor = vec3(0.0);\n uniform vec3 keyColor = vec3(1.0);\n uniform vec3 majorColor[SETS_COUNT];\n const int majorIds[MAJOR_COUNT] = int[](0, 2, 4, 5, 7, 9, 11, 12, 14, 16, 17, 19, 21, 23, 24, 26, 28, 29, 31, 33, 35, 36, 38, 40, 41, 43, 45, 47, 48, 50, 52, 53, 55, 57, 59, 60, 62, 64, 65, 67, 69, 71, 72, 74, 76, 77, 79, 81, 83, 84, 86, 88, 89, 91, 93, 95, 96, 98, 100, 101, 103, 105, 107, 108, 110, 112, 113, 115, 117, 119, 120, 122, 124, 125, 127);\n out vec4 fragColor;\n void main(){\n // White keys, and separators.\n float widthScaling = horizontalMode ? inverseScreenSize.y : inverseScreenSize.x;\n float majorUvX = fract(In.uv.x * notesCount);\n // Edges on the sides\n float centerIntensity = 1.0 - step( 1.0 - 2.0 * notesCount * widthScaling, abs(majorUvX * 2.0 - 1.0));\n // If the current major key is active, the majorColor is specific.\n int majorId = majorIds[clamp(int(In.uv.x * notesCount) + minNoteMajor, 0, 74)];\n int cidMajor = actives[majorId];\n vec3 frontColor = (highlightKeys && cidMajor >= 0) ? majorColor[cidMajor] : keyColor;\n // Mix.\n fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);\n fragColor.a = 1.0;\n }\n "},
15
15
{ "minorKeys_vert", "#version 330\n layout(location = 0) in vec2 v;\n out INTERFACE {\n vec2 uv;\n float id;\n } Out ;\n uniform bool horizontalMode = false;\n uniform float keyboardHeight = 0.25;\n uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)\n uniform int actives[128];\n uniform int minNoteMajor;\n uniform float minorsHeight = 0.6;\n uniform float minorsWidth = 1.0;\n vec2 flipIfNeeded(vec2 inPos){\n return horizontalMode ? vec2(inPos.y, -inPos.x) : inPos;\n }\n #define MINOR_COUNT 53\n const int minorIds[MINOR_COUNT] = int[](1, 3, 6, 8, 10, 13, 15, 18, 20, 22, 25, 27, 30, 32, 34, 37, 39, 42, 44, 46, 49, 51, 54, 56, 58, 61, 63, 66, 68, 70, 73, 75, 78, 80, 82, 85, 87, 90, 92, 94, 97, 99, 102, 104, 106, 109, 111, 114, 116, 118, 121, 123, 126);\n const int noteDelta[12] = int[](0, 0, 1, 1, 2, 3, 3, 4, 4, 5, 5, 6);\n float minorShift(int id){\n if(id == 1 || id == 6){\n return -0.1;\n }\n if(id == 3 || id == 10){\n return 0.1;\n }\n return 0.0;\n }\n void main(){\n float noteWidth = 2.0 / notesCount;\n // Size of the note : width, height based on duration and current speed.\n vec2 noteSize = vec2(0.9 * noteWidth * minorsWidth, 2.0 * minorsHeight * keyboardHeight);\n // Compute note shift.\n // Horizontal shift based on note id, width of keyboard, and if the note is minor or not.\n //float a = (1.0/(notesCount-1.0)) * (2.0 - 2.0/notesCount);\n //float b = -1.0 + 1.0/notesCount;\n // This should be in -1.0, 1.0.\n // input: noteId is in [0 MAJOR_COUNT]\n // we want minNote to -1+1/c, maxNote to 1-1/c\n float a = 2.0;\n float b = -notesCount + 1.0 - 2.0 * float(minNoteMajor);\n int minorId = minorIds[gl_InstanceID];\n int noteId = (minorId/12) * 7 + noteDelta[minorId % 12];\n float horizLoc = (float(noteId) * a + b + 1.0) / notesCount;\n float vertLoc = 2.0 * (1.0 - minorsHeight) * keyboardHeight - 1.0 + noteSize.y * 0.5;\n vec2 noteShift = vec2(horizLoc, vertLoc);\n noteShift.x += minorShift(minorId % 12) * noteSize.x;\n // Output position.\n gl_Position = vec4(flipIfNeeded(noteSize * v + noteShift), 0.0 , 1.0) ;\n // Discard keys that are too close to the screen edges.\n if(abs(noteShift.x) >= 1.0 - 0.5 * noteWidth){\n gl_Position = vec4(-40000.0);\n }\n \n // Output the UV coordinates computed from the positions.\n Out.uv = v.xy + 0.5;\n // And the active channel if present.\n Out.id = float(actives[minorId]);\n \n }\n "},
16
16
{ "minorKeys_frag", "#version 330\n in INTERFACE {\n vec2 uv;\n float id;\n } In ;\n #define SETS_COUNT 12\n uniform bool highlightKeys;\n uniform bool horizontalMode = false;\n uniform float keyboardHeight = 0.25;\n uniform float notesCount; // (maxNoteMajor - minNoteMajor + 1)\n uniform int minNoteMajor;\n uniform vec2 inverseScreenSize;\n uniform vec3 edgeColor = vec3(0.0);\n uniform vec3 minorColor[SETS_COUNT];\n uniform bool edgeOnMinors;\n uniform float minorsHeight = 0.6;\n uniform float minorsWidth = 1.0;\n vec2 minorShift(int id){\n if(id == 1 || id == 6){\n return vec2(0.0, 0.3);\n }\n if(id == 3 || id == 10){\n return vec2(0.3, 0.0);\n }\n return vec2(0.1,0.1);\n }\n out vec4 fragColor;\n void main(){\n // Center uvs\n vec2 ndc = 2.0 * In.uv - 1.0;\n float widthScaling = horizontalMode ? inverseScreenSize.y : inverseScreenSize.x;\n float heightScaling = horizontalMode ? inverseScreenSize.x : inverseScreenSize.y;\n float uvWidth = minorsWidth / float(notesCount) * 0.5;\n float uvHeight = minorsHeight * keyboardHeight * 0.5;\n // Edges on the sides and bottom.\n float xStep = step(1.0 - 2.0 * widthScaling / uvWidth, abs(ndc.x));\n float yStep = step(1.0 - 2.0 * heightScaling / uvHeight, -ndc.y);\n float centerIntensity = edgeOnMinors ? ((1.0 - xStep) * (1.0 - yStep)) : 1.0;\n // Key color changes when active.\n int cidMinor = int(In.id);\n vec3 frontColor = (highlightKeys && cidMinor >= 0) ? minorColor[cidMinor] : edgeColor;\n // Mix\n fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);\n fragColor.a = 1.0;\n }\n "},
17
17
{ " backgroundtexture_vert" , " #version 330\n layout(location = 0) in vec2 v;\n out INTERFACE {\n vec2 uv;\n } Out ;\n uniform bool behindKeyboard;\n uniform float keyboardHeight = 0.25;\n void main(){\n vec2 pos = v;\n if(!behindKeyboard){\n pos.y = (1.0-keyboardHeight) * pos.y + keyboardHeight;\n }\n // We directly output the position.\n gl_Position = vec4(pos, 0.0, 1.0);\n // Output the UV coordinates computed from the positions.\n Out.uv = v.xy * 0.5 + 0.5;\n \n }\n " },
0 commit comments