From 481f911c8c1afaf72ee7e073c3ad97793a254723 Mon Sep 17 00:00:00 2001 From: Abdullaev Farkhodjon <45960476+fredsofdev@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:01:26 +0900 Subject: [PATCH 1/2] Create seriously.distortion.js Distortion effect for security IP camera footage --- effects/seriously.distortion.js | 101 ++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 effects/seriously.distortion.js diff --git a/effects/seriously.distortion.js b/effects/seriously.distortion.js new file mode 100644 index 0000000..9fe0698 --- /dev/null +++ b/effects/seriously.distortion.js @@ -0,0 +1,101 @@ +(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('distortion', { + commonShader: true, + shader: function (inputs, shaderSource) { + shaderSource.vertex = [ + + 'precision highp float;', + + + 'attribute vec3 aVertexPosition;', + + 'attribute vec2 aTextureCoord;', + + 'varying vec3 vPosition;', + 'varying vec2 vTextureCoord;', + + 'void main(void){', + 'vPosition = aVertexPosition;', + 'vTextureCoord = aTextureCoord;', + + 'gl_Position = vec4(vPosition,1.0);', + '}', + ].join('\n'); + shaderSource.fragment = [ + 'precision highp float;', + + 'uniform vec3 uLensS;', + 'uniform vec2 uLensF;', + + 'uniform vec2 uFov;', + + 'uniform sampler2D source;', + + 'varying vec3 vPosition;', + 'varying vec2 vTextureCoord;', + + 'vec2 GLCoord2TextureCoord(vec2 glCoord) {', + ' return glCoord * vec2(1.0, -1.0)/ 2.0 + vec2(0.5, 0.5);', + '}', + + 'void main(void){', + 'float scale = uLensS.z;', + 'vec3 vPos = vPosition;', + 'float Fx = uLensF.x;', + 'float Fy = uLensF.y;', + 'vec2 vMapping = vPos.xy;', + 'vMapping.x = vMapping.x + ((pow(vPos.y, 2.0)/scale)*vPos.x/scale)*-Fx;', + 'vMapping.y = vMapping.y + ((pow(vPos.x, 2.0)/scale)*vPos.y/scale)*-Fy;', + 'vMapping = vMapping * uLensS.xy;', + 'vMapping = GLCoord2TextureCoord(vMapping/scale);', + 'vec4 texture = texture2D(source, vec2(vMapping.x, 1.0 - abs(vMapping.y)));', + 'if(vMapping.x > 0.99 || vMapping.x < 0.01 || vMapping.y > 0.99 || vMapping.y < 0.01){', + ' texture = vec4(0.0, 0.0, 0.0, 1.0);', + '}', + 'gl_FragColor = texture;', + '}' + ].join('\n'); + return shaderSource; + }, + inPlace: true, + inputs: { + source: { + type: 'image', + uniform: 'source' + }, + uLensS: { + type: 'vector', + uniform: 'uLensS', + dimensions: 3, + defaultValue: [1.0, 1.0, 1.5] + }, + uLensF: { + type: 'vector', + uniform: 'uLensF', + dimensions: 2, + defaultValue: [0.0, 0.0] + } + + + }, + title: 'distortion', + description: '' + }); +})); From c3a0f91a0fffb83f5b2d882657584467b66b086f Mon Sep 17 00:00:00 2001 From: Abdullaev Farkhodjon <45960476+fredsofdev@users.noreply.github.com> Date: Tue, 12 Jul 2022 17:29:05 +0900 Subject: [PATCH 2/2] Update README.md --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index bd79a0f..9ea2bd3 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Full documentation is in progress at the [wiki](https://github.com/brianchirls/S - Directional Blur - Displacement Map - Dither +- Distortion - Edge Detect - Emboss - Exposure Adjust @@ -115,4 +116,4 @@ Individual plugins may be licensed differently. Check source code comments. ## Credits -Seriously.js is created and maintained by [Brian Chirls](http://chirls.com) \ No newline at end of file +Seriously.js is created and maintained by [Brian Chirls](http://chirls.com)