buildaworldnet / IrrlichtBAW

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

Relaxed Cone Step Mapping (Relief Mapping) example #226

Open devshgraphicsprogramming opened 5 years ago

devshgraphicsprogramming commented 5 years ago

Make the binary search optional (update: I'd rather you not use bsearch) as well as the usage of a quad channel cone-map https://developer.nvidia.com/gpugems/GPUGems3/gpugems3_ch18.html

Need an irr::ext to cone maps from a bump-map (and warn everyone all the way through about the assumption that tangent space is completely flat). This should be implemented as a compute shader and should be possible to happen together with derivative map computation. It should be able to compute both the quad-channel cone-map and a single-channel cone-map. IMPORTANT Include an alpha testing threshold in the cone-step-map calculation, if alpha below threshold, substitute Relief Map value for -FLT_MAX (the the raytracing correctly skips downward).

It makes sense to compute derivative map and cone-map with the same function parameters as the heightfield-scale has to match. Heightfield-scale parameter should be defined relative to the normalized 0,1 texture coordinates, not texels, to be resolution independent and give the same results (as it is in derivative mapping already).

NOTE: The compute shader that calculates the derivative map, should also calculate the mip-maps as the mip-map filtering for a cone-map could be vastly different from the standard (manipulate shininess even further on account of the height differences). However no further filtering of specular maps should is necessary until #280 is complete.

Derivative map and cone-map should be in separate textures, as during the raytracing the cone-map will be sampled multiple times and we don't want to use more bandwidth than we need to.

Implement as a GLSL function generated from mostly built-in engine includes. Keep the implementation modular enough so we can trace arbitrary rays in tangent space, also provide two version of the tracing function:

  1. Traces through the XY texture domain and then continues, wrapping around, giving us either an intersection with heightfield or reports a failure (ray left tangent space with Z coord becoming <0 or >1). You may think its impossible, but its possible for shadow rays (tracing in reverse) and alpha tested geometry.
  2. Same as nr. 1 , but traces through the XY texture domain once, terminating reporting a failure to hit if the ray X or Y coordinate goes outside the [0,1] range.

Bonus points for implementing silhoutte handling properly http://www.inf.ufrgs.br/~oliveira/pubs_files/Policarpo_Oliveira_RTM_multilayer_I3D2006.pdf This has stuff for handling silhouettes http://www.inf.ufrgs.br/~oliveira/pubs_files/Oliveira_Policarpo_RP-351_Jan_2005.pdf

devshgraphicsprogramming commented 5 years ago

Also provide a GLSL function to calculate new gl_FragDepth (without writing to it! just want the number) given a tangent-space difference between the ray-entry-point and the ray-hit-point.

devshgraphicsprogramming commented 3 years ago

@AnastaZIuk add to stack of "recruitment tasks"