www.tombraiderforums.com  

Go Back   www.tombraiderforums.com > Tomb Raider Modding > Tomb Raider Level Editor > Software Development

Reply
 
Thread Tools
Old 04-01-13, 01:40   #1
Lwmte
Archaeologist
 
Lwmte's Avatar
 
Join Date: Aug 2010
Posts: 1,129
Default 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!

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.

Last edited by Lwmte; 18-01-13 at 17:27.
Lwmte is offline   Reply With Quote
Old 04-01-13, 03:17   #2
Turbo Pascal
Student
 
Join Date: Jan 2004
Location: Central America
Posts: 111
Default

Quote:
...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:

http://www.evpopov.com/perso/dl/TRSt...ileFormat.html


Quote:
/*
* 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?,


Tp.

Last edited by Turbo Pascal; 04-01-13 at 03:24.
Turbo Pascal is offline   Reply With Quote
Old 04-01-13, 07:44   #3
Lwmte
Archaeologist
 
Lwmte's Avatar
 
Join Date: Aug 2010
Posts: 1,129
Default

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

Quote:
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... It may be easier to write wrapper renderer from scratch!
Quote:
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... Anyway, I'll PM you soon!
Lwmte is offline   Reply With Quote
Old 04-01-13, 09:24   #4
Joey79100
Professor
 
Joey79100's Avatar
 
Join Date: Mar 2012
Location: France
Posts: 3,074
Default

Quote:
Originally Posted by Lwmte View Post
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.
__________________
"sdfgisdgdsfgdsfgdsgfsdgsgfdgsfgdsf" ~ SrDanielPonces
Joey79100 is offline   Reply With Quote
Old 04-01-13, 10:00   #5
Lwmte
Archaeologist
 
Lwmte's Avatar
 
Join Date: Aug 2010
Posts: 1,129
Default

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
Lwmte is offline   Reply With Quote
Old 04-01-13, 10:01   #6
HeinzFritz
Explorer
 
Join Date: Feb 2006
Posts: 526
Default

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
Omnipresence=1
Name=EXPANDING HEAD
Description=LENGTH 1 = LENGTH 2 (1F double 30 triple)//STRETCH SPEED 1 (max FF)//STRETCH SPEED 2 (max 3F)//RETRACTION SPEED (lower-inverses direction)

RequiresRemap=0
RequiresYiff=0
RequiresPart=0
RequiresSave=0
Dependencies=
CondBehave=0

bambi=0|1
ronno=0|FBF6
gprince=0|10
faline=0|LENGTH 1
mena=0|0
bambi=1|1
ronno=1|FC10
gprince=1|10
faline=1|LENGTH 2
mena=1|0
bambi=2|1
ronno=2|FC15
gprince=2|D2
faline=2|TIMER fine tuning
mena=2|0
bambi=3|1
ronno=3|FC16
gprince=3|00
faline=3|TIMER coarse tuning
mena=3|0
bambi=4|1
ronno=4|FBFA
gprince=4|80
faline=4|STRETCH SPEED 1
mena=4|0
bambi=5|1
ronno=5|FBFB
gprince=5|00
faline=5|STRETCH SPEED 2
mena=5|0
bambi=6|1
ronno=6|FC37
gprince=6|80
faline=6|RETRACTION SPEED
mena=6|0
/end 001

Last edited by HeinzFritz; 04-01-13 at 10:26.
HeinzFritz is offline   Reply With Quote
Old 04-01-13, 10:20   #7
Titak
Moderator
 
Titak's Avatar
 
Join Date: Jul 2003
Location: Drenthe, The Netherlands
Posts: 32,557
Default

Quote:
Originally Posted by Lwmte View Post
I want to make it compatible with TRNG, not only TREP.
Music to my ears!

Great stuff you have going on there, Lwmte!

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.
__________________
If it walks like a duck and if it quacks like a duck, it is a duck.
Titak is offline   Reply With Quote
Old 04-01-13, 10:30   #8
Lwmte
Archaeologist
 
Lwmte's Avatar
 
Join Date: Aug 2010
Posts: 1,129
Default

@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! 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"!

Last edited by Lwmte; 04-01-13 at 10:35.
Lwmte is offline   Reply With Quote
Old 04-01-13, 10:38   #9
KurtisandLara
Golden
 
KurtisandLara's Avatar
 
Join Date: Oct 2008
Location: Nebraska, USA
Posts: 5,090
Default

@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!
__________________
Pull the lever kronk!
KurtisandLara is offline   Reply With Quote
Old 04-01-13, 11:35   #10
Boobandie
Professor
 
Join Date: Jul 2012
Posts: 3,912
Default

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.
Boobandie is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



All times are GMT. The time now is 09:30.


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