Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

hi-poly 2 lo-poly realtime reconstruction

Discussion in 'Made With Unity' started by tomaszek, Dec 1, 2012.

  1. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    Hi,

    Theme is like this. Let's say you've got hi-poly model that can be converted into heightmap. Then we translate hi-poly into lo-poly. At the end we can apply my new shader which will redraw correct geometry looking almost the same as hi-poly version. In the example below we reduce poly count x100 ! (from 250k into 2.5k in forward w/o shadows and from 1M into 10k with shadows). We can esp. gain when using realtime shadows - we don't need hi-poly geometry to be rendered in shader passes.

    http://www.stobierski.pl/unity/POMVolume_WebPlayer/WebPlayer.html



    We need heightmap+normalmap (in example normal map is 512x512, heightmap is onyl 256x256 Alpha8) + shader + script.

    What do you think ? Usable ?

    Tom
     
  2. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,765
    Given that I the left and right heads look the same to me I'd say it works? :)

    What is the actual benefit of this? Does the reduction in vertex/mesh data, displaced into height map + normal map texture lookups, faster than rendering the high-poly model?

    btw when I play the webplayer on my iMac the heads are solid black, no color or light at all.
     
  3. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    From my tests difference between hipoly (4x65k tris - shaded specular) vs low poly (4x650 tris shaded with my displace shader stuff) works about 2x faster. However I could imagine that using hundred of such hi poly models ( 6.5M tris) would kill vertex unit while rendering of 60k tris of 100 models would be just fine - depends only on number of pixels shaded, so it scale great when we get far from object. We may think about it this way - no need to prepare LOD versions as we already use "lowest LOD" model no matter the distance, as we get close to the model its detailed structure smoothly reveals.

    Of course we have to pay the price - object have to be static for obvious reason no skin anim available, lo-poly mesh that "holds" actual silhouette must be tight. Mean close to the geometry because ray tracing/traveling thru mesh volume is expensive, and so on. More issues are probably hidden somewhere (for example forward+shadows+postFX + alpha cutout shading). As usual, but this technique seems to be promising for certain applications. I think about it for sweeten architectural objects (fancy baroque puttos, decos on walls, etc). I guess it's possible to atlas resources to minimize material count (-> drawcalls). And it gives us method to produce detailed look w/o necessary to use DX11 features (available on small number of platforms only - Win7 standalone/webplayer I guess ?).

    We need relatively small displace map to get very smooth look/silhouette of object (in my example 128x128 heightmap would work just fine and would give us <25kB memory footprint). Even smaller (64x64) texture still uses bilinear interpolation so we could have very smooth (however not much detailed) visual representation.

    Performance - I've got GT240 - easily handles hundreds of polys and it doesn't hurt. Fragment shading unit is also reasonable. Results - 1280x1024 w/o shadows, forward, gives - hipoly (4 heads - 250k tris) ca. 1.6ms, low poly (2.5k) - 0.8-0.9 ms, resulting in over 500fps even when we cover the whole screen by these ugly king-kong faces.

    I believe that the method will give good profits when we use many models shaded this way. On complex scene objects that are to be rendered and are occluded (z buffer) skips fragment shading. As our model is low-poly they would cost _nothing_. Optimizing geometry (occlusion) however is much harder, so I believe it would work great for complex scenes with lot of objects.

    I know that gamers just complain about "this game sucks because I see low-poly edges". DX11 tesellation solves it, and in a few years my solution probably will become quite invalid method, but for these incoming 2-3 years some great titles could profit from the idea.

    Mac compatibility - it's always pain in neck. Cg->GLSL auto conversion is still problematic in Unity. Much better than year ago, but still - complex shaders takes ages to compile so that I use #pragma only_renderer d3d9 when writing new stuff, then I check it on openGL mode. I'll check it in forced openGL mode on my PC if it looks fine or not.

    This shader will be available to buy as part of "Relief Shaders Pack" (together with "Relief Terrain Pack") - both products incoming at the beginning of next week.

    ATB, Tom
     
    Last edited: Dec 1, 2012
  4. I am da bawss

    I am da bawss

    Joined:
    Jun 2, 2011
    Posts:
    2,574
    I don't quite understand - is this displacement mapping? The silhouette of the geometry is very smooth so I am thinking this is a runtime thing where it generate extra polygons to smooth out the edge/silhouette from the low polygon data. If that's the case, how much extra polygon is generated from baseline low polygon mesh?
     
  5. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
    No additional geometry is generated. That's the idea. We've got low-poly which looks very smooth like hi-poly (which were base model for doing heightmap). Whole trick is done by fragment program in shader. When you tick "enable reconstruction" you see 2.5k geometry rendered. When you don't tick it you see 250k polys mesh rendered (w/o shadows in forward, deferred or shadows multiplies draw calls / tris rendered).

    Tom
     
    Last edited: Dec 2, 2012
  6. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,765
    However it works, I think you know that if it's able to increase the framework of games and is easy to use and covers enough artistic scope, people will buy it.
     
  7. tomaszek

    tomaszek

    Joined:
    Jun 18, 2009
    Posts:
    3,861
unityunity