-
Notifications
You must be signed in to change notification settings - Fork 231
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
Using -pp-premultiply with sRGB compression gives a brigher than expected output #477
Comments
EDIT: Ignore, yes it does. |
How are you loading your texture in the graphics API? I suspect you are loading it as a linear texture format, not an sRGB texture format, so the correct gamma curve is not being applied when the texture is being sampled. |
Input values into the compressor:
This looks correct to me for an sRGB input image. The 0.7315 in sRGB gamma = 0.4941 in linear gamma. I strongly suspect you are reading this as a linear texture in your shader, so missing the required gamma correction for an sRGB input. For linear textures you should be using |
What are the differences between processing premultiplied alpha using the Sharp library versus Ascent? Although both are supposed to perform premultiplication of the alpha channel, the resulting outputs differ. Furthermore, even though the same API is invoked in both cases, why do different results occur? I am using the LayaAir engine. |
No idea - I've never used Sharp or Ascent. However from my point of view, the compressor is currently doing the right thing for sRGB textures, which is applying the pre-multiplication in linear-space. If you want the other behavior, which is pre-multiplication without sRGB color conversion, use |
My apologies for the confusion in my description. What I meant was, does using the Sharp library for premultiplication, as shown in the code above, result in inconsistencies compared to the algorithm used within the compressor? Does the compressor only support linear premultiplication? |
Yes, the code you posted is ignoring color space information, so applying pre-mul in sRGB domain.
|
Also, going back to to an earlier question ... Are you sure these are actually loaded as sRGB ASTC textures in the graphics API? What is the API format being used when you use these at runtime? Compressing with |
"Maybe I didn't describe clearly at first. Let me detail my steps now. I conducted a comparison. The second group of operations is: |
"I also consulted the official LayaAir engine team. They indeed use the Sharp library first for PremultiplyAlpha and then utilize pvrtextoolcli for texture compression." |
Not sure how many ways I can say the same thing. Stop using astcenc sRGB mode (-cs) in your command line and use linear mode (-cl). Does that work? You are compressing this as an sRGB texture (-cs). How is the game engine setting up the texture? Is it using an sRGB or a linear format enum in the graphics API? They are different things, and need different handling for premul. It only makes sense to use sRGB mode (-cs) in the compressor if the game engine is configured to read the data as an sRGB texture. It looks like the game engine is reading it as a linear texture, so you should be using linear mode (-cl) when compressing. |
yes -cl not work it didn't work and it turned completely white. |
In linear encoding it should look darker - the border goes to 0.4 with premul, instead of 0.7. |
Output image after compressing with linear-space premultiplication:
Output after reading as a linear texture and blending on to a 136/255 grey background, which gives a 149/255 output which matches your "good" example above (modulo rounding):
|
This looks like a colorspace issue in your content pipeline and/or application - everything in the compressor seems to working correctly. Unless you can point at something specific the compressor is doing wrong, I'm going to close this ticket as the issue is not related to the to compressor behavior. |
When I convert an image using the command-line tool astcenc with the command astcenc -cs k.png [email protected] 6x6 -medium -pp-premultiply, the resulting image appears overly bright when displayed in WebGL.。
However, when I manually handle the pre-multiplication of the Alpha channel using the sharp library in Node.js and then use the command-line tool astcenc with the command astcenc -cs k.png [email protected] 6x6 -medium, the image displays correctly in WebGL.
codes are like this;
The text was updated successfully, but these errors were encountered: