Search Unity

  1. Unity 2018.3 is now released.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Want more efficiency in your development work? Sign up to receive weekly tech and creative know-how from Unity experts.
    Dismiss Notice
  4. Build games and experiences that can load instantly and without install. Explore the Project Tiny Preview today!
    Dismiss Notice
  5. Want to provide direct feedback to the Unity team? Join the Unity Advisory Panel.
    Dismiss Notice
  6. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice

► DirectX 11 Low Poly Shader ◄

Discussion in 'Works In Progress' started by Arkhivrag, May 24, 2016.

  1. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921


    Nowadays the only possibly way of achieving flat shaded and low poly effect, consists in removing smooth info from mesh and baking color data(texture) inside mesh.
    And here problems begin:
    1. The most important - vertex count is tripled for every face, as all face must have unique vertices at each corner.
    2. Original mesh vertex count is limited to 21.666 (after conversion vertex count will be tripled - 65.000).
    3. Every converted mesh is unique. If required different colored mesh - another copy must be generated.
    4. Not all mesh data is supported (e.g Blendshapes).
    5. Converted mesh needs much more GPU and HDD memory than original.
    6. Increased vertex count and worse batching leads to slow rendering.
    7. CPU time wasting for run-time converted meshes. Even more wasting if need Normal/ Tangent re-calculations.
    All mesh packages in the Asset Store offering faceted style look are done by that way. Yes, they really are not 'low poly'.
    And all editor tools generating faceted meshes do exactly that.



    I want to introduce my new solution



    Yes, it's a shader. All "texture to vertex color" calculations are done inside shader and final effect is 100% the same as from converted meshes, but has much more advantages:
    1. No mesh converting - just apply shader to any mesh and it will be rendered in 'low poly' and 'flat-shaded' style.
    2. Important - vertex count is not increased. Mesh is rendered using its own vertices. New vertices are not generated at all!
    3. Better mesh batching → Less draw calls → Faster rendering.
    4. No limit on source mesh vertex count.
    5. No need to duplicate meshes for various color styles. Just use different material with desired texture.
    6. Even effect is calculated from texture - no need to have them in HD resolution. Compressed texture with 256 resolution is pretty enough.
    7. No increased memory because of mesh on HDD and GPU. Texture require much less space.
    8. No CPU time wasting on mesh conversion and Normal/Tangent re-calculation.
    9. Perfect for run-time generated meshes.
    10. Supports all mesh features, including Blendshapes.
    11. No limit on complex meshes (e.g Terrain, SpeedTree).

    Note:
    This is shader! Do not confuse with mesh decimation tool.
    Geometry Shaders support is required, check your device before purchasing with this test shaders.
    directx11-low-poly-shader.jpg


    Compatible with Wireframe shader for achieving better paper-craft effect.



    Here are some benchmarks:
    Test scene contains only opaque meshes, one directional light without shadow cast, camera in Forward Rendering.
    No skybox, GI, image effects or other run-time scripts. All possible features that can somehow effect rendering are disabled.
    Rendering resolution 1920x1080. PC build (GTX 660M).
    DirectX11-low-poly-shader-banchmark(full).jpg

    v2018.3
    • Added Dissolve effect for Cutout shaders

    v2018.2
    • Updated for Unity 2017.4 and Unity 2018.2
    • Added Specular map option for LegacyShaders.
    • Added Metallic/Smoothness map option for PBS shaders.

    v2018.1
    • Fixed shader compilation errors in Unity 2017.3

    v2017.3
    •Added Emission

    v2017.2
    • Compatible with 5.6
    • Added Unity 5.6 GPU Instancing
    • Added quad wireframe effect support

    v2017.1
    • Reflection with Bump will now produce better low poly look.
    • Several micro improvements.
    • All known bugs fixed. Package is not in beta any more.

    v0.92 beta
    • Added compatibility with Wireframe shader for creating paper-craft effect

    v0.91 beta
    • Unity 5.5 ready
    • Added physically based shaders (Standard shading model)

    v0.90 beta
    • Initial release



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Dec 11, 2018 at 3:38 PM
  2. theANMATOR2b

    theANMATOR2b

    Joined:
    Jul 12, 2014
    Posts:
    7,781
    This is looking like a useful alternative to the common workflows.

    Could you provide a couple more visual examples side by side, original and flat shaded, a couple characters at different original resolutions would be good and a simple tree.

    Question - does the shader support animated color changes? Example - if I wanted to show a characters face changing from normal shade to a reddish tinted color when he getting angry.
     
  3. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Bear.jpg

    I've just finished working on shader core and have no much visual examples to show, but will definitely share more progress info, stay-turned.

    Shaders will have wide range of visual controllers including tint color, two texture blending for low poly effect, textures animation and many others.


    Elephant.jpg



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 2, 2016
    theANMATOR2b and RavenOfCode like this.
  4. screenname_taken

    screenname_taken

    Joined:
    Apr 8, 2013
    Posts:
    608
    It looks really great. One question though. I heard that if i select to have hard edges in Maya to get this look, it would kill a game engine as it would make it a draw call for each face as it would put each one in its own strip. Is that the case?
     
  5. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Low poly shader renders faceted effect just in one pass, one draw call.
    You can import smooth model without hard edges and using this shader achieve desired effect.
    Also importing mesh with hard edges will increase mesh vertex count (by triangle count * 3), that will have very bad influence on rendering(check charts in the #1 post) and mesh batching.



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 3, 2016
  6. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    This a really interesting project - you have a habit of coming up with some of the most interesting assets, haha. However, I'm not sure I understand your figures (?) The low poly shader isn't showing benefits except for texture memory and VRAM, but is outperforming flat / faceted mesh in almost all categories, which is good. Could you explain why flat / faceted mesh is performing so poorly compared to the original mesh in these samples?
     
  7. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Main reasons is increased mesh vertex count -> that leads to worse static and dynamic batching -> that leads to increased draw calls.
    Also GPU handles 432K vertices better than 992K. Same as pixel shader that rasterizes each polygon.



    VacuumShaders - Facebook Twitter YouTube
     
  8. buttmatrix

    buttmatrix

    Joined:
    Mar 23, 2015
    Posts:
    609
    Right, I forgot this was a realtime solution, so we're gaining vertices, not losing them as we would if we were to decimate in modeling software. Your asset Mesh Materializer does something like this, correct? It bakes out a reduced polycount version of the original mesh?
     
  9. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Vertex count will increase in any case - it is the only possible solution nowadays for faceted style rendering.

    Before texture baking inside mesh vertex color its vertices are split because each polygon (consisting of 3 vertices) must have unique color -> that leads to increased vertex count, final mesh always will have triangle count * 3 vertices.

    All mesh packages in the Asset Store offering faceted style look are done by that way. Yes, they really are not 'low poly' meshes.
    And all editor tools generating faceted meshes do exactly that.

    And here comes DirectX 11 Low Poly Shader, that creates faceted style without increasing vertex count :cool:.



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 3, 2016
  10. screenname_taken

    screenname_taken

    Joined:
    Apr 8, 2013
    Posts:
    608
    And this is where a drop the mic smiley would be great.
     
    RavenOfCode and theANMATOR2b like this.
  11. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Was able to transform built-in skybox shader into low poly style. It is visible to GI and reflection probes.
    New shader is even faster as there is no calculations inside pixel shader at all.
    dirextx-11-low-poly-shader-skybox.png

    Skybox.png


    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 3, 2016
    defaxer, theANMATOR2b and RavenOfCode like this.
  12. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Unity renders terrain in several passes depending on used paint textures.
    DirectX 11 Low Poly Shader will render it just in one pass and without any texture rasterization inside pixel shader.

    Lowpoly - Terrain.png





    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 3, 2016
    fastbomb and RavenOfCode like this.
  13. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Achieved Paper-craft effect by combining DirectX 11 Low Poly Shader and Wireframe Shader
    PaperCraft.png

    Animation is modified with custom script (will be included in pack).

    Wireframe is completely generated inside shader and has 0 cost.
    But it's rendering with low poly effect will require Wireframe Shader pack.



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Jun 9, 2016
    00Fant and theANMATOR2b like this.
  14. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    This sounds really promising! Can't wait to see it on the Asset Store. Any idea of an ETA?

    I am using Mesh Materializer & PolyWorld at the moment but would love this for performance reasons.

    All the best!
     
  15. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Unfortunately no ETA, want to release as soon as possible.



    VacuumShaders - Facebook Twitter YouTube
     
  16. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Last edited: Jun 9, 2016
    Whiteleaf and fastbomb like this.
  17. screenname_taken

    screenname_taken

    Joined:
    Apr 8, 2013
    Posts:
    608
    Somehow the lighting makes parts look smooth instead of faced. I think it's because the light changes smoothly instead of jumping from shadow to light?
     
  18. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    It's just a game of options.
    Water_compare.png



    VacuumShaders - Facebook Twitter YouTube
     
    theANMATOR2b likes this.
  19. screenname_taken

    screenname_taken

    Joined:
    Apr 8, 2013
    Posts:
    608
    Oooooooo
    This shader is going to be great for a pop-up book type of thing as well.
     
  20. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    The water shader looks amazing! Every shot is increasing my interest. Can't wait to get this from the Asset Store.
     
  21. tpelham42

    tpelham42

    Joined:
    Apr 15, 2008
    Posts:
    119
    This looks really cool and quite useful.
     
  22. Supergeek

    Supergeek

    Joined:
    Aug 13, 2010
    Posts:
    89
    I really like the water shader. I saw the gif on Reddit. Would make a cool screen saver or something.
     
  23. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    498
    Looks great
     
  24. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    How do you think this will run on mobile? I imagine that it will be a lot faster. I would love to purchase a Beta even. Looking forward to the next round of screen caps.
     
  25. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    498
    I don't think Mobile devices can handle Direct X 11..
     
  26. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Not the whole DirectX 11 but only one of its feature - Geometry Shader.
    I will share simple geometry shader to check device if it is ready.



    VacuumShaders - Facebook Twitter YouTube
     
  27. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    You seriously just blew my mind redhawk! You had me questioning the entire scope of my project.

    I think a DX11 Geometry Shader might work though - http://blogs.unity3d.com/2015/05/26/dx11-features-on-mobile/

    Can't wait to test it out on my Samsung Note 5!
     
    99thmonkey likes this.
  28. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Ocean.png
    Download test Geometry Shaders here.

    Compilation targets supporting Geometry Shaders (more info here):

    #pragma target 4.0
    • DX11 shader model 4.0.
    • Supported on DX11+, OpenGL 3.2+, OpenGL ES 3.1+AEP, PS4/XB1 consoles.
    • Not supported on DX9, DX11 9.x (WinPhone), OpenGL ES 2.0/3.0/3.1, Metal.
    • Has geometry shaders and everything that es3.0 target has.
    #pragma target 4.6 (or gl4.1)
    • OpenGL 4.1 capabilities (DX11 SM5.0 on D3D platforms, just without compute shaders). This is basically the highest OpenGL level supported by Macs.
    • Not supported on DX9, DX11 before SM5.0, OpenGL before 4.1, OpenGL ES 2.0/3.0/3.1, Metal.
    • Supported on DX11+ SM5.0, OpenGL 4.1+, OpenGL ES 3.1+AEP, PS4/XB1 consoles.
    #pragma target 5.0
    • DX11 shader model 5.0.
    • Supported on DX11+ SM5.0, OpenGL 4.3+, OpenGL ES 3.1+AEP, PS4/XB1 consoles.
    • Not supported on DX9, DX11 before SM5.0, OpenGL before 4.3 (i.e. Mac), OpenGL ES 2.0/3.0/3.1, Metal.


    VacuumShaders - Facebook Twitter YouTube
     
    DxStd_IgnatPribylov likes this.
  29. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    Thanks for providing the Geometry Shader test files. Targets 4.6 and 5.0 seemed to work for me on the Note 5. The objects I tested were Green in my builds.

    The Unity Editor did not seem to like my setup though. When I switched the Platform to Android the objects were Magenta in the Editor.

    I am happy that this might be working. Was I supposed to only see Green or Magenta? The beach ball image made me expect something a little different.
     
  30. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    For test shaders if output color is Green, it means that device supports geometry shaders.
    Test package includes 3 similar shaders but for different platforms. It is enough one of them to work.



    VacuumShaders - Facebook Twitter YouTube
     
    theANMATOR2b likes this.
  31. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    Awesome sauce! I am glad that the test device worked. The next test will be your Shader plus the Samsung Gear VR.
     
  32. NikProductions

    NikProductions

    Joined:
    Oct 29, 2014
    Posts:
    95
    Any updates?
     
  33. NikProductions

    NikProductions

    Joined:
    Oct 29, 2014
    Posts:
    95
    Cool, can't wait!
     
  34. MaartenBicknese

    MaartenBicknese

    Joined:
    Jul 27, 2016
    Posts:
    1
    This is exactly the shader I was hoping to find!

    You were talking about a Beta last month, any updates on that? An ETA even maybe? Also, I wouldn't mind alpha testing it at all! :)
     
  35. pixelsteam

    pixelsteam

    Joined:
    May 1, 2009
    Posts:
    918
    What is this vacation stuff all about!!! Get back here Unity 5.4 is out and I want this shader ;);)
     
  36. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    Last edited: Aug 30, 2016
    fastbomb, theANMATOR2b and pixelsteam like this.
  37. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    468
    how much it will be
     
  38. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    While in beta it will be 25$



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Aug 29, 2016
  39. paulojsam

    paulojsam

    Joined:
    Jul 2, 2012
    Posts:
    468
    Thank you for the reply, now its just look at the monitor until its released ...
     
  40. fastbomb

    fastbomb

    Joined:
    Jun 28, 2013
    Posts:
    26
    What happy news @Arkhivrag! Congrats on the Beta!
     
  41. QuantumCalzone

    QuantumCalzone

    Joined:
    Jan 9, 2010
    Posts:
    245
    I can't wait for this!
     
  42. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    What to expect from DX11LPS v0.9 beta

    1. Includes Unlit and Legacy shaders.
    2. With opaque, transparent and cutout rendering modes.
    3. Supporting GI, Reflection probes, ambient lighting, lightmaps.
    4. Low poly effect color is calculated from texture. Optionally 2 textures can be mixed by Detail or Decal blend modes.
    5. Textures support scroll parameter and can be used for uv panning.
    6. Tint color, of course.
    7. Mesh vertex color, yes.
    8. Regardless low poly texture (calculated per-vertex) can be used 1 common texture (per-pixel) with Detail or Decal blend modes.
    9. Optional Specular and Bump effects.
    10. Three type of reflection: Cubemap, Reflection Probe and Real-time Planar reflection.
    11. Two type of displace: Texture(can be used 1 or 2 textures, with scrolling option) and Procedural(water surface effect).
    12. Additional shaders: Terrain, Nature tree bark and leaves, Skybox (Cubemap and Procedural).
    material-editor.png
    All screens and promo video are done by these shaders only.


    One exception! While all low poly effect components (color, normal and reflection vectors) do work the same way in all rendering modes, there is Light vector that is always smooth in Deferred mode. Because Unity generates it inside engine, it's calculated per-pixel using screen uv coordinates and can not be modified by custom shader.

    Above - Low poly light in Deferred mode.
    Below - the same light in Forward rendering mode.

    Water_compare.png


    PBS and Water (real-time refraction, depth, shore features) shaders are still in development.
    Future updates will include compatibility with Curved World and Wireframe (for paper-craft effect) shaders.



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Dec 9, 2016
  43. imaginaryhuman

    imaginaryhuman

    Joined:
    Mar 21, 2010
    Posts:
    5,565
    Apart from this looking nice, I just can't follow your logic. You talked about how there is no additional vertex data added and no extra memory used etc, but from what I can tell you are still requiring the original FULL DETAIL meshes and textures to be passed in, which are then converted to low-poly on the fly. The result may be that they render faster because you've simplified the mesh on the fly, but the hardware still has to read the entire high-detail meshes and convert them, which means they actually DO take far more memory than the equivalent 'converted' low-poly meshes... I don't see it as any kind of savings compared to the other low-poly solutions in that way. It's like a 3D de-resolution shader. You could throw a million triangle mesh at it and have it convert it to 1000 triangles on the fly but you still have to store that whole mesh in memory and send it through the pipeline. Right?
     
  44. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
    It's a shader, not mesh decimation tool.
    It does not reduce triangle or vertex count, but renders mesh in an effect called: lowpoly style or faceted shading or flat-shaded.



    VacuumShaders - Facebook Twitter YouTube
     
    Last edited: Sep 8, 2016
  45. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
  46. FloHal

    FloHal

    Joined:
    Feb 25, 2013
    Posts:
    28
    Looks amazing!
     
  47. Sx3

    Sx3

    Joined:
    Sep 25, 2012
    Posts:
    6
  48. Arkhivrag

    Arkhivrag

    Joined:
    Apr 25, 2012
    Posts:
    1,921
  49. 99thmonkey

    99thmonkey

    Joined:
    Aug 10, 2012
    Posts:
    498
    Anyone test on iOS?
     
  50. imump

    imump

    Joined:
    Jul 3, 2011
    Posts:
    48
    How do I achieve the Papercraft look? Having both the Low Poly shader and the Wireframe, I cant find a way?