Red/Blue Channel swap in texture
by Ryan Dey (not Tom Watson) · in Torque Game Engine Advanced · 07/20/2006 (4:10 pm) · 12 replies
This may (or may not) be related to the bug thread started by pauliver, but it's different enough that I thought I'd start anew.
I was draping aerial imagery over some terrain and I thought my fields in TSE looked a little more blue-ish than the source imagery. I quickly did up a color test image, and sent it through the processing pipeline, and sure enough, the red and blue channels of of my texture are getting swapped.
Here's a screenshot (note I flipped the screenshot because I forgot to flip the texture first in photoshop)
ryan.dey1.com/files/color_swap.jpg
My processing pipeline is simply:
atlasGenerateTextureTOCFromLargeJPEG("./colors.jpg", 2, "./colors.atlas");
atlasGenerateUniqueTerrain("./Data.atlas","./elev.atlas","./colors.atlas");
Is this a known bug? Something that got overlooked, or updated in the HEAD after my last update? Working as intended (I hope not)? Should I just head for the hills and get a head start on that whole living as a hermit in a cave thing?
Much appreciated.
I was draping aerial imagery over some terrain and I thought my fields in TSE looked a little more blue-ish than the source imagery. I quickly did up a color test image, and sent it through the processing pipeline, and sure enough, the red and blue channels of of my texture are getting swapped.
Here's a screenshot (note I flipped the screenshot because I forgot to flip the texture first in photoshop)
ryan.dey1.com/files/color_swap.jpg
My processing pipeline is simply:
atlasGenerateTextureTOCFromLargeJPEG("./colors.jpg", 2, "./colors.atlas");
atlasGenerateUniqueTerrain("./Data.atlas","./elev.atlas","./colors.atlas");
Is this a known bug? Something that got overlooked, or updated in the HEAD after my last update? Working as intended (I hope not)? Should I just head for the hills and get a head start on that whole living as a hermit in a cave thing?
Much appreciated.
About the author
#2
07/20/2006 (4:27 pm)
In that case I'll just add "Manually swap color channel" in photoshop into my pipeline until it gets resolved. Thanks mate.
#3
The problem i had i made a fix for (* in map2diff_plus i swapped them), but after the first alt tab its all swapped again. Making it pretty useless [but it keeps Jesse McKinney happy so its worth it]
**Edit**
I just switched my client from fullscreen to not fullscreen (after a horrible attempt to debug with breakpoints in fullscreen. if you only have 1 screen do not try this it never works) anyway i noticed that the border around the options dialog switches colors, it goes from red to blue, to red to blue every time you click apply even if there are no other changes, not sure exactly which of the color swapping threads this belongs in, or neithor?
07/20/2006 (5:19 pm)
Could you test to see if these also swap when you alt-tab in fullscreen?The problem i had i made a fix for (* in map2diff_plus i swapped them), but after the first alt tab its all swapped again. Making it pretty useless [but it keeps Jesse McKinney happy so its worth it]
**Edit**
I just switched my client from fullscreen to not fullscreen (after a horrible attempt to debug with breakpoints in fullscreen. if you only have 1 screen do not try this it never works) anyway i noticed that the border around the options dialog switches colors, it goes from red to blue, to red to blue every time you click apply even if there are no other changes, not sure exactly which of the color swapping threads this belongs in, or neithor?
#4
now i don't claim to be a bitmap expert, but we are having trouble w/ switching, and that functions is switching colors so.... might that be the problem?
07/20/2006 (6:06 pm)
Ok so i'm not over knowledgable about bitmap formats but this is the function for convertToBGRx() which is called during the Refresh function, which is called during an alt-tab or a press of the refresh button [and this function is called no matter what]void GBitmap::convertToBGRx()
{
if( internalFormat == GFXFormatR8G8B8A8 || internalFormat == GFXFormatR8G8B8X8 )
{
for( U32 j = 0; j < numMipLevels; j++ )
{
U8 *bits = (U8*)getBits(j);
for( U32 i = 0; i<getWidth(j) * getHeight(j); i++ )
{
U8 red = bits[i * 4 + 0];
U8 green = bits[i * 4 + 1];
U8 blue = bits[i * 4 + 2];
U8 alpha = bits[i * 4 + 3];
#ifdef _XBOX
bits[i * 4 + 0] = alpha;
bits[i * 4 + 1] = blue;
bits[i * 4 + 2] = green;
bits[i * 4 + 3] = red;
#else
bits[i * 4 + 0] = blue;
bits[i * 4 + 1] = green;
bits[i * 4 + 2] = red;
bits[i * 4 + 3] = alpha;
#endif
}
}
}
else if( internalFormat == GFXFormatR8G8B8 )
{
for( U32 j = 0; j < numMipLevels; j++ )
{
U8 *bits = (U8*)getBits(j);
for( U32 i = 0; i < getWidth(j) * getHeight(j); i++ )
{
U8 red = bits[i * 3 + 0];
U8 green = bits[i * 3 + 1];
U8 blue = bits[i * 3 + 2];
bits[i * 3 + 0] = blue;
bits[i * 3 + 1] = green;
bits[i * 3 + 2] = red;
}
}
}
}now i don't claim to be a bitmap expert, but we are having trouble w/ switching, and that functions is switching colors so.... might that be the problem?
#5
The ALT-TAB problem doesn't have a work-around that I'm aware of, but the Convert one does. Basically, put the call to atlasGenerateTextureTOCFromLargeJPEG in main.cs before the engine is initialized (right near the top). You can do the other function calls once the engine has loaded up but the texture convert needs to happen before anything else. That will fix your colour problem (it did for me). Last I heard, Ben was working on a "comprehensive fix" for these numerous texture-related issues.
07/21/2006 (8:16 am)
This colour swapping has already been reported. Now, the ALT-TAB thing is a different issue but there is a work-around for the ConvertFromJPEG version. First off, Ben said that the convertToBGRx is necessary because DirectX9 is messed up and (for whatever reason) needs those colour channels to be swapped. However, this is supposed to be a one-time thing and it's happening one too many times.The ALT-TAB problem doesn't have a work-around that I'm aware of, but the Convert one does. Basically, put the call to atlasGenerateTextureTOCFromLargeJPEG in main.cs before the engine is initialized (right near the top). You can do the other function calls once the engine has loaded up but the texture convert needs to happen before anything else. That will fix your colour problem (it did for me). Last I heard, Ben was working on a "comprehensive fix" for these numerous texture-related issues.
#6
07/21/2006 (9:20 am)
If you change the color of your options dialog box to blue or red, when you hit apply on the video resolution settings portion of the page, does it change to the opposite color as well?
#7
I have been able to work around the issue with Atlas color getting swapped, but haven't looked into Alt-Tab solution or workaround yet, which also would be tied to this same thing.
08/13/2006 (7:40 pm)
I was curious if any of this had been resolved for MS4, since it has to do with lighting as well?I have been able to work around the issue with Atlas color getting swapped, but haven't looked into Alt-Tab solution or workaround yet, which also would be tied to this same thing.
#8
08/13/2006 (8:42 pm)
I do have this issue fixed insofar as it affects terrain. I am unaware of lighting related issues but if there are some be sure to let us know! :)
#9
08/13/2006 (8:46 pm)
This is fixed in MS4, the problem can occur when a texture is uploaded to DX more than once (as convertToBGRx is called again). I made changes to ensure the conversion only ever occurs once.
#10
08/13/2006 (8:48 pm)
Great! Can't wait for MS4.. I worked around it already, but good to know it wont be needed soon
#11
If you create the texture atlas files by calling the commands in main.cs, right at the top before the engine loads, only one swap will occur and the textures will appear correct in the game.
Props go to Mark Dynna (and maybe others) for that one.
08/14/2006 (8:13 am)
For reference, as you probably already know (talking to people who might not be posting here)...If you create the texture atlas files by calling the commands in main.cs, right at the top before the engine loads, only one swap will occur and the textures will appear correct in the game.
Props go to Mark Dynna (and maybe others) for that one.
#12
Ben was actually the one who found the solution. I just confirmed it for him.
08/21/2006 (10:28 am)
*tips his hat*Ben was actually the one who found the solution. I just confirmed it for him.
Torque Owner Chris Byars
Ion Productions