Previous Blog Next Blog
Prev/Next Blog
by date

TGE Detail maps (let's fix it)

TGE Detail maps (let's fix it)
Name:Apparatus
Date Posted:Jun 22, 2008
Rating:4.3 out of 5
Public:YES
Comments:YES
RSS Feed:GarageGames Blog feedor Subscribe with .
Profile Page:View profile page for Apparatus

Blog post
I know detail map code is in there, Milkshape exporter has (had?) it, Lightwave exporter has it (complete with detail scale), 3dsMax (version 8 tested) exporter has it if you add the detail texture in the Ambient slot of the material. Yet in Torque no detail maps show up..

I recon it is not so important for many people but sometimes it really makes the difference; In TGE a small / medium object with a proper diffuse map could look great; in TGEA the fancy normal mapping and specular make indeed wonders. What if you run into a problem when you really could use a good ol' trick?

I was making these huge mountain bits and since the textures are relatively perfect for the job one may think it was enough. Well, it isn't : ) TGE recommends a maximum resolution of 512x512. On current hardware, 1024x1024 can be used here an there with no problem at all. I can't say about TGEA cause I don't have it / never looked into the issue.

The following example has a good 1024x1024 texture estate (with a bit of repeating as well) and should provide enough detail and it does, as looking at it from a distance ; On a close up however, we got ourselves a huge chunk of the screen covered with this dull blurred texture. And we really need some detail there since the player is about 2 m high (and that's about half the square zoomed region).

no detailmap whatsoever:


with detail map - the same texture cause I haven't bothered to create one so you get dirty spots and a bit of saturation from it:



Since this is looking right in ShowToolPro, the question is why it doesn't show up in TGE (1.4 and up)? I am willing to provide assistance to whomever is good at this and maybe we can fix this and release it to the community.

Also, the guy who can fix this in a quick manner will get a free bundle (2 packs: Bridge Pack and TGE Mountain - or environment pack as I call it for the moment);

Post here your ideas or write me an email if you're interested. Thanks!

Recent Blog Posts
List:12/10/08 - Textures Pack Down
12/09/08 - Materials Bazaar ~ Metals Library release
12/07/08 - Materials Bazaar (II) update
12/03/08 - Materials Bazaar (I)
12/03/08 - TGEA Environment Guide
11/04/08 - Kork 2.0, halted work
09/24/08 - Constructor Pipeline (I)
09/23/08 - Interior Guide Pack Free Download

Submit ResourceSubmit your own resources!

Nathan Kent   (Jun 22, 2008 at 00:49 GMT)
Question: What cool things aren't you doing?

Morrock   (Jun 22, 2008 at 00:52 GMT)
I'd be willing to help with this. I doubt I could be the one to solve it (unless I get very lucky) because I don't know much about graphics programming, but I'll help and look around. Unfortunately, all the areas of code that would deal with this are ones I haven't even studied.

Just did a quick search for a few things in the source, maybe some of these could give you a lead?

In dgl/gTexManager.cc
U32 sgTextureDetailLevel = 0;

In sceneGraph/detailManager.cc
Line 125-158 are commented out, these seem to have quite a bit to do with bumping.

Apparatus   (Jun 22, 2008 at 01:06 GMT)   Resource Rating: 5
@Nathan - dunno, I don't drink? :)

@Morrock - I am positive bump mapping was left out long ago, people have tried it before; I will send you a test model right away, with and without detail info. I will also install a compiler myself and check it out (so we only exchange info not builds); thanks a lot.
Edited on Jun 22, 2008 01:06 GMT

Koushik   (Jun 22, 2008 at 02:16 GMT)
@Morrock: The sgTextureDetailLevel variable deals with mipmap levels inside openGL. In fact, you can also find a console function setOpenGLMipReduction as well which deals with this.

@Apparatus: I think the problem might be in the way the texture units are set-up, don't know for sure though. I will take a look at it when I get back to my comp.
And yeah, bump-mapping was removed from the engine a long time ago, but there are still hooks in the code.

If you want normal-mapping with TGE, you might want to first get the modernization kit, and then my fix for DTS shaders Here
Edited on Jun 22, 2008 02:21 GMT

Craig Fortune   (Jun 22, 2008 at 02:57 GMT)
Apparatus: I agree, TGE is often missing stuff you expect to be working etc. That second shot in TSTP looks v nice.

Morrock: Have another look at the code in detailManager.cc you referred to and you'll see that its to do with bumping between detail levels in a more figurative sense.

Apparatus   (Jun 22, 2008 at 03:46 GMT)   Resource Rating: 5
Morrock pointed out that ts/tsShapeInstance.cc may have to deal with detail maps so I went there, lurked for a while and changed


mMaxDetailMapDL = -1;


to


mMaxDetailMapDL = 1;


I have absolutely no idea what I actually did, if it's a hack or simply the solution to my problem. It works though, with a few notes:

1. Greyscale textures must comply with TLK instructions or you will get weird lighting on the detail mapped object;
2. Detail texture must be the same size - i'll test more on this later


No detail map:



With detail map:




At this point I need to work on the textures a bit more but it's there.
Edited on Jun 22, 2008 03:47 GMT

Joseph Greenawalt   (Jun 22, 2008 at 04:20 GMT)
@Apparatus:

Detail maps exported from Blender work fine in TGE 1.52 without any code changes.

(screenshot from stock TGE 1.52)

Here's a dts file that uses detail maps and works in (stock) TGE: jsgreenawalt.com/Downloads/Blender/TestModels/Material_test2.zip

TGEA still does not support detail maps last time I checked. Does your TGE code change fix the clamp/wrap issues that appear when exporting a scaled detail map?

Apparatus   (Jun 22, 2008 at 04:36 GMT)   Resource Rating: 5
@Joseph - I was hoping for a solution that requires no code change. The clamp issues disappear if I use a detail texture the same size with the color texture w is fine since I can tile the detail. Without code change it showed up just fine in ShowToolPro but but not in the engine; I will test some more tonight.

Joseph Greenawalt   (Jun 22, 2008 at 04:53 GMT)
An exporter side fix should be possible.

When you say that you can tile the detail, do you mean that you can tile it at a different interval than the diffuse texture? If so, I'd love to get my hands on a model that shows it working (just a simple cube would do :-). If you want to post or email me such a model I'd be glad to help out with trying to find the difference between the max and blender detail maps, which should hopefully lead to an exporter-side fix for the problem that you're having :-)

Joseph Greenawalt   (Jun 22, 2008 at 06:01 GMT)
The loop immediately below the "mMaxDetailMapDL = -1;" line should be scanning through each primitive of every mesh in every detail level looking for primitives with a material that has a detail map assigned. When it finds one, it should change the mMaxDetailMapDL value to match the detail level that the material was found in. Hardcoding the value to 1 looks to be tricking the engine into thinking that it's found a detail map in one of the materials of the first detail level (and second?, DL numbers should start with 0, I think), which it should be finding anyway. It seems almost certain that whatever is going wrong is happening in one of the tests in that loop.

Apparatus   (Jun 22, 2008 at 06:33 GMT)   Resource Rating: 5
Joseph, the model above have the detail tiled 4 times; -4 actually, smaller than the diffuse texture. I will email it to you in a bit. And you are saying that the exporter is the problem and I should not hardcode nMaxDetailMapDL?

Joseph Greenawalt   (Jun 22, 2008 at 06:43 GMT)
Gah, that's the second time tonight that the forum has eaten a long post that I've typed up. I've got to start typing these things in notepad first :-)

The shortened version:
Yeah, I do think that an exporter fix is possible, and probably preferable to hardcoding nMaxDetailMapDL. But it really depends on the exact nature of the problem. I'll take a look at the model you sent and see if I can figure out what's going on.

Joseph Greenawalt   (Jun 22, 2008 at 08:33 GMT)
OK, the loop that I was talking about is actually working fine and does find the detail map for your shape in detail level 0, as it should. It looks like the difference comes down to the intraDL value, which is causing one of two codepaths to be used for rendering the detail maps. One of these code paths works, and the other does not. I'm still tracing through the maze of selectCurrentDetailXX methods (seems there are about 12 of them, what a mess). At this point I'd say that it's the second detail map rendering method that needs to be fixed and not the max exporter. I'll post my findings in the private forums once I'm finished and have had time to write them up.

edit - also it looks like the differences between the two detail map rendering procedures may account for the clamp/wrap problem in the code path that Blender exported models are using.
Edited on Jun 22, 2008 08:42 GMT

Apparatus   (Jun 22, 2008 at 09:39 GMT)   Resource Rating: 5
This is a great leap forward, thanks Joseph. May have to hurry up and complete the (tge mountain) pack so you can enjoy the little prize :)

Leslie Young   (Jun 22, 2008 at 11:59 GMT)
In showtool it only shows the detail if you Detail Levels dialog select "controlled by slider", else it won't render it either.

In tsShapeInstance.cc I changed
mMaxDetailMapDL = dl; to mMaxDetailMapDL = dl+1; (which causes 0 to be 1, and the rest +1 from there if you got detail map on other detail levels)
It must be ignoring or following a different codepath as Joseph said when mMaxDetailMapDL is 0.

Joseph Greenawalt   (Jun 22, 2008 at 12:01 GMT)
Here's what I've got so far:
www.garagegames.com/mg/forums/result.thread.php?qt=76451

Morrock   (Jun 22, 2008 at 16:48 GMT)
I think I got it, um yay?!
I added the following code to the S32 TSShapeInstance::selectCurrentDetailEx(F32 errorTOL) function, right at the beginning after the description comment.


if (mShape->mSmallestVisibleDL == 0)
{
// get here if we are drawing at DL==0
mCurrentDetailLevel = 0;
mCurrentIntraDetailLevel = 1.0f;
return mCurrentDetailLevel;
}


It has the detail texture and doesn't "pop" when loading into a different LOD.

edit: I left out the return value from this, fixed it. Sorry for the mix-up Joseph :/
Edited on Jun 22, 2008 23:55 GMT

Morrock   (Jun 22, 2008 at 16:54 GMT)
I've tried it both with and without Joseph's addition he posted in the forum thread and can't see any difference, I'm going to try and see if it's needed. Oh, and now screenshots. Ignore the massive shadow in the ground. I forgot to relight the scene after adding/removing certain items.






edit: Alright, never posted images in comments here before... I tired BBC, HTML, I give up, how do I do it.
Never mind. Thanks silentMike.
Edited on Jun 22, 2008 17:42 GMT

Michael (silentMike) Hall   (Jun 22, 2008 at 17:20 GMT)
I swear that boulder has got to the be the "real-est" looking rock I've seen in a game that wasn't using shaders. It's great to see an artist showing that you don't need fancy hardware and rendering techniques to make something look good.

Bridges, mountains, rainbows, waterfalls, rivers, and trees oh my! What else have you got hidden up your sleaves to show off in your environment pack?

@Morrock: BBC uses [ img ] for images, on here you gotta use the word image.

edit: hung-over Sunday morning spelling ;)
edit: removed image - no problem Morrock!
Edited on Jun 22, 2008 18:42 GMT

Apparatus   (Jun 22, 2008 at 19:23 GMT)   Resource Rating: 5
Started a new entry here - please refer to it with all the code changes needed so that everyone can take advantage of it.

Oh, and thanks everyone! I am collecting email addresses and sending over the link for download right now.
Edited on Jun 22, 2008 19:24 GMT

Joseph Greenawalt   (Jun 22, 2008 at 23:11 GMT)
@Morrock:
Hardcoding mCurrentIntraDetailLevel to 1.0 for the last DL does cause the detail maps to be drawn, but they don't fade out as the distance from the camera increases. That's one of the solutions that I considered. Perhaps the lack of fading isn't important, and hardcoding mCurrentIntraDetailLevel to 1.0 for the last DL does prevent the "popping" issue that I mentioned in the thread. I'm not sure why you're not seeing any difference with my suggested change though... I am seeing a difference here using the model that Apparatus sent me. I took a version with detail map and without and set them right against each other and the difference was pretty obvious (here at least :-)

Morrock   (Jun 22, 2008 at 23:58 GMT)
Whoops, may have been bad phrasing. I was kind of rushed at the time. What I meant to say is, my code implemented both with and without your code didn't seem to make much difference on the object. I was thinking maybe some objects that had a smallestVisibleDL !=0 may have had a difference with your code fix. Your code does cause a big difference from stock TGE 1.5.2, but I meant in combination with my effort.

Joseph Greenawalt   (Jun 23, 2008 at 00:04 GMT)
Ah, gottach :-) Yeah, I was worried there for a minute that there may have been yet another path through the code that I wasn't seeing with the test model that I've got. All of those selectCurrentDLNew2Newer3Ex(random argument list) methods were starting to make my head spin ;-)

You must be a member and be logged in to either append comments or rate this resource.