wayfinder Posted August 15, 2015 Share Posted August 15, 2015 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: What actually happens is a rectangle the size of the texture's native dimension (512x512): 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? Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 15, 2015 Author Share Posted August 15, 2015 edit: thought i had something but no. Quote Link to comment Share on other sites More sharing options...
xerver Posted August 16, 2015 Share Posted August 16, 2015 It is "percentages of the native dimensions" because the vertices are normalized, that is on purpose. You should be using normalized verts. Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 16, 2015 Author Share Posted August 16, 2015 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... Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 16, 2015 Author Share Posted August 16, 2015 Won't let that deter me though Quote Link to comment Share on other sites More sharing options...
xerver Posted August 16, 2015 Share Posted August 16, 2015 Hmm, I think your calculations are off somewhere. The rope/mesh classes don't do anything with a 100 magic number. There also isn't a magic number in the example: http://pixijs.github.io/examples/index.html?s=demos&f=strip-demo.js&title=Strip Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 16, 2015 Author Share Posted August 16, 2015 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)... Quote Link to comment Share on other sites More sharing options...
wayfinder Posted August 17, 2015 Author Share Posted August 17, 2015 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.