Skip to content

Commit

Permalink
gh-63: Ensures unipolar values are always clamped in range.
Browse files Browse the repository at this point in the history
Slight optimization of gain implementation.
Fixes linting issues and error in tests.
  • Loading branch information
colinbdclark committed Aug 3, 2022
1 parent ccbe32b commit f5949d4
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 14 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{
"extends": "eslint-config-fluid",
"env": {
"node": true
"node": true,
"es6": true
},
"rules": {
"dot-notation": [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"electron": "17.4.0",
"electron-icon-builder": "2.0.1",
"electron-packager": "15.4.0",
"fluid-lint-all": "1.1.5",
"fluid-lint-all": "1.2.2",
"node-jqunit": "1.1.9"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/renderer-process/css/score-panel.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@
}

.bubbles-osc-panel {
border-bottom: 0.1em solid #aaa;
color: #fff;
font-family: sans-serif;
font-size: 0.8em;
font-weight: 600;
opacity: 1;
padding: 0 0.5em 1.5em 0.5em;
border-bottom: 0.1em solid #aaa;
}
2 changes: 2 additions & 0 deletions src/renderer-process/js/modulation-matrix-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ https://github.com/colinbdclark/bubbles/raw/master/LICENSE

"use strict";

var bubbles = fluid.registerNamespace("bubbles");

fluid.defaults("bubbles.modulationMatrixView", {
gradeNames: "fluid.containerRenderingView",

Expand Down
2 changes: 0 additions & 2 deletions src/renderer-process/js/osc-relayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ https://github.com/colinbdclark/bubbles/raw/master/LICENSE

"use strict";

var bubbles = fluid.registerNamespace("bubbles");

fluid.defaults("bubbles.oscRelayer", {
gradeNames: "fluid.modelComponent",

Expand Down
2 changes: 1 addition & 1 deletion src/renderer-process/js/osc-source.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fluid.defaults("bubbles.oscSource", {
},

model: {
isListening: false,
isListening: false
/*
gain: 1.0,
layers: {
Expand Down
26 changes: 19 additions & 7 deletions src/renderer-process/shaders/bubbles.frag
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,20 @@ uniform float saturation[MAX_LAYERS];
uniform sampler2D samplers[MAX_LAYERS];
uniform vec2 textureSize;

float clampUnipolar (float value) {
if (value < 0.0) {
value = 0.0;
}

return value;
}

float luma (vec3 fragment) {
return dot(fragment, W);
}

vec3 brightnessContrast (vec3 fragment, float brightness, float contrast) {
vec3 brightnessContrast (vec3 fragment, float brightness,
float contrast) {
return (fragment - 0.5) * contrast + 0.5 + brightness;
}

Expand Down Expand Up @@ -52,15 +61,18 @@ void main(void) {
colour = brightnessContrast(colour, brightness[i], contrast[i]);

// 2. Scale colour channels.
vec3 colourScale = vec3(redScale[i], greenScale[i],
blueScale[i]);
vec3 colourScale = vec3(
clampUnipolar(redScale[i]),
clampUnipolar(greenScale[i]),
clampUnipolar(blueScale[i]));

colour = colour * colourScale;

// 3. Apply saturation.
colour = saturate(colour, saturation[i]);

// 4. Adjust overall opacity
colour = colour * opacity[i];
colour = colour * clampUnipolar(opacity[i]);

// 5. Apply luma key.
// TODO: Add some smoothstepping.
Expand All @@ -69,10 +81,10 @@ void main(void) {
// 6. Sum pixel with other layers if it isn't keyed out.
layerSum = layerSum + colour;
}

// 7. Apply gain to all layers.
layerSum = layerSum * gain;
}

// 7. Apply gain to all layers.
layerSum = layerSum * clampUnipolar(gain);

gl_FragColor = vec4(layerSum.r, layerSum.g, layerSum.b, 1.0);
}
21 changes: 20 additions & 1 deletion tests/js/main-window-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,26 @@ fluid.defaults("bubbles.tests.mainWindowTestEnvironment", {

components: {
app: {
type: "bubbles.app"
type: "bubbles.app",
options: {
components: {
mainWindow: {
options: {
model: {
url: {
expander: {
funcName: "fluid.stringTemplate",
args: [
"%url/../src/renderer-process/html/main-window.html",
"{app}.env.appRoot"
]
}
}
}
}
}
}
}
},

tester: {
Expand Down

0 comments on commit f5949d4

Please sign in to comment.