Closed ydcoming closed 5 months ago
~The current code for premul doesn't do anything with color space information ...~
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:
1.0000 1.0000 1.0000 0.4941
0.7315 0.7315 0.7315 0.4941
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 -cl
not -cs
.
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 -cl
not -cs
when compressing.
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?
result in inconsistencies compared to the algorithm used within the compressor
Yes, the code you posted is ignoring color space information, so applying pre-mul in sRGB domain.
Does the compressor only support linear premultiplication?
If you want the other behavior, which is pre-multiplication without sRGB color conversion, use -cl not -cs when compressing.
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 -cs
only makes sense if you sample from the texture as an sRGB texture.
"Maybe I didn't describe clearly at first. Let me detail my steps now. I conducted a comparison. The first group of operations is as follows: I used the Sharp library for PremultiplyAlpha, with the code as mentioned earlier. Then I passed the processed image to the compressor with the parameters: astcenc -cs output.png k@1.ktx 6x6 -medium. The colors appear normal in the LayaAir engine.
The second group of operations is: I directly used the compressed PremultiplyAlpha with astcenc -cs k.png k@1.ktx 6x6 -medium -pp-premultiply. In the LayaAir engine, the brightness is higher. What I mean is, there's a difference between how I handled PremultiplyAlpha myself and how the compressor did it."
"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.
Original input image:
Output image after compressing with linear-space premultiplication:
./bin/astcenc-avx2 -tl in.png in-linear-pre.png 6x6 -medium -pp-premultiply
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):
./Utils/astc_blend_test in-linear-pre.png bt-out-l.png linear pre off
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 k@1.ktx 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 k@1.ktx 6x6 -medium, the image displays correctly in WebGL.
codes are like this;
;