-
Notifications
You must be signed in to change notification settings - Fork 354
/
seriously.bleach-bypass.js
90 lines (76 loc) · 2.19 KB
/
seriously.bleach-bypass.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
/* 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';
/*
Shader code:
* Copyright vade - Anton Marini
* Creative Commons, Attribution - Non Commercial - Share Alike 3.0
http://v002.info/?page_id=34
Modified to keep alpha channel constant
*/
Seriously.plugin('bleach-bypass', {
commonShader: true,
shader: function (inputs, shaderSource) {
shaderSource.fragment = [
'precision mediump float;',
'varying vec2 vTexCoord;',
'uniform sampler2D source;',
'uniform float amount;',
//constants
'const vec4 one = vec4(1.0);',
'const vec4 two = vec4(2.0);',
'const vec4 lumcoeff = vec4(0.2125,0.7154,0.0721,0.0);',
'vec4 overlay(vec4 myInput, vec4 previousmix, vec4 amount) {',
' float luminance = dot(previousmix,lumcoeff);',
' float mixamount = clamp((luminance - 0.45) * 10.0, 0.0, 1.0);',
' vec4 branch1 = two * previousmix * myInput;',
' vec4 branch2 = one - (two * (one - previousmix) * (one - myInput));',
' vec4 result = mix(branch1, branch2, vec4(mixamount) );',
' return mix(previousmix, result, amount);',
'}',
'void main (void) {',
' vec4 pixel = texture2D(source, vTexCoord);',
' vec4 luma = vec4(vec3(dot(pixel,lumcoeff)), pixel.a);',
' gl_FragColor = overlay(luma, pixel, vec4(amount));',
'}'
].join('\n');
return shaderSource;
},
inPlace: true,
inputs: {
source: {
type: 'image',
uniform: 'source',
shaderDirty: false
},
amount: {
type: 'number',
uniform: 'amount',
defaultValue: 1,
min: 0,
max: 1
}
},
title: 'Bleach Bypass',
categories: ['film'],
description: [
'Bleach Bypass film treatment',
'http://en.wikipedia.org/wiki/Bleach_bypass',
'see: "Saving Private Ryan", "Minority Report"'
].join('\n')
});
}));