New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sprites are positioned upside down or sometimes are streched #277
Comments
It is difference in coordinate system that leads to texture loading upside down . Images treat topleft as origin whereas scene is cartesian co-od system . You can rotate,scale the object on which texture loaded . |
We should be handling the vertical flipping. Not sure what you mean with stretched. Screenshot? |
Textures are pretty much always upside down for me as well, unless I'm using an orthographic camera. |
It fixes it for me, if I add this line _gl.pixelStorei(_gl.UNPACK_FLIP_Y_WEBGL, true); into the setTexture() function in WebGLRenderer.js |
Interesting. Do you mind pasting the whole setTexture method? (Just to know where exactly you added it...) |
sure
|
If you do this than all other non-sprite textures will be flipped. Seems like sprites do not do any flipping by themselves - other things do flippings in UVs or in shaders. The simplest fix would be to flip UVs in sprites vertex shader, a bit faster would be to flip sprite geometry UVs. |
Hmmm.... Wouldn't it be better to remove those UV flippings in shaders instead? |
If you mean to do everything properly then not - we have been at this point multiple times. I myself tried at least twice to clean up this damn texture flipping business, plus somebody else also tried. After big efforts always there was something left that was messed up so overall effect was always worse than before cleaning. But feel free to try ;) Hard parts are - minecraft AO example and stuff that does multipass rendering (there may be more, don't remember, for example tangents / normal mapping use UVs). Meanwhile I committed fix for |
I have the same problem with a plane post processed (with a ortho camera). |
Not using sprites right? The texture on the plane is stretched you mean? |
No sprites, only Plane Onject3D. |
Well I think there are probably different ways, but the first way I can think of is to flip the face uv coordinates by multiplying by -1.
|
ok, thanks for your quick answer. |
unfortunally, it doesn't work for me :( Info:I apply a WebGlRenderTarget to the plane. |
This hack should work: plane.doubleSided = true;
plane.scale.y = - 1; But I'll definitely take a look at all this. |
this hack work great ;) |
I hit this too. Rotating the images proved easier than figuring out a fix. But could someone explain how the hack/fix shown here would work in terms of http://alteredqualia.com/three/examples/particles_sprites_gl.html i.e. with a ParticleSystem? I couldn't find the equivalent of the plane object... |
Do you mean you have Or do you have correctly displayed texture that you want to flip to be upside down? If for some reason you want to have flipped texture on point sprites, you could either flip the image in 2d canvas before creating |
It was a very naive experiment: I took http://alteredqualia.com/three/examples/particles_sprites_gl.html and replaced the snowflake image URLs with other images; at which point it became clear the textures were upside down. |
Could you try that with more recent version of that example (version on my site is very ancient)? Just clone I tried and it works ok for me, no upside down turning. |
Not sure if 'git clone https://github.com/mrdoob/three.js.git -b dev' is the right voodoo to get dev branch, but I was working from a v recent stand git clone; the link to your site was lazyness, I just googled a working copy to illustrate the remark. Trying afresh, I still get the flipping. An image of some text now seems to be showing me its backside and upside down. This is in Firefox on OSX, I guess the graphics card is the only thing that might even matter? Chipset Model: AMD Radeon HD 6750M |
Where do you see white dots here, up or down? http://alteredqualia.com/three/examples/webgl_particles_sprites2.html Edit: I tried on my other notebook with ATI card and I think it's a bug in ATI OpenGL driver (probably in handling of I get different orientations on ATI when using ANGLE (dot is up) vs OpenGL (dot is down), while on notebook with Nvidia I get the same orientation for both ANGLE and OpenGL (dot is up, which I believe is correct one). I'm afraid there is not much that could be done about this. No matter how you flip the texture, it'll be wrongly oriented for somebody :S In theory you could try to serve different versions to different GPUs (that's how games deals with these issues) though in practice you can't due to browsers hiding GPU information. |
Down! Is that good? :) |
Bad, see my edit in the comment above. I googled about this and it seems point sprites are notorious problems with ATIs, people have issues with them for years :/. Seems like "modern" solution to this is just to forget about point sprites and use geometry shaders to create quads from points on GPU, but also this is not possible with WebGL. If you don't need many "particles", you could use just regular quads, that's what |
On 5 December 2011 01:21, AlteredQualia
ah, thanks for investigating
Ah, thanks, that's all good to know. BTW I'm entirely new to all this My immediate particles interest comes from some work with data mining So all the time each 'item' is not illustrated with its own texture, I The trickiest ambition is to do something with Pivot-viewer style http://www.youtube.com/watch?v=DbN3kWenjJs ... Pivot-viewer (if you I'm not sure yet how much of that WebGL + Three.js makes easy. So I If I had only 300 or so base textures eg. from BBC TV shows (my Anyway thanks for the help on this issue. It's a good nudge to get cheers Dan |
For applications like you linked to the best would be probably to use texture atlases - concatenate offline many smaller images into fewer bigger ones, keep somewhere metadata about offsets / sizes and then use this to pick out just the relevant subimage in the shader. That's what I think Google Bookcase does: |
On 5 December 2011 12:50, AlteredQualia
Great, thanks. I'll try that direction. I also found some interesting Dan |
Sorry to bump this old issue.. But I ran into this problem with y-flipped textures, recently. Trying to think of a way to detect and work around this. I was thinking, what if I create like a small canvas and render one sprite/particle that is red on the top half and green on the bottom half. And then I guess draw that to a 2dcanvas and pick the color at the top to see if it´s flipped or not. That way I would know if I should flip or not from there on. Would something like that work? Seems like a kinda hacky way :) Anyone got a better idea? |
I was also thinking about something like this. I don't see easier way how to find out if a system has this bug then to actually induce it. |
Maybe the test could be run on some popular demo page, for a week or so, then the results shared? Do the webgl apis share enough info to cleanly re-identify problem hardware setups? Dan |
Not directly, browsers intentionally hide GPU identification info (manufacturer, version, driver, even whether renderer is native OpenGL or ANGLE). You would need to do some datamining / machine learning on info that is available for other purposes (like max sizes of textures, available features, etc). Having small targeted code probe seems better, you can detect the problem directly instead of trying to guess correlation from bunch of unrelated numbers. Also it would be "future proof" - if some new GPU / driver messes up, it would be covered. |
On Thursday, 16 February 2012, AlteredQualia <
Makes sense. I have a friend at Apple who is happy to receive shader Dan
|
@mrdoob 太棒了 |
Hey guys, most of the times that I am adding a sprite on a webg scene, the texture is upside down, or stretched. Why is this happening. Is there a way so that I won't have to rotate it and change the scale of the object so that it matches the with, height and rotation of the texture image?
The text was updated successfully, but these errors were encountered: