Skip to content
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

CompressedTexture: Support flipY in shaders. #4316

Open
pikaya opened this issue Jan 19, 2014 · 12 comments
Open

CompressedTexture: Support flipY in shaders. #4316

pikaya opened this issue Jan 19, 2014 · 12 comments
Milestone

Comments

@pikaya
Copy link

pikaya commented Jan 19, 2014

I convert a simple sheep model use convert_obj_three.py to .json ,
load it use THREE.JSONLoader(),
and use THREE.ImageUtils.loadCompressedTexture(texturepath) to add the texture,
but not reach my results,
here is:
image
image

here is the code : https://github.com/pikaya/lei ,

Thank you very much for someone to help me!

here is the result of DDS converted to PNG :
image

@WestLangley
Copy link
Collaborator

Confirmed. If the DDS file is converted to PNG, then the model renders correctly.

"mapDiffuse" : "monster_2008.png",

@pikaya
Copy link
Author

pikaya commented Jan 20, 2014

Thank you for your answer ,
But I have a lot of mode use DDS texture,If convert all DDS map, it will be very trouble,I want to know ,If there is a more simple method.

@mrdoob
Copy link
Owner

mrdoob commented Jan 20, 2014

Random guess... Maybe texture.flypY needs to be set to false for DDS?

@WestLangley
Copy link
Collaborator

Random guess... Maybe texture.flipY needs to be set to false for DDS?

Yes, it appears that the texture is rendered upside down, but texture.flipY has no effect for some reason.

EDIT: The three.js compressed image files (except for cube maps) appear to be inverted. monster_2008.dds is not.

@wrr
Copy link
Contributor

wrr commented Jul 23, 2014

I've researched this issue a bit, here are my findings:

OpenGL addresses textures upside down (the first row of pixels data is interpreted at the bottom row on a screen). Because this is not how browsers (and most other software) addresses pixels, WebGL for convenience provided a flag UNPACK_FLIP_Y_WEBGL to allow using standard images as textures.
In OpenGL such flag is not available, and assets are usually flipped on disk.

For compressed textures the FLIP_Y flag does not work. Flipping compressed image data is not easy, because pixels are arranged in blocks (also the flip operation would require browsers to parse DXT which AFAIK browsers avoid due to patent concerns).

Because of these, the DDS textures are handled as expected by Three.js, they are in the correct orientation from the OpenGL point of view. The library probably could provide an option to flip DXT data in JavaScript, but this doesn't seem to make much sense (applications use compressed textures for performance benefits and flipping DXT would be quite slow).

DDSes that are flipped in a correct way can be generated from non flipped images for example like this:

convert input.png -define dds:compression=dxt1 -flip output.dds

@ikerr
Copy link
Contributor

ikerr commented Jul 21, 2017

Why not have Three.js use flipY in the shader, rather than when images are uploaded to the GPU? Then it would work for all textures, including DXT-compressed ones, no?

@soadzoor
Copy link
Contributor

@wrr What kind of command line tool is the one you use like that?

@Herst
Copy link
Contributor

Herst commented Apr 14, 2018

@soadzoor
Copy link
Contributor

@Herst Thanks!

@mrdoob mrdoob added Enhancement and removed Bug labels Apr 15, 2018
@mrdoob
Copy link
Owner

mrdoob commented Apr 15, 2018

The summary of this issue is that UNPACK_FLIP_Y_WEBGL does not work with compressed textures and we could generate 1.0 - uv.y in the shader instead.

@mrdoob mrdoob added this to the rXX milestone Apr 15, 2018
aussig added a commit to OpenSceneryX/three.js that referenced this issue Jul 30, 2019
aussig added a commit to OpenSceneryX/three.js that referenced this issue Jul 30, 2019
aussig added a commit to OpenSceneryX/three.js that referenced this issue Jul 30, 2019
aussig added a commit to OpenSceneryX/three.js that referenced this issue Jul 30, 2019
aussig added a commit to OpenSceneryX/three.js that referenced this issue Apr 9, 2020
…in UV coordinates to work around mrdoob#4316, allowing us to use uncompressed DDS, compressed DDS and PNG textures interchangeably. Closes #6.
@LeviPesin
Copy link
Contributor

So seems like this issue can be easily fixed by simply adding new flag like COMPRESSED_FLIP_Y and checking it in shaders?

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 11, 2024

This issue is not exclusive to S3TC but affects all compressed texture formats.

Different workarounds are outlined in #19797 (comment). Generating compressed textures in the correct orientation is best, for all other cases the mentioned flipY() helper function to update the uv coordinates once seems like a good alternative.

In context of WebGLRenderer an enhancement in the shader is problematic since the impact on the code base is quite noticeable. You would need a GLSL define and the related JS code that manages it for all different texture slots (diffuse, normal, ao etc.).

In context of WebGPURenderer there is an additional solution:

const uvNode = uv();
material.colorNode = texture( ktxTexture, uvNode.setY( uvNode.y.oneMinus() ) );

I think we could investigate to automatically inject this code inside the renderer somehow so flipY is implemented in the shader. AFAICS, this is also @mrdoob's preferred approach, see #26818 (comment).

@Mugen87 Mugen87 changed the title THREE.js doesnt support dds texture very good ? CompressedTexture: Support flipY in shaders. Mar 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants