You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Normalized
(0,0) is top-left corner, (1,1) is bottom-right.
Virtual units
(CSS), its units that pixi use for containers, displayObjects and so on. (0,0) is left-top corner, (w,h) is right-bottom.
Physical pixels
(pixels), basically same a screen units. Difference appears on retina screens. As an example, it helps in case you want to know physical pixel on the right/left/top/down of current one.
Here and in all docs we use
normalized
word for first type,
pixels
for third type. By default we are talking about virtual units (CSS).
There are 5 coordinates systems in pixi filters. Each can be used with any of three types.
Input coords
- temporary pow2 texture that FilterSystem took from the pool. Used for
texture2D
sampling.
Screen coords
- do not depend whether output is temporary texture or screen, whether there we are 10 filters away from screen, it is the screen coord.
Filter coords
- (0,0) is mapped to top-left corner of part of screen that is covered by filter. For CSS or physical units it has the same scale but different offset than screen.
Sprite texture coords
- sometimes there's extra sprite input in filter. Sprite is positioned in pixi stage tree and its area does not equal filter area. This is what we pass in
texture2D()
for extra sampler. Example is
DisplacementFilter
Sprite atlas coords
- sprite can use texture from an atlas, and just
sprite texture coords
aren't enough to get the correct value from
texture2D
. Example:
SpriteMaskFilter
Default filter code
Filter constructor params include vertex and fragment shaders. What happens if we specify
null
or
undefined
in them?
newFilter(undefined,fragShader,myUniforms);// default vertex shadernewFilter(vertShader,undefined,myUniforms);// default fragment shadernewFilter(undefined,undefined,myUniforms);// both default
aTextureCoord is normalized input coord that is passed through. If PixiJS v5 detects that attribute, it switches to v4-compatibility mode that adds old filter uniforms.
v4 default fragment shader
In case you are porting stuff from v4 and you used default fragment shader, you may notice that your filter look different in v5. That's because default v4 fragment code had a serious problem regarding double multiplication by alpha.
v4 dimensions uniform
There is very popular workaround with dimensions uniform in v4, it looks like that:
Unfortunately, in v5 it crashes because input is not RenderTarget but RenderTexture, it has no sourceFrame field. To fix the crash you have to:
replace input.sourceFrame to input.filterFrame.
add dimensions uniform in filter constructor params or body: this.uniforms.dimensions = new Float32Array(2);
However, I advice you to remove it completely in favor of built-in inputSize uniform, inputSize.xy is the size of filter area in pixels, exactly the same as dimensions. In that case you can remove extra code from constructor and apply function.
v4 padding difference
Padding in v5 applied before autoFit, in v4 it was applied after. That leads to the issue that blurFilter an other filters with padding are treated differently:
https://github.com/pixijs/pixi.js/issues/5969
Multi-pass filters
Filters can use temporary renderTextures to apply shader two times, or to apply inner filters
In v4 that function was getRenderTarget(clear, resolution). In v5 you can use getFilterTexture(resolution).
getFilterTexture() returns the texture the same size as the input. If you use resolution, filter area in new texture can have different normalized coordinate system! It is fine, unless you start to use it as an extra sampler.
Even more, due to fullscreen filters logic, there's no guarantee that getFilterTexture(0.5 * input.resolution) returns the texture that is exactly two times smaller than the input.
If you want to have it as an extra sampler, you have to use conversion functions.
Suppose we have inner filter that produces result in temporary texture with smaller resolution.