Engine level normal map support

Engine level normal map support

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Engine level normal map support

Post by Beherith »

So, after much hand wringing, I decided to try implementing engine-level normal map support. This includes the following:
  • Bump maps on features
    Bump maps on units with no lua unit shaders overhead (in my experience, the overhead there is massive, nearly 50% less fps when many (100+) units are on screen
    Bump maps for units under construction
It was surprisingly easy to do in a hacky way, but there are a few caveats that should be discussed.

1. Where to store the normal map/unit assignments?
Currently, i hard coded to load a texture that is called the same as texture1 (e.g. Arm1.dds -> Arm1_normal.dds)

Code: Select all

		
S3DModel* CS3OParser::Load(const std::string& name)
...
model->tex3 = (char*) &fileBuf[header.texture1];
model->tex3 = model->tex3.insert( model->tex3.find_last_of("."), "_normal"); //horrible hacks by beherith
...
Since adding a third texture to the s3o format seems very complex, and defining it elsewhere is difficult to get the right balance of simplicity/configurability.
I figured that normal maps are nearly 100% tied to the diffuse texture1, this would be an 'ok', if hackish solution.

Also, if a normal map cannot be loaded, this allocates a single pixel dummy normal map. Which brings me to my next point

2. Texture caching.

I did a horrible hack to change the 'hash' function:
from
#define TEX_MAT_UID(pTxID, sTxID) ((boost::uint64_t(pTxID) << 32u) | boost::uint64_t(sTxID))

to:
#define TEX_MAT_UID(pTxID, sTxID, tTxID) ((boost::uint64_t(pTxID) << 32u) | (boost::uint64_t(sTxID) << 16u ) | tTxID))

As I saw that texID's seem to be small values, incrementally assigned, and the chance of a collision seemed very low.

Just a screenshot of features and units having engine-level normal maps:
screen00066.jpg
(1.07 MiB) Downloaded 2 times
Any thoughts are welcome
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Engine level normal map support

Post by gajop »

Needs a comparison screenshot. I think I can see the effect in the tires and the blue parts of the robot but it's not super obvious.
Also good for separating it from S30. Any reason it couldn't be used for assimp too? Seems fairly obvious.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Engine level normal map support

Post by Beherith »

Vanilla:

Image

Engine normals:

Image

Keep in mind that the normals on the wreck and the tree were just button mashed quick generated with nvidia photoshop plugin.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Engine level normal map support

Post by smoth »

Not bad behe!
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Engine level normal map support

Post by Silentwings »

Can't see the difference on the unit, but the wreck looks great.
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Engine level normal map support

Post by PicassoCT »

Dat ground

Image

Makes me sad panda for knowing that this is too much work for a one man project.
Allready have to redo the gui.

:(

If spring had bump generatinon as a graphics option..
https://github.com/kmkolasinski/AwesomeBump
but then still ..
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: Engine level normal map support

Post by gajop »

While the effect is more obvious on the feature, the feature itself is weird with some texture seams in the original and the final is random so it's hard to tell what's desired.
The unit feels much "sharper" which is probably one of the desired effects so +1

PS: I realize I have great difficulty telling whether normal maps are being used or not.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Engine level normal map support

Post by smoth »

it's probably that in in 0ad they have translucency support and we do not. that causes what appears to be "seams" if you are talking about the yellowish edge on the leaves.
Super Mario
Posts: 823
Joined: 21 Oct 2008, 02:54

Re: Engine level normal map support

Post by Super Mario »

Can you write an actual function equivalent to the #define by expanding it, to make sure that the compiler catches any bugs? I remember a certain bug, that prevents msvc compiler support.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Engine level normal map support

Post by Beherith »

PicassoCT wrote:Dat ground

Makes me sad panda for knowing that this is too much work for a one man project.
Allready have to redo the gui.

:(

If spring had bump generatinon as a graphics option..
https://github.com/kmkolasinski/AwesomeBump
but then still ..
I knew you would notice the crystals, Picasso :D (the secret is that terrain is also bump mapped now :O )

Also, super thanks for the awesomebump tip, it is a very powerful free and open source bump map creator.

Screenie:
Image
User avatar
PicassoCT
Journeywar Developer & Mapper
Posts: 10450
Joined: 24 Jan 2006, 21:12

Re: Engine level normal map support

Post by PicassoCT »

okay fuck all reason i need to have this
User avatar
code_man
Posts: 260
Joined: 19 Jan 2014, 13:10

Re: Engine level normal map support

Post by code_man »

Very nice, i sure hope this will be in the engine.

Spring is a great engine, but it fell behind over the years i fell.
Even zero hour has bloom and bumpmaps hacked into it nowadays.
Im not one of these people who get a hardon for gfx, but i sure wouldnt mind a bit more shiny stuff, im sure many would like that too.
Would be nice if we get a bit of bloom in the future too.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Engine level normal map support

Post by smoth »

very cool behe! I also didn't realize people liked my distillery
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Engine level normal map support

Post by Silentwings »

Would be great to get this into the engine...

For 1, I guess filename in unitdef file and a normals dir in the base game dir.
User avatar
Beherith
Posts: 5145
Joined: 26 Oct 2007, 16:21

Re: Engine level normal map support

Post by Beherith »

Well, since it's not limited to units, and works on features and projectiles too, adding it to definitions is a tad iffy.

I cant think of a reason besides code cleanliness to not load them with the models themselves.

Oh and btw, it costs nearly 0 performance :)
User avatar
FLOZi
MC: Legacy & Spring 1944 Developer
Posts: 6240
Joined: 29 Apr 2005, 01:14

Re: Engine level normal map support

Post by FLOZi »

Beherith wrote:Well, since it's not limited to units, and works on features and projectiles too, adding it to definitions is a tad iffy.
I don't see how, don't they all inherit from WorldObject? That's where model is. Or am I not following you? :(
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Engine level normal map support

Post by Silentwings »

Features can have defs too - https://springrts.com/wiki/Gamedev:FeatureDefs - but projectiles (afaik) don't, the models used are just identified in the weapondefs by filename.
Kloot
Spring Developer
Posts: 1867
Joined: 08 Oct 2006, 16:58

Re: Engine level normal map support

Post by Kloot »

Quick opinion:

Normal-mapping on the engine side is trivial, but would mostly be limited to games that don't employ custom shaders at all or only for NM. On the other hand the default shaders could be made to support a wider range of standard bling with not too much work, and cover most of the custom cases. Just having mapped normals on props isn't enough of a draw.

Normal-map generation really belongs in an artist pipeline, not the engine.
User avatar
smoth
Posts: 22309
Joined: 13 Jan 2005, 00:46

Re: Engine level normal map support

Post by smoth »

Shaders cannot be assigned to features.
User avatar
Silentwings
Posts: 3720
Joined: 25 Oct 2008, 00:23

Re: Engine level normal map support

Post by Silentwings »

Kloot wrote:Normal-map generation really belongs in an artist pipeline, not the engine.
I'm confused by this - I thought that was what going in Behe's code was that the generation of normals was getting done by the artist alongside making the model, and its the rendering based on the normals that's being done inside the engine. Are you saying that ideally all non-basic rendering should be done, by the artist, in a (lua) shader?
Post Reply

Return to “Engine”