buildaworldnet / IrrlichtBAW

Build A World fork of Irrlicht
http://www.buildaworld.net
Apache License 2.0
122 stars 27 forks source link

Add an utility shader and functions for Normal Compression #19

Open devshgraphicsprogramming opened 6 years ago

devshgraphicsprogramming commented 6 years ago

Best idea would be to generate a 2D lookup texture as per Crytek.

devshgraphicsprogramming commented 6 years ago

We currently travel the cubic grid along the original normal vector and find the closest (normalized dot product angle wise) integer vector (closest to co-linear) for a given precision (8-8-8 or 10-10-10), we use a cache with a binary search to speed that up.

For realtime purposes Crytek made a HLSL function which uses a precomputed 2D 1024x1024 or 2048x2048 texture to give very good approximates to the results of the above.

Cryengine Presentation

devshgraphicsprogramming commented 5 years ago

@Crisspl try and do this over the course of the month.

I think my findFit function is messed up, or something else (like the rest of quantizeNormal_10_10_10_2) that causes the latest MSVC 2019 to make the sphere look bad in your current BRDF Explorer branch (July 6).

Also @Przemog1 already implemented the vector hashing function: https://github.com/buildaworldnet/IrrlichtBAW/issues/221#issuecomment-463733547

So you can add an std::hash implementation to core::vectorSIMDf and change the normal quantization cache to a better data structure, as right now model loading turns into 99% binary insertion sort which is very very slow.

Note: unordered_map is actually quite slow because the C++11 spec is written so badly it precludes the use of anything else than a linked list for the bins... keep that in mind (one day we may alias core::unordered_map to something else than std::unordered_map)