Last active
January 5, 2020 08:02
-
-
Save komietty/bfd215169a28a4190183c9c452457b48 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cvs = document.getElementById('cvs') | |
cvs.width = 800 | |
cvs.height = 600 | |
let renderer = new PIXI.WebGLRenderer(cvs.width, cvs.height, {view: cvs, antialias: true} ) | |
let container = new PIXI.Container() | |
let img = new Image() | |
img.src = "/images/detail/" + imgID + ".jpg"; | |
img.onload = function(){ | |
let sprite = new PIXI.Sprite(new PIXI.Texture(new PIXI.BaseTexture(img))) | |
sprite.width = cvs.width | |
sprite.height = cvs.height | |
container.addChild(sprite) | |
renderer.render(container) | |
} | |
let frag = | |
`precision mediump float; | |
uniform vec4 filterArea; | |
uniform sampler2D uSampler; | |
uniform mat3 mappedMatrix; | |
uniform float val; | |
varying vec2 vTextureCoord; | |
void main (void) { | |
vec3 map = vec3(vTextureCoord.xy, 1) * mappedMatrix; | |
vec4 col = texture2D(uSampler, vTextureCoord); | |
if(map.x > val) | |
gl_FragColor = texture2D(uSampler, vec2(val, vTextureCoord.y)); | |
else | |
gl_FragColor = col; | |
}` | |
.split('\n').reduce((c, a) => c + a.trim() + '\n') | |
let uniforms = { | |
val: { type: 'float', value: 0 }, | |
mappedMatrix : { type: 'mat3', value: new PIXI.Matrix() } | |
}; | |
let filter = new PIXI.Filter(null, frag, uniforms); | |
filter.apply = function (filterManager, input, output){ | |
filterManager.calculateNormalizedScreenSpaceMatrix(uniforms.mappedMatrix.value) | |
filterManager.applyFilter(this, input, output); | |
}; | |
container.filters = [filter] | |
function update(){ | |
uniforms = { | |
val: { type: 'float', value: 1 }, | |
mappedMatrix : { type: 'mat3', value: new PIXI.Matrix() } | |
}; | |
filter = new PIXI.Filter(null, frag, uniforms); | |
container.filters = [filter] | |
renderer.render(container) | |
requestAnimationFrame(update) | |
} | |
update(); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let cvs = document.getElementById('cvs') | |
cvs.width = 800 | |
cvs.height = 600 | |
let renderer = new PIXI.WebGLRenderer(cvs.width, cvs.height, {view: cvs, antialias: true} ) | |
let container = new PIXI.Container() | |
let img = new Image() | |
img.src = "/images/detail/" + imgID + ".jpg"; | |
img.onload = function(){ | |
let sprite = new PIXI.Sprite(new PIXI.Texture(new PIXI.BaseTexture(img))) | |
sprite.width = cvs.width | |
sprite.height = cvs.height | |
container.addChild(sprite) | |
renderer.render(container) | |
} | |
let frag = | |
`precision mediump float; | |
uniform vec4 filterArea; | |
uniform sampler2D uSampler; | |
uniform mat3 mappedMatrix; | |
uniform float val; | |
varying vec2 vTextureCoord; | |
void main (void) { | |
vec3 map = vec3(vTextureCoord.xy, 1) * mappedMatrix; | |
vec4 col = texture2D(uSampler, vTextureCoord); | |
if(vTextureCoord.x > val) | |
gl_FragColor = texture2D(uSampler, vec2(val, vTextureCoord.y)); | |
else | |
gl_FragColor = col; | |
}`.split('\n').reduce((c, a) => c + a.trim() + '\n') | |
let uniforms = { | |
val: { type: 'float', value: 0 }, | |
mappedMatrix : { type: 'mat3', value: new PIXI.Matrix() } | |
}; | |
let filter = new PIXI.Filter(null, frag, uniforms); | |
filter.apply = function (filterManager, input, output){ | |
filterManager.calculateNormalizedScreenSpaceMatrix(uniforms.mappedMatrix.value) | |
filterManager.applyFilter(this, input, output); | |
}; | |
container.filters = [filter] | |
function update(){ | |
uniforms = { | |
val: { type: 'float', value: 1 }, | |
mappedMatrix : { type: 'mat3', value: new PIXI.Matrix() } | |
}; | |
filter = new PIXI.Filter(null, frag, uniforms); | |
container.filters = [filter] | |
renderer.render(container) | |
requestAnimationFrame(update) | |
} | |
update(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment