Odd difference in appearance of .tga texture and .jpg

Discussion for Level editing, modeling, programming, or any of the other technical aspects of Quake
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Odd difference in appearance of .tga texture and .jpg

Post by Magnus »

Hey all.

Ok, step by step.

I opened a new file in photoshop and added an alpha channel and then cleared the immage so nothing but alpha was there.

I created a blood smear texture that I can apply to one face of a nonsolid no-draw brush.

The point was to make a texture that can be placed on a 1 unit thick brush above a floor so it will look like a bloody body has been drug along leaving a smeared trail of blood on the floor.

The texture looks great in photoshop but when I apply it in a .map in Radiant it looks like the colors have blead beyond the borders of the actuall shape of the immage I created.

I created a .jpg of the immage and it looks fine in photoshop and in Radiant, but of course the .jpg can't support the aplha transparency.

I would figure it has something to do with my shader script, but even it I totally remove any scripting fot the trxture it still looks the same. The .jpg looks just as I created it but the .tga looks like the colors have blead beyond the borders of the actuall shape of the immage I created.

I guess it could be because I am trying to apply a .tga with a alpha channel, but without a proper script for it or even applying a .tga with an alpha channel and no scripting at all.

Any ideas as to why there is a difference in the way the .jpg looks just as I created it, but the .tga looks messed up?

Thanks.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

So the tga file isn't sized correctly on the brush in game and in the editor? Have you tried simply fitting/scaling the texture to fit the brush?

Post your shader.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
reptile
Posts: 74
Joined: Sat Oct 06, 2001 7:00 am

Post by reptile »

Yeah, post your shader first and probabbly the textur.
Anyway check out that you can ask also on mapcenter.com I'm pretty sure they also can help.
Why dont you try this via patches? Like the blood is made in doom3?
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

Ok, yes I tryed making a brush to fit the texture and I also used the surface inspector the "fit" the texture as well.

My shader.

textures/sfx/bloodsmear5
{
{
map textures/sfx/bloodsmear5.tga
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
rgbGen lightingDiffuse
}
{
map textures/sfx/bloodsmear5.tga
alphaFunc GE128
depthWrite
//rgbGen identity
rgbGen lightingDiffuse

}

And this is how the .jpg and .tga immages look in photoshop:

The .tga looks the same, but the white areas are all alpha.
Image


Here is how the .jpg and .tga looks in radiant and ingame:

The .tga is on the left and the .jpg is on the right.

Image
Last edited by Magnus on Tue Oct 11, 2005 8:16 pm, edited 3 times in total.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

Hrm. Odd, haven't had that problem before. Are you sure the texture is scaled onto the brushes properly?

Possibly not related to your problem, but to "clean" up your shader:

Why do you have 2 stages of the same texture? This unnecessarily adds an extra rendering pass when only one will do.

You only need blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA (blendFunc blend). Alpha depth testing with depthWrite and alphaFunc are not necessary - they are only used on lightmapped alphachanneled surfaces (like grates). The problem with grates is that the lightmap doesn't know what part of the grate is transparent or not, resulting in shadows where the grate is actually translucent. That's when we use depthWrite and alphaFunc to compensate, by "testing" the texture's alpha channel to see if the lightmap should be transparent in those areas as well.

Change rgbGen lightingDiffuse to rgbGen identity. lightingDiffuse is only used on player models and items where lighting depends on the lightgrid.

You will likely need to add some other directives...

polygonOffset - not necessary, but I generally use this for decals. It forces the shader to be rendered above other surfaces. Adding this to your shader allows you to place the brush flush with the floor (doesn't have to be 1 unit above) and not worry about z-fighting.

surfaceparm trans - flags the surface as being transparent. Not affected by visibility calculations.

surfaceparm nonsolid - err... not solid. Players won't snag on it, weaponfire and items won't impact on it.

surfacepam nomarks - makes sure that weapon impacts don't leave marks. Otherwise, you end up with two marks, one on the floor, the second on the decal.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

obsidian wrote:Hrm. Odd, haven't had that problem before. Are you sure the texture is scaled onto the brushes properly?
I think so I made the texture into two parts. Each one is 128x40 pixels. And the brush I am creating in radiant to apply the texture on is 128x40 units. I also used the surface inspectior in two different ways.
First I just hit the "Fit" button and it fit the .jpg just fine, but the .tga looked strange as you have seenThen I used the x and y scale and x and y position to try to adjust it till it looked right. Either way the .tga looked bad.

If that isn't what you mean let me know.
obsidian wrote:Possibly not related to your problem, but to "clean" up your shader:

Why do you have 2 stages of the same texture? This unnecessarily adds an extra rendering pass when only one will do.
I actually started out with the following as my shader:

textures/sfx/bloodsmear5
{
{
map textures/sfx/bloodsmear5.tga
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
rgbGen lightingDiffuse
}
}

But when I had problems with it looking so strange I added the second stage. I guess I was aggressively trying to force it to render the alpha portions as transparent....lol.
obsidian wrote:You will likely need to add some other directives...

polygonOffset - not necessary, but I generally use this for decals. It forces the shader to be rendered above other surfaces. Adding this to your shader allows you to place the brush flush with the floor (doesn't have to be 1 unit above) and not worry about z-fighting.
So if I script it as a decal should I continue to place it on a nodraw non-solid brush? I have never used a decal. I figure I would have to place it on some kind of brush seperate from the one that is the floor. If I did that wouldn't the texture on the floor be covered in the bloodsmear texture instead of the tiles?

Also if I do use a nodraw non-solid brush amd place it right on the floor I notice a hall of mirrors effect under the texture.

This is obviosly a new experience for me.

I even tried applying the bloodsmear immage on top of a copy of the tiles textures and then just making a large seperate square brush that is part of the floor, but it just didn't look very....um...dynamic. Kind of bland.

Anyway thanks for all this help again.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

The floor should be textured with tiles. Then create another brush or patch for the decal, texture that with your shader on the top face and the other faces with nodraw. Then place the decal brush so that the top face is flush with the floor (no need for it to be 1 unit above). The decal (with polygonOffset) will be rendered by hardware to appear above the tiles.

All texture art needs to be created in dimensions in a power of 2. So something like 128x128 or 128x64 or 128x32, etc. 40 is NOT a power of 2, so this may be part of your problem.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

obsidian wrote:Then place the decal brush so that the top face is flush with the floor (no need for it to be 1 unit above). The decal (with polygonOffset) will be rendered by hardware to appear above the tiles.
Ahh! I see now.
I took the part about it not having to be 1 unit above the floor as there dosent need to be 1 unit of empty space between the bottom of the bloodsmear brush and the top of the floor brush.

Like I said I was placeing the bloodsmear texture on a nodraw non-solid brush 1unit thick and then placeing that brush 1 unit off the floor because if the nodraw non-solid brush was placed right on the floor I would get the HOM effect under the trxture.

Now I understand why you said not to worry about z fighting..heh.
obsidian wrote:All texture art needs to be created in dimensions in a power of 2. So something like 128x128 or 128x64 or 128x32, etc. 40 is NOT a power of 2, so this may be part of your problem.
True. I'll go back and resize the texture to 128x 32 and then adjust the immage to take the scue caused by resizing it out and then give it another try. I'll come back and post my results after I am finnished.

Thanks obsidian.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

OK. I resized the textures to 128x32 and applied them and I still came up with the same problem.

Here is a screenshot from ingame.
I took the screenshot into photoshop and outlined where the actuall borders of the immage are in yellow.
Anything outside the yellow outline are areas of what seems to be where the colors are bleeding outside the edges of the actuall immage in the .tga, but again this is not happening in the .jpg.
Image

So the texture is now a multiple of 2 in x and y (128x32 pixels) and it has been applied to a brush that is a multiple of 2 in x and y (128x32 units) and I it still renders like this.

I tried the texture with a shader script and without a shader script and it still looked the same.
The texture had the white outline around it in radiant so I know it is being recognised as a shader and I am not getting any warnings or errors in the console ingame.

Here is what I changed the shader to.

textures/sfx/blsm1
{
surfaceparm trans
surfaceparm nonsolid
surfaceparm nomarks
{
map textures/sfx/blsm1.tga
blendFunc GL_SRC_ALPHA GL_ONE_MINUS_SRC_ALPHA
rgbGen identity
}
}

I havent tried the polygonOffset to make it a decal yet because I want to study what parameters may be involved and what they do when useing polygonOffset.

I hope this new info gives some insite into what is going wrong.

Thanks again.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Shallow
Posts: 167
Joined: Wed Feb 09, 2005 1:58 pm

Post by Shallow »

1. Try moving the shader and everything so you aren't using /sfx/, it's possible there's a conflict, and using the game's default folders for custom content is a bad idea anyway.

2. Make certain you don't have identically named .jpg and .tga versions of the texture in the same place. The .jpg will be loaded by default.

3. If you are using Photoshop 7, patch it, the .tga saving module it shipped with was hosed.
Hr.O
Posts: 152
Joined: Wed Jul 12, 2000 7:00 am

Post by Hr.O »

standard is two pixels per unit, so your shader get's stretched.
128*32 pixel shader you stick on a 64*16 brush-face. (look closely at the picture, you see how blocky it is)
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

Actually Shallow and Hr.O are correct.

I do have the .tga and the .jpg with the same name in the SFX file

Also no I don't have photoshop 7 I have CS 6. I don't know if you guys have ever heard of it, but I also have a program called "The Gimp". It is a free altenative to photoshop and it is actually a great tool! I have Gimp 2.2 and Photoshop CS 6 and I tried turning the texture into a .tga in Gimp just like I did in Photoshop and there is no difference in the immage or the problem.

And yes I did notice that the .tga looked very blocky on the 128x32 brush like it was 8 bit or something, but the funny thing is the .jpg looks great on the 128x32 brush.

I have to admit I didn't know that thing about the 2:1 ratio for textures, but it makes a lot of sense. You would just get a higher quality looking texture ot of it.

I'll go back and remove the .jpg with the same name from the file and then apply the texture to a 64x16 brush and see what kind of results I get.

I'll be back later with more info on the results.

Thanks guys!
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

OK, I removed the .jpg with the same name from the folder and then I made a brush 64x16 and applied the 128x32 texture and I also tried remaking the texture so it is 256x64 and applied it to a 128x32 brush, but there is still no change.

Is it possible that even though the areas outside of the immage look totaly alpha in photoshop there is actually still some very faint color there that is being enhanced when I apply the texture in radiant and ingame?

It dosent seem like it because the .jpg form of the same immage has nice and clean edges and looks great as you can see in one of my above posts. It's just the .jpg isn't able to support aplha transparency.

Anyway there it is so far.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Shallow
Posts: 167
Joined: Wed Feb 09, 2005 1:58 pm

Post by Shallow »

Temporarily change the shader to point at a standard texture which comes with the game and definitely does have an alpha channel, e.g. base_floor/cybergrate2.tga

If this doesn't work, there is something wrong with the shader. If it does work there is something wrong with your texture.

(Note that for the purposes of this test, recompiling the map or even opening radiant will be unnecessary.)
Hr.O
Posts: 152
Joined: Wed Jul 12, 2000 7:00 am

Post by Hr.O »

Magnus, could you post the tga (or email), i'm realy curious as to what's happening round here.
Lenard
Posts: 737
Joined: Mon Aug 04, 2003 7:00 am

Post by Lenard »

Yeah, for some reason I am sitting on the edge og my seat. I really want to see this probelm get resolved.
[img]http://myspace-001.vo.llnwd.net/00555/10/05/555355001_l.gif[/img]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

The shader. Everything should be self explanitory, or described in my post above:

Code: Select all

// Test Decal
textures/obsidian_test/decal_blend
{
	polygonOffset
	surfaceparm nonsolid
	surfaceparm nomarks
	surfaceparm trans
	qer_editorImage textures/obsidian_test/blooddragdecal_e.tga
	{
		map textures/obsidian_test/blooddragdecal_d.tga
		blendFunc blend
		rgbGen identity
	}
}
The texture:
Image

The alpha:
Image

The editorImage (make sure it's the same dimensions as the actual texture):
Image

Building it in GtkRadiant:
Image

Placement of decal inside floor. You'll get some z-fighting in the editor but because of polygonOffset, the decal is rendered above the floor by hardware, preventing z-fighting in game.
Image

In game shot
Image
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

Hr.O wrote:Magnus, could you post the tga (or email), i'm realy curious as to what's happening round here.
First I should make it clear that the total immage is actually made up of two seperate immages that are to be fit together to make the L shaped immage. As you can see below.

Image


Other than that here in the .tga and the .jpg.

The .jpg#1
http://users.adelphia.net/~magnus3204/images/blsm1.jpg

Image

The .jpg#2
http://users.adelphia.net/~magnus3204/images/blsm2.jpg

Image

As you can see the .jpg looks nice, clean and sharp.

The .tga#1
http://users.adelphia.net/~magnus3204/images/blsm1.tga

Tha .tga#2
http://users.adelphia.net/~magnus3204/images/blsm2.tga


Just right click the URL above each immage and save target as...for anyone who didn't know.

I wil go test my script on a standard Q3A radiant immage and check the results while you guys look this one over.

Oh, BTW @obsidian, so my shader is ok other than I need to add the polygonOffset above my surfaceparm entries and the engine will interperate the rest for me?

A big thanks to you all for your help and interest.

If any of you want once I get this thing finished you are all welcome to the first copies of my 5 map pack that this map will be a part of.

These maps are intended to be a part of "The Hidden" mod reef myself and a few others are working on.

I already created the Hunter models and the transparent Hunted models as well as a transparant gauntlet. Now I am making 5 custom maps for it, but they will be playable as normal DM, TDM and or Tourney.

We just need to find a coder. I just am not experienced enough as a coder to do it myself.

Anyway I'll be back later.

Thanks again everyone.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

OK I tried useing my shader on the cybergrate2.tga texture and instead of the alpha areas looking transparent it looed black, but the strange thing is the other parts of the texture looked as they should clean and clear not smudged and spread beyond their intended bounds like mt texture.

Looks like my script and my texture are at fault.

So there are the results of that.
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

Well, no wonder why the texture is bleeding (ahem, excuse the pun) off the edges... your alpha-channel is bleeding off the edges. As mentioned by Hr.O, you need to stay well within the boarders.

Second of all, I just noticed, that none of the screenshots you posted shows an actual working blendFunc. All areas are opaque. According to your alpha-channel, at least some parts of those white bits are supposed to be transparent. This leads me to think that you have something wrong with the file paths or file overwriting issues.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

(Hopefully) Foolproof test:

In all the following steps, note the case sensitivity!

1) Use this shader... copy it to a new text file, name it magnus_decals.shader

Code: Select all

// Blood Smear Decal
textures/magnus_decals/blsm1
{
   polygonOffset
   surfaceparm nonsolid
   surfaceparm nomarks
   surfaceparm trans
   qer_editorImage textures/magnus_decals/blsm1.tga
   {
      map textures/magnus_decals/blsm1.tga
      blendFunc blend
      rgbGen identity
   }
}
2) Add "magnus_decals" to your shaderlist.txt

3) In your textures directory, create a new folder named "magnus_decals".

4) Move blsm1.tga inside the new folder.

5) Open GtkRadiant and your map, retexture the decal face with the newly created shader. You should see a new shader listing in textures > magnus_decals.

6) Recompile your map and load it in Q3.



This should solve the problem with the shader not working. You'll likely need to edit the alpha-channel afterwards to prevent bleeding off the edges, but you can worry about that after.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

Magnus wrote:Is it possible that even though the areas outside of the immage look totaly alpha in photoshop there is actually still some very faint color there that is being enhanced when I apply the texture in radiant and ingame?

As you can see I kinda wondered if that might be the problem with the texture part.

I'll go back in and adjust the alpha so I can see the more faint portions of the color in the immage and the erase them well.
Then reset the alpha to it's origonal settings and then save the immage. That should take care of the "bleeding" of the colors, Then I'll follow your instructions and come back with the end result, but all of that will have to be tomorrow as it is 2:31 a.m. here now and I have to be up at 5:30a.m. to get my girls off to school.

Thanks to you all and I will return tomorrow with any new info.

Later. :icon17:
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Hr.O
Posts: 152
Joined: Wed Jul 12, 2000 7:00 am

Post by Hr.O »

Welps, sorry, i managed to delete my post last night...(blame it on the beerzz)
a few things,
1) i Don't recommend using white as a background colour, rather use black. Even if there's still some bleeding, a mediation between red and black is less visible then a mediation between white and red
2) keep alphachan well within texture bounds
3) as obsidian mentioned, your shader doesn't look like any decal i use. i suggest using obsidian's
obsidian
Posts: 10970
Joined: Mon Feb 04, 2002 8:00 am

Post by obsidian »

Hr.O wrote:i Don't recommend using white as a background colour, rather use black. Even if there's still some bleeding, a mediation between red and black is less visible then a mediation between white and red
Better yet, just paint the whole thing red, like my example above.
[size=85][url=http://gtkradiant.com]GtkRadiant[/url] | [url=http://q3map2.robotrenegade.com]Q3Map2[/url] | [url=http://q3map2.robotrenegade.com/docs/shader_manual/]Shader Manual[/url][/size]
Magnus
Posts: 529
Joined: Wed Feb 16, 2005 6:38 pm

Post by Magnus »

I found something that might be part of the problem other than the obvios problem with my shader script.

If you know what I am talking about follow me here.

You know when you open an immage there is a option in the toolbar "Layers" if you open layers you have several options in this menu. Adjust hue, saturation, color balance, lithograph adjust with RGB and Alpha, and curves as well as a few others.

Well if you go to curves adjustments in x on the grid controls the lightness or darkness and y on the grid controls the saturation.

If I take my .tga into the curves adjustment and pull the line all the way into the upper left hand corner suddenly the immage look exacly the same as it does in Radiant and ingame.

So it appears when I save my immage as a .tga it is pumping up the darkness and the saturation wich is exposing areas of color that are very faint in photoshop as fully visible in Radiant and ingame.

Does This give anyone any clues as to a known problem?

I will as you guys suggest use black instead of white.

I noticed that all of the default textures in Q3A that have shader scripts but no alpha use black as background instead of white.

I will also try making the texture totally covered in the bloody look as obsidian said and make a black cover with an alpha channel for the bloody smear to appear through.

I want to try all versions of how to do this so I have the added experience for future projects and so I can pass along what I learn from you guys.

I'll be back in a bit.

Thanks for sticking with me here! :icon25:
Uh, well....good luck with that. :shrug:

[img]http://i57.photobucket.com/albums/g228/Magnus3204/forumheader.jpg[/img]
Post Reply