Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Color Look-Up Table effect, with example #96

Merged
merged 4 commits into from
Jun 28, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions effects/seriously.lut.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* global define, require */
(function (root, factory) {
'use strict';

if (typeof define === 'function' && define.amd) {
// AMD. Register as an anonymous module.
define(['seriously'], factory);
} else if (typeof exports === 'object') {
// Node/CommonJS
factory(require('seriously'));
} else {
if (!root.Seriously) {
root.Seriously = { plugin: function (name, opt) { this[name] = opt; } };
}
factory(root.Seriously);
}
}(window, function (Seriously) {
'use strict';

Seriously.plugin('lut', {
commonShader: true,
shader: function (inputs, shaderSource) {
/*
Shader borrowed from BBC R&D, with permission
*/
shaderSource.fragment = [
'precision mediump float;',

'varying vec2 vTexCoord;',

'uniform sampler2D source;',
'uniform sampler2D lut;',
'uniform float amount;',

'void main(void) {',

' vec4 textureColor = texture2D(source, vTexCoord);',
' textureColor = clamp(textureColor, 0.0, 1.0);',

' float blueColor = textureColor.b * 63.0;',

' vec2 quad1;',
' quad1.y = floor(floor(blueColor) / 8.0);',
' quad1.x = floor(blueColor) - (quad1.y * 8.0);',

' vec2 quad2;',
' quad2.y = floor(ceil(blueColor) / 8.0);',
' quad2.x = ceil(blueColor) - (quad2.y * 8.0);',

' vec2 texPos1;',
' texPos1 = (quad1 * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.rg);',

' vec2 texPos2;',
' texPos2 = (quad2 * 0.125) + 0.5/512.0 + ((0.125 - 1.0/512.0) * textureColor.rg);',

' lowp vec4 newColor1 = texture2D(lut, vec2(texPos1.x, 1.0 - texPos1.y));',
' lowp vec4 newColor2 = texture2D(lut, vec2(texPos2.x, 1.0 - texPos2.y));',

' vec4 newColor = mix(newColor1, newColor2, fract(blueColor));',

' gl_FragColor = mix(textureColor, newColor, amount);',
'}'
].join('\n');
return shaderSource;
},
inPlace: true,
inputs: {
source: {
type: 'image',
uniform: 'source'
},
lut: {
type: 'image',
uniform: 'lut'
},
amount: {
type: 'number',
uniform: 'amount',
min: 0,
max: 1,
defaultValue: 1
}
},
title: 'Color Look-Up Table',
description: ''
});
}));
83 changes: 83 additions & 0 deletions examples/color/lut.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<!DOCTYPE html>
<html>
<head>
<title>Seriously.js Color Look-Up Table Example</title>
<style type="text/css">
img {
display: none;
}

#controls {
display: inline-block;
vertical-align: top;
}

#controls input {
width: 400px;
}

label {
display: block;
}
</style>
</head>
<body>
<img src="../../examples/images/robot.jpg" id="robot"/>
<img src="../../examples/images/lut_cyanspike.png" id="cyanspike"/>
<img src="../../examples/images/lut_lockstock.png" id="lockstock"/>
<img src="../../examples/images/lut_supervivid.png" id="supervivid"/>
<canvas id="canvas" width="640" height="619"></canvas>
<div id="controls">
<div>
<label>Look-Up Table
<select id="lut">
<option value="">Original</option>
<option value="cyanspike">Cyan Spike</option>
<option value="lockstock">Lock Stock</option>
<option value="supervivid">Super Vivid</option>
</select>
</label>
</div>
<div>
<label>Amount <input type="range" id="amount" min="0" max="1" step="0.001" value="1"/></label>
</div>
</div>
<script src="../../lib/require.js"></script>
<script>
require.config({
baseUrl: '../../'
});

require([
'seriously',
'effects/seriously.lut'
], function (Seriously) {
var seriously, // the main object that holds the entire composition
effect,
target, // a wrapper object for our target canvas
selectLut = document.getElementById('lut');

function selectTable() {
if (selectLut.value) {
effect.lut = document.getElementById(selectLut.value);
target.source = effect;
} else {
target.source = '#robot';
}
}

seriously = new Seriously();
target = seriously.target('#canvas');

effect = seriously.effect('lut');
effect.source = '#robot';
effect.amount = '#amount';

selectLut.onchange = selectTable;
selectTable();

seriously.go();
});
</script>
</body>
</html>
9 changes: 8 additions & 1 deletion examples/images/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,11 @@ Attribution-NonCommercial-ShareAlike 2.0 Generic (CC BY-NC-SA 2.0)

## Panorama
by Jimmy Ferbuson
http://www.jwjferguson.com
http://www.jwjferguson.com

## Color Look-Up Talbes
by Ian Forrester
http://www.bbc.co.uk/rd/people/ianforrester
- Cyan Spike
- Lock Stock
- Super Vivid
Binary file added examples/images/lut_cyanspike.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/lut_lockstock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added examples/images/lut_supervivid.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 7 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,13 @@
<li><a href="displace">Depth Map/Displacment</a></li>
<li><a href="gradientwipe.html">Gradient Wipe</a></li>
<li><a href="crop.html">Crop</a></li>
<li><a href="color/linear-transfer.html">Linear Color Transfer</a></li>
<li>
Color Adjustment
<ul>
<li><a href="color/linear-transfer.html">Linear Color Transfer</a></li>
<li><a href="color/lut.html">Look-Up Table</a></li>
</ul>
</li>
<li><a href="target/multi-target.html">Multiple Canvas Targets</a></li>
<li><a href="demo/select.html">Select</a></li>
<li><a href="demo/drunk.html">Drunk</a></li>
Expand Down