Jump to content

are vertex positions in a strip interpreted as percent of the texture's native dimension? or am I doing something wrong here


wayfinder
 Share

Recommended Posts

Caveat: I'm working with Phaser, so this is pixi v2, but the general principles shouldn't have changed too much.

 

I'm creating a Strip with a vertex array like so:


        var vertices = new PIXI.Float32Array([0, 0, 100, 0, 0, 100, 100, 100]);        var uvs = new PIXI.Float32Array([0, 0, 1, 0, 0, 1, 1, 1]);        var colors = new PIXI.Float32Array([1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]);        var indices = new PIXI.Uint16Array([0, 1, 2, 3]);                this.strip = new Phaser.Strip(this.game, 0, 0, 'temp/rockfill512_2', vertices, uvs, colors, indices);

(Phaser.Strip is not much more than a wrapper for PIXI.Strip, it simply passes the arrays on)

 

Now, what I would expect to happen from this is a rectangle at 0, 0 with a width and height of 100px each, and textured with one full copy of the texture, scaled down to fit the size of the rectangle, like so:

NFuixnn.png

 

What actually happens is a rectangle the size of the texture's native dimension (512x512):

g3h75HH.png

 

Playing around with the vertex values, it quickly becomes apparent that the strip isn't interpreting the vertex values as raw pixels, i.e. placing them at (x, y), but instead placing them at (x * texture.width / 100, y * texture.height / 100), i.e. interpreting them as percentages of the native dimensions of the texture

 

Is this expected behaviour? It seems exceedingly weird to me...

 

Here's the vertex shader code I'm using:


    this.vertexSrc  = [        'attribute vec2 aVertexPosition;',        'attribute vec2 aTextureCoord;',        'attribute vec4 aVertexColor;',        'uniform mat3 translationMatrix;',        'uniform vec2 projectionVector;',        'uniform vec2 offsetVector;',        'uniform vec3 tint;',        'varying vec2 vTextureCoord;',        'varying vec4 vColor;',        'void main(void) {',        '   vec3 v = translationMatrix * vec3(aVertexPosition, 1.0);',        '   v -= offsetVector.xyx;',        '   gl_Position = vec4(v.x / projectionVector.x - 1.0, v.y / -projectionVector.y + 1.0, 0.0, 1.0);',        '   vTextureCoord = aTextureCoord;',        '   vColor = aVertexColor * vec4(tint, 1.0);',        '}'    ];

If I multiply all numbers in my vertex Array by 100/texture.width (resp. 100/texture.height for y values) before rendering, the result looks as expected. But why?

 

Can you help me understand what's going on?

 

 
Link to comment
Share on other sites

But where does the factor 100 come from? That's what I don't get... I would expect normalized values to be something I'd generate with (x/texture.width, y/texture.height), like the UVs. So with normalized values if I wanted to place a vertex at 140, -32 and my baseTexture had the dimensions 512 x 1024, I'd have to set the vertex value to (140/512, -32/1024). My current situation though is that I'd have to set the vertex value to (140 * 100/512, -32 * 100/1024), and I don't see why...

Link to comment
Share on other sites

:(

 

There's nothing using "100" or "0.01" in my code (or Phaser's), do you have an idea where would I even start to look? None of the other kinds of objects (sprites, tilesprites, graphics) in my project behave like this (but of course, I'm not setting their vertices directly)...

Link to comment
Share on other sites

Okay, I did some more testing, and it appears that this has something to do with the initial texture—when I set a new texture on the strip, things go back to as I initially expected them to be, ie vertex values are interpreted as pixels and not normalized, and no factor of 100. Exceedingly weird.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...