[英]Converting Pixijs v3 AbstractFilter to v4 Filter
I'm trying to convert a custom shader for Pixi v3 to v4.我正在尝试将 Pixi v3 的自定义着色器转换为 v4。
The original article is here: http://www.awwwards.com/a-gentle-introduction-to-shaders-with-pixi-js.html原文在这里: http : //www.awwwards.com/a-gentle-introduction-to-shaders-with-pixi-js.html
the associated CodePen here http://codepen.io/omarshe7ta/pen/xVeWWy此处关联的 CodePen http://codepen.io/omarshe7ta/pen/xVeWWy
So far, I've got this:到目前为止,我有这个:
function CustomFilter(fragmentSource) {
PIXI.Filter.call(this,
null,
fragmentSource
);
}
CustomFilter.prototype = Object.create(PIXI.Filter.prototype);
CustomFilter.prototype.constructor = CustomFilter;
// smoke shader
var shaderCode = document.getElementById('fragShader').innerHTML
var smokeShader = new CustomFilter(shaderCode);
smokeShader.uniforms.resolution[0] = width;
smokeShader.uniforms.resolution[1] = height;
smokeShader.uniforms.alpha = 1.0;
smokeShader.uniforms.shift = 1.6;
smokeShader.uniforms.time = 0;
smokeShader.uniforms.speed[0] = 0.7;
smokeShader.uniforms.speed[1] = 0.4;
var bg = PIXI.Sprite.fromImage("pixi_v3_github-pad.png");
bg.width = width;
bg.height = height;
bg.filters = [smokeShader]
stage.addChild(bg);
var logo = PIXI.Sprite.fromImage("pixi_v3_github-pad.png");
logo.x = width / 2;
logo.y = height / 2;
logo.anchor.set(0.5);
logo.blendMode = PIXI.BLEND_MODES.ADD;
stage.addChild(logo)
var count = 0
animate()
function animate() {
requestAnimationFrame(animate);
count += 0.01
smokeShader.uniforms.time = count;
renderer.render(stage);
}
Edge runs it fine Edge 运行良好
Chrome throws an error Chrome 抛出错误
pixi.min.js:13 Uncaught TypeError: Cannot read property 'value' of undefined
at e.syncUniforms (pixi.min.js:13)
at e.applyFilter (pixi.min.js:13)
at CustomFilter.t.apply (pixi.min.js:13)
at e.popFilter (pixi.min.js:13)
at e.renderAdvancedWebGL (pixi.min.js:10)
at e.renderWebGL (pixi.min.js:10)
at e.renderWebGL (pixi.min.js:10)
at e.render (pixi.min.js:13)
at animate (shader-v4.html:123)
at shader-v4.html:113
FireFox throws an error then crashes the computer. FireFox 引发错误,然后使计算机崩溃。
t.uniforms.data[u] is undefined
Anyone have ideas what's wrong and how fix it?任何人都知道出了什么问题以及如何解决?
TIA TIA
The variable变量
uniform float alpha
is not used, so presumably optimised away when the shader is compiled.未使用,因此可能在编译着色器时进行了优化。 However, CustomFilter seems oblivious to the fact.
然而,CustomFilter 似乎没有注意到这个事实。
Removing "alpha" from the code solves the problem, commenting it out doesn't.从代码中删除“alpha”可以解决问题,而将其注释掉则不行。 Presumably the shader source is "dumbly" parsed for uniforms and attributes - comments aren't taken into account.
据推测,着色器源是针对制服和属性进行“愚蠢”解析的 - 未考虑注释。
I believe Pixi now uses glsify, so it looks like glslify may have a shortcoming.我相信 Pixi 现在使用 glsify,所以看起来 glslify 可能有一个缺点。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.