Skip to content

Commit b79877a

Browse files
committed
Renderer: apply background keyboard color.
1 parent 4a4dc15 commit b79877a

File tree

5 files changed

+9
-7
lines changed

5 files changed

+9
-7
lines changed

resources/shaders/majorKeys.frag

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ uniform int actives[128];
1414
uniform int minNoteMajor;
1515
uniform vec2 inverseScreenSize;
1616
uniform vec3 edgeColor = vec3(0.0);
17+
uniform vec3 keyColor = vec3(1.0);
1718

1819
uniform vec3 majorColor[SETS_COUNT];
1920

@@ -34,7 +35,7 @@ void main(){
3435
// If the current major key is active, the majorColor is specific.
3536
int majorId = majorIds[clamp(int(In.uv.x * notesCount) + minNoteMajor, 0, 74)];
3637
int cidMajor = actives[majorId];
37-
vec3 frontColor = (highlightKeys && cidMajor >= 0) ? majorColor[cidMajor] : vec3(1.0);
38+
vec3 frontColor = (highlightKeys && cidMajor >= 0) ? majorColor[cidMajor] : keyColor;
3839

3940
// Mix.
4041
fragColor.rgb = mix(edgeColor, frontColor, centerIntensity);

src/rendering/Renderer.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -399,13 +399,14 @@ void Renderer::drawFlashes(const std::shared_ptr<MIDIScene>& scene, float time,
399399
glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE);
400400
}
401401

402-
void Renderer::drawKeyboard(const std::shared_ptr<MIDIScene>& scene, float, const glm::vec2 & invScreenSize, const glm::vec3 & keyColor, const ColorArray & majorColors, const ColorArray & minorColors, bool highlightKeys) {
402+
void Renderer::drawKeyboard(const std::shared_ptr<MIDIScene>& scene, float, const glm::vec2 & invScreenSize, const glm::vec3 & edgeColor, const glm::vec3 & keyColor, const ColorArray & majorColors, const ColorArray & minorColors, bool highlightKeys) {
403403

404404
{
405405
_programKeyMajors.use();
406406
// Uniforms setup.
407407
_programKeyMajors.uniform("inverseScreenSize", invScreenSize);
408-
_programKeyMajors.uniform("edgeColor", keyColor);
408+
_programKeyMajors.uniform("edgeColor", edgeColor);
409+
_programKeyMajors.uniform("keyColor", keyColor);
409410
_programKeyMajors.uniforms("majorColor", majorColors.size(), majorColors.data());
410411
_programKeyMajors.uniform("highlightKeys", highlightKeys);
411412

@@ -418,7 +419,7 @@ void Renderer::drawKeyboard(const std::shared_ptr<MIDIScene>& scene, float, cons
418419
_programKeyMinors.use();
419420
// Uniforms setup.
420421
_programKeyMinors.uniform("inverseScreenSize", invScreenSize);
421-
_programKeyMinors.uniform("edgeColor", keyColor);
422+
_programKeyMinors.uniform("edgeColor", edgeColor);
422423
_programKeyMinors.uniforms("minorColor", minorColors.size(), minorColors.data());
423424
_programKeyMinors.uniform("highlightKeys", highlightKeys);
424425

src/rendering/Renderer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class Renderer {
3838

3939
void drawParticles(const std::shared_ptr<MIDIScene>& scene, float time, const glm::vec2 & invScreenSize, const State::ParticlesState & state, bool prepass);
4040

41-
void drawKeyboard(const std::shared_ptr<MIDIScene>& scene, float time, const glm::vec2 & invScreenSize, const glm::vec3 & keyColor, const ColorArray & majorColors, const ColorArray & minorColors, bool highlightKeys);
41+
void drawKeyboard(const std::shared_ptr<MIDIScene>& scene, float time, const glm::vec2 & invScreenSize, const glm::vec3 & edgeColor, const glm::vec3 & keyColor, const ColorArray & majorColors, const ColorArray & minorColors, bool highlightKeys);
4242

4343
void drawPedals(const std::shared_ptr<MIDIScene>& scene, float time, const glm::vec2 & invScreenSize, const State::PedalsState & state, float keyboardHeight, bool horizontalMode);
4444

src/rendering/Viewer.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ void Viewer::drawScore(const glm::vec2 & invSize) {
358358
void Viewer::drawKeyboard(const glm::vec2 & invSize) {
359359
const ColorArray & majColors = _state.keyboard.customKeyColors ? _state.keyboard.majorColor : _state.notes.majorColors;
360360
const ColorArray & minColors = _state.keyboard.customKeyColors ? _state.keyboard.minorColor : _state.notes.minorColors;
361-
_renderer.drawKeyboard(_scene, _timer, invSize, _state.keyboard.edgeColor, majColors, minColors, _state.keyboard.highlightKeys);
361+
_renderer.drawKeyboard(_scene, _timer, invSize, _state.keyboard.edgeColor, _state.keyboard.backColor, majColors, minColors, _state.keyboard.highlightKeys);
362362
}
363363

364364
void Viewer::drawNotes(const glm::vec2 & invSize) {

src/resources/shaders.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const std::unordered_map<std::string, std::string> shaders = {
1111
{ "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 "},
1212
{ "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 "},
1313
{ "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 "},
1515
{ "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 "},
1616
{ "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 "},
1717
{ "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

Comments
 (0)