www.tombraiderforums.com (https://www.tombraiderforums.com/index.php)
-   Software Development (https://www.tombraiderforums.com/forumdisplay.php?f=55)
-   -   Decomposing TR4 renderer... (https://www.tombraiderforums.com/showthread.php?t=196254)

Lwmte 04-01-13 01:40

Decomposing TR4 renderer...
Hi again! :)
During these new year long weekends, I have decided to return to something I have never accomplished back in early TREP days - decomposing TR4 renderer to bits. It's a hard one, because TR4 engine used DirectX 6 API, and it is hard to find proper D3D6 documentation these days.

Any TRLE builder knows that TR4 engine, unfortunately, lacks any blending modes except simple "Add" operation. Simply said, you can't have black smoke and shadows, muddy dark water, gray fog, semi-transparent realistic dark sprites, and so on, because any "translucent" surface in TR4 engine results in increased brightness of combined textures. Fortunately, DirectX allows to use almost any blending operations (inversion by colour or alpha values, colour combining, etc.), but these were never used in TR3-TR5 engine for general purpose.

Most logical and wiseful thing to do is to add these missing blending modes to TR4 engine - it is very easy, but the question is how it will be used in levels. Paolone may come up with scripting ideas (like he already did with static mesh transparency assigned via script), but I think that the best way is to assign it directly to textures. Is there some "unused" field in TR4 file format that can be used for this extra blending mode info? Right now, I have no idea - maybe experienced guys like meta2tr or sapper have some ideas? :)

Here are the screenies! :D

This is example from meta2tr demo level, two alternate blending modes: darken and screen:

By default, it looks like this:

New, really really smooth shadow, black water textures and darkened clear menu backgrounds.
http://trep.trlevel.de/temp/t-new-shadow.jpg http://trep.trlevel.de/temp/t-shadow.jpg http://trep.trlevel.de/temp/t-darkened-backgrnd.jpg http://trep.trlevel.de/temp/t-renderer-negative.jpg

Turbo Pascal 04-01-13 03:17


...Is there some "unused" field in TR4 file format that can be used for this extra blending mode info? Right now, I have no idea - maybe experienced guys like meta2tr or sapper have some ideas? :)
Hi Ensi, glad to see you have again time and curiosity to play again with the tr engine.

I am a litle rusty about the TR file format, but i think that maybe you can use the "attribute" field in the texture table.

Every rectangle/triangle used for room geometry, movables, static mesh objects, have a index that point to the general texture table array, every entry in this table defines the texture page and the UV map and also includes a 16 bits field (0-64536) called attribute, wich currently is used (if i remember well) as:

Value 0 (bit 0 off) = texture is applied in Opaque way.
Value 1 (bit 0 ON) = Texture is applied transparent for all magenta color pixels.
Value 2 (bit 1 On) = Texture is applied using Alpha Blend, additive operation.

So, i think you have 14 bits available to implement all kind textures effects you want.

More info about the tr4 file format:



* Object texture structure.
* These, thee contents of ObjectTextures[], are used for specifying texture
* mapping for the world geometry and for mesh objects.
typedef struct { // 20 bytes
bitu16 Attribute; // 0 means that a texture is all-opaque, and that transparency
// information is ignored.
// 1 means that transparency information is used. In 8-bit colour,
// index 0 is the transparent colour, while in 16-bit colour, the
// top bit (0x8000) is the alpha channel (1 = opaque, 0 = transparent).
// 2 (only in TR3) means that the opacity (alpha) is equal to the intensity;
// the brighter the colour, the more opaque it is. The intensity is probably calculated
// as the maximum of the individual color values.
bitu16 Tile; // index into textile list
tr2_object_texture_vert Vertices[4]; // the four corners of the texture
} tr2_object_texture;

The things is, now what tool can you use to setup those values in the attibute field so you can do your test?; any idea?,


Lwmte 04-01-13 07:44

Wow! Hi there, Turbo! Long time no see! :eek: How everything's going? ;)


So, i think you have 14 bits available to implement all kind textures effects you want.
That's exactly what I need, thank you very much! 14 bits is more than enough, maybe we can implement some other texture effects, like multipass texturing or real bump-mapping, I have no idea yet, if it is actual at all, regarding catastrophically low TR4 rendering speed... :hea: It may be easier to write wrapper renderer from scratch! :D

The things is, now what tool can you use to setup those values in the attibute field so you can do your test?; any idea?,
I don't know yet, but regarding meta2tr, this program hugely evolved since the last time I used it, last version even allows you to edit room collision! It is even compatible with Dxtre3d, because it also works with compiled level file. I suppose, if we will come to a common solution, it can be implemented into it. But that's just one idea; moreover, maybe NGLE already used extra texture parameters for its internal purposes, because I remember that it used "cold" room flag instead of "reverb" flag, which was unused in PC version of TR4. It is critical, because if it'll go that way, I want to make it compatible with TRNG, not only TREP.

Speaking of which, the way TR4 renders scene is very strange. Remember when you tried to sort scene by face type (i. e. opaque, transparent, translucent, etc.)? TR4 not only sorts them by type, but also it renders opaque faces in 3 different subroutines! I have no idea why they done it this way (maybe it's related to face orientation?), because it results in strange rendering artifacts (for example, classic TRx engine clipping bug, when you can see some overlapping faces cyclically appear and disappear).

As for transparent/translucent faces, it seems more logical. Engine has 8 different subtypes of transparent faces, of which only one natively uses pseudo-alpha transparency. This type globally used for almost every particle effect, for shiny effect and for translucent room/object/static meshes. Each subtype gets its own DrawPrimitive call and set of SetRenderState calls, etc., so basically it is done in the same way as in your engine. Only thing that I'm still digging into is sorting procedure.

By the way, have you solved sorting slowdowns in your engine? What's new, generally? ;) I've read somewhere that you've rewrote some parts of renderer with HLSL... :eek: Anyway, I'll PM you soon! ;)

Joey79100 04-01-13 09:24


Originally Posted by Lwmte (Post 6589462)
I remember that it used "cold" room flag instead of "reverb" flag, which was unused in PC version of TR4.

That's wrong. It doesn't work with many computers but I know I already made it to work on an old computer (with W98).
But I don't know what audio card I had, I have to put my hands on this computer to tell you.

Lwmte 04-01-13 10:00

No, I didn't mean that it got replaced, I mean that this flag was left in TR4 file format, but it has no use in PC version; there is no sample post-processing... Yet :D

HeinzFritz 04-01-13 10:01

If I have ever seen a good direction to continue working, then it is this idea of decomposing the TR4 renderer.

Probably you know it already but, just in case, I will point to two types of transparency that the engine uses as both have been neglected so far.

1. First of all the most rudimentary transparency used with BINOCULARS (just intensity of transparency related to the BINOCULAR GRAPHIC moveable, where the lighter the texture color the more transparent it gets. The color of the transparency can not be changed this way).

2. The smooth increase/decrease of the darkening type of transparency associated with the GODS HEAD object, which starts from opaque and with the retraction of the object gets more and more transparent until it gets completely clear. I have tested it by building an object and to putting it in the GOD HEAD slot, fine tuned by FE the transparency (with the MOVE_BYTE command in TREP Flip effect editor) and tested it as a curtain. This kind of transparency supports color but all sprites or alpha transparent faces behind it are invisible.

For those who want to play with the second effect, here is the DRACO PATCH:

/bgn 001
Description=LENGTH 1 = LENGTH 2 (1F double 30 triple)//STRETCH SPEED 1 (max FF)//STRETCH SPEED 2 (max 3F)//RETRACTION SPEED (lower-inverses direction)


faline=0|LENGTH 1
faline=1|LENGTH 2
faline=2|TIMER fine tuning
faline=3|TIMER coarse tuning
faline=4|STRETCH SPEED 1
faline=5|STRETCH SPEED 2
/end 001

Titak 04-01-13 10:20


Originally Posted by Lwmte (Post 6589462)
I want to make it compatible with TRNG, not only TREP.

Music to my ears! :D

Great stuff you have going on there, Lwmte! :jmp:

I wonder if it would be possible to get in contact with Paolone.
No idea if he'll ever resurface but people might be allowed to take over and make their own changes to TRNG.

Lwmte 04-01-13 10:30

@Heinz: Yes, I almost broke my head back these years trying to understand how BINOCULAR_GRAPHICS works with "darken" translucency, because smooth shadow from TR4 beta demo used same face subtype! :hea: But actually it is pretty simple. Edge binocular graphics polygons have continous black-to-white gradient (not sure if it's done by coloring vertices or by 1x2 black-white texture), which internally converts to semi-transparent gradient. It has no practical use, as you noticed it only contains "intensity" value, not depending on colour.

God head uses same transparency routine as look transparency and vanishing enemy. I suppose, Paolone's transparent statics feature uses it too; you're right - unfortunately, it discards alpha tests behind itself. I'll check out if it's possible to fix or not.

@Titak: Hi! :) Right now I'm in the process of "developer hell", trying to simultaneously create new universal patcher for both TRNG and standard tomb4.exe based on classic TREP source code and also maintain backwards compatibility with classic TREP; I'm not sure how it will turn out - as Turbo Pascal says, "stay tuned"! ;)

KurtisandLara 04-01-13 10:38

@titak: One thing I thought about if people started mAking updates for trng is, say there's multiple people each coming out with their own content, who's to say they are all compatible with one another? Since its not paolone. That's always been my concern.
Loving this work so far lwmte, I can't even fathom how you people do this lol! Good job!

Boobandie 04-01-13 11:35

Just seeing as you are working with the TR4 code, any chance you can get some of the PS1 effects like footprints on sand/dirt/gravel/snow/mud to work?

Dreamcast shadows would also be FANTASTIC.

We already have bump mapping in the TRLE, which overlays an automatically generated grey version of the texture over the actual thing. Once again, just pointing stuff out you probably know to make sure you know it.

All times are GMT. The time now is 08:59.

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2020, vBulletin Solutions Inc.