New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parallax mapping #30

Open
illwieckz opened this Issue Sep 9, 2017 · 12 comments

Comments

4 participants
@illwieckz
Copy link
Member

illwieckz commented Sep 9, 2017

I noticed yesterday that XreaL had working parallax mapping, I know Darkplaces (used by Xonotic) has it too. What's missing to have that effect in our maps?

@DolceTriade

This comment has been minimized.

Copy link
Contributor

DolceTriade commented Sep 10, 2017

We had (have?) it too. But it was SUPER expensive and no one could use it. In order to use it, we'd need to generate an additional height map for each of our normal maps I think...

@Viech

This comment has been minimized.

Copy link
Member

Viech commented Dec 12, 2017

I recall there is a texture shader keyword that needs to be set in order for the effect to appear. Not sure if height maps needed to be included.

@Viech Viech added the enhancement label Dec 12, 2017

@illwieckz illwieckz added this to To Do in Xonotic Oct 24, 2018

@illwieckz illwieckz added this to Done in Unvanquished Oct 24, 2018

@t4im t4im added the Renderer label Nov 24, 2018

@illwieckz illwieckz moved this from Done to To do in Unvanquished Nov 26, 2018

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 9, 2019

So, after investigation, I discovered that Dæmon engine…

  • requires height maps (there is no magic computation of height map from normal map at run time)
  • expects height maps to be stored in alpha channel of normal maps
  • requires a special keyword to be set in shader before the normalMap stage, this keyword is named parallax and would have been best named heightMapInNormalMap
  • does not know how to load height map that is not stored in a normal map alpha channel

So, to get parallax in game we need a lot of work to do, but that's possible.

I discovered that 2010 edition of XreaL shipped height maps for ex texture set (as external files) and trak5 one (in normal map alpha channels), but better than that, I discovered that xonotic ships height map for almost every texture they ship, including pk01, pk02, trak5, ex… 99.99% of their height maps are stored in normal map alpha channel, without requiring shader keywords. Some rare files (less than 10 in their xonotic-maps pk3) are stored as external files.

But another great news, they have code (GPLv2+) to generate height maps from normal maps, in three stages:

So, what we can do:

  • import their height maps
  • compute the others

What could be good:

  • not requiring any shader keyword to guess the availability of an height map in a normal map file
  • optional heightmap loading from dedicated file, perhaps by merging the height map to normal map alpha channel in engine so the internal representation is kept

So, it requires a lot of work, but we can do it for Unvanquished.

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 9, 2019

Quote from #159:

Note that since Xonotic ships a heightmap with almost all its normalmap, I enabled temporarily parallax on all shaders just to have a look. It works (and I haven't experienced preformance issue) but I discovered that xonotic heightmaps are upside down, or our engine is.

Perhaps it's a trick to not have to detect the presence of heightmap hidden in alpha channel of normalmap, as a missing alphachannel would mean a flat surface at the good level. Currently our engine displays a flat surface at the wrong level if we enable parallax on a normalmap without heightmap in alpha channel.

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

Since we never shipped heightmap file, we are at a redemption time allowing us to change the heightmap orientation in engine if it's more clever to do this way.

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 9, 2019

If I understand things well, according to the way a height map is stored, in one case black is up and in the other case black is down. In Dæmon the lack of alpha channel in normal map (storing the height map) produces a down height map, if heightmap was expected upside down, I guess a missing alpha channel in normal map would produce a up height map. What do people think about it? 🤔

@gimhael @cmf028 @Amanieu @Kangz any knowledge to share ? 😃

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 10, 2019

Setting r_parallaxDepthScale -0.03 displays parallax correctly, as an additional proof xonotic's height maps are reversed (or Dæmon engine is):

xonotic parallax

It proves that parallax works in engine if height maps are correctly provided, I see no performance issue.

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 10, 2019

more sreenshots:

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

xonotic upside-down parallax

@DolceTriade

This comment has been minimized.

Copy link
Contributor

DolceTriade commented Feb 11, 2019

By no performance issue, what do you mean (ie, what FPS do you get with parllax mapping vs without)? Also, those screenshots look really nice. Do the above scripts work automatically?

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 11, 2019

By no performance issue I mean it's playable with 100+ FPS while my GPU is on powersaving mode. It's a powerful GPU (R9 390X) but I run it in powersaving mode. I think it's good enough to allow us to tell we support that and that means we can ship everything required to do parallax. If someone has performance issue, he can disable it in anyway.

All those screenshots were made without editing xonotic data (it's straight xonotic pk3 with dpk symlink for easy loading), using my work in progress extramap branch discussed in #159.

The only hack I will probably not merge is the hack that activated parallax for all shaders since it produces wrong results if heightmap is missing. Note that the hack is only done on autodiscovered xonotic normalmap so it still allows to render unvanquished maps at the same time, but it would be far better to detect the presence of that heightmap.

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 11, 2019

Do the above scripts work automatically?

I thought you were talking about the xonotic .shader files, but now I think you maybe talked about the makenorms stuff above… Those scripts are meant to be called on a given set, but they look like to be written to be run only one time so there may be some tweaking required, I don't know.

@Viech

This comment has been minimized.

Copy link
Member

Viech commented Feb 11, 2019

The last three screenshots look really noisy. You might want to set a minimum texture resolution for any notion of auto-enable of that feature, because the engine implementation clearly does no smoothing of the height data (and if it did, it would look bad as well I suppose). Also note that any form of lossy compression could be problematic here as well.

@illwieckz

This comment has been minimized.

Copy link
Member Author

illwieckz commented Feb 11, 2019

Sure, that's a problem, and we (Unvanquished) have a bigger problem: we have a playable character that have eyes almost at floor level: the Dretch. Parallax looks bad if looked too nearby.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment