Free RNM Shaders

Discussion in 'Showcase' started by n00body, Dec 22, 2010.

?

Will you be using this code in your project?

  1. Yes

    57 vote(s)
    86.4%
  2. No

    9 vote(s)
    13.6%
  1. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    UPDATE:
    For anyone who is interested, feel free to check out my prior work with RNM in my SS Bump map article. There you get links to all the articles on RNM and SS Bump maps, tons of images breaking down how it works, and a video showing the tech running in a demo program I cooked up. Also, anyone wondering about the detail mapping technique used in my shaders can check out my article on Partial Derivative Normal maps. It may focus on an alternative encoding for normal maps, but it is also a pretty exhaustive article on detail mapping with tons of images.

    Background:

    Hello all! I've only recently joined the Unity community, but I want to start off with a big splash! ;)

    I started using Unity 3D when my artist friend Xenius asked me to join his project as a shader programmer. Here, I was commissioned to write a series of custom shaders that employ Radiosity Normal Mapping (RNM) to handle scene lighting. Upon completing my task, I noticed the extreme lack of usable RNM shaders for Unity 3D, and decided to release our project's shaders for free.

    Comments:
    This package contains the shaders from our project, each supporting a variety of features beyond just RNMs. Among said features are cubemap specular, detail diffuse normal maps, and alpha translucency cutouts. The combinations are in the form of multiple shaders, rather than an ubershader.

    Please note, these shaders are completely free. I will at no point charge money for them, and simply ask to be credited appropriately. Since I am releasing them for free, I make no guarantees about their overall quality or efficiency. However, they have proven to be reasonably efficient thus far, and should be ready for production use with little to no modifications.

    Other than all that, if you use my shaders then I would like to hear about the project(s) in which you plan to use them. If you have any questions, please feel free to post here or PM me. ;)

    Credits:
    xenius : Creating example art assets documentation
    n00body: Implementing RNM shaders, and coding all their variants

    Screenshots:
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]
    [​IMG]

    Files:
    Documentation
    Shaders
    Sampler Scene
    Web player for sample
    Maya 2009 project of sample scene (requires Turtle)
    Last edited: Dec 22, 2010
  2. xenius

    xenius

    Member

    Joined:
    Sep 30, 2010
    Messages:
    195
    Hi all,
    If anyone has any questions about using these RNM Shaders in a scene, baking with turtle, workflow questions, or just general aesthetic inquiry about using RNMs feel free to post or PM me.
    -Xenius
  3. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    Very cool contribution :)

    While the project I'm currently part of will pretty surely not have use for something on this visual demand level, I'm looking forward to see what others do with it.
  4. Tim C

    Tim C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Messages:
    1,437
    Very cool! I was thinking about writing something like this a few months ago but when unity3 came out I found that deferred was better for the project I'm working on. I'm curious if the 2.0 ones run on iPhone and what kind of performance you are seeing.
  5. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    I doubt it would work on mobile, it uses too many texture maps for mobile due to which it would require 2+ passes (depending on the shader 2 or even 3 passes) which just isn't doable thanks to apples decision to push an underspeced gpu into 4th gen and ipad ... the 3gs potentially could afford it but doing something that runs there and not natively on the newer ones would be a suicide design plan ;)

    Also I think there is some confusion that should cleared out, thought that already on your editor thread: OpenGL ES 2.0 is actually not SM2. Its something above it in the gpus that apple built into the current generation and DX10.1+ on any imagination tech gpu that was released after the SGX535 used by apple at the time (hard to give exact names as OpenGL ES is the streamlined optimized "super brother" of OpenGL and as such it has stuff cut. for example ES 2.0 means no FFP present at all so also none of the gl_xxx normally, unity covers this for you by feeding you with macros and perma filled registers as far as I can say)
    Last edited: Dec 22, 2010
  6. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @stramit:
    Funny thing is, my artist originally was using the deferred renderer so he could have up to 8 shadowed lights per scene to achieve his desired look. Naturally, this was horrible for performance, especially when most of the lights were static. So I was asked to implement RNMs so he could add far more lights, radiosity, etc and still be able to run on lower spec hardware. Now we are using the deferred renderer strictly for dynamic lights.

    Fun little side note, the bottom three shots have absolutely no dynamic lights in them. They are lit entirely by RNMs. :D

    @dreamora:
    Wow. I wasn't even aware of that limitation. :(

    Thanks for update.

    @both:
    Thus far, I haven't benchmarked the shaders, but will probably do so later in our project. Sadly, I don't have an iPhone on which to test, so I can't really comment on their performance. I will report my changes/findings here as time permits. ;)
  7. the_gnoblin

    the_gnoblin

    Member

    Joined:
    Jan 10, 2009
    Messages:
    721
    What is RNM if you try to explain the feature for "dummies"? ;)
    I feel sad, but I am not yet familiar with the technique. What it does? \ what are positive sides of using it? \ what are negative sides of using it?

    thanks,
    Slav
  8. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,420
    Two questions:

    1. I'm not seeing the shader's effect on either of my machines (ATI x1600 on a Mac and GeForce GTS360M on a PC). What sort of graphics card do I need to see this?

    2. Any way to create RNM normal maps in Blender or other free / open source apps?
  9. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586
    I can throw the test scene there, have iTouch 3GS, iTouch 4th gen and iPad to let it run through at native resolutions and gather you some iOS native profiler data.
    Will see if I potentially find the time today, have an important task to finish on my work before I can head to "private fun" though ;)

    EDIT:
    Short feedback on running it at full resolution on itouch 4: it stutters serious in the sample scene already and thats lightweight.
    I've gpu avg times of up to 450ms depending on the angle

    In addition it uses to many varyings for the platform which disables fog and vertex color for example
    Last edited: Dec 22, 2010
  10. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @gnoblin:
    "Radiosity Normal Mapping" is less commonly, but more appropriately referred to as "Directional Lightmapping". Essentially, it is a form of lightmapping that allows you to store lighting information from three directions, then combine them using a standard normal map. This differs from traditional lightmaps which would have to be aware of surface normal maps when baking the lightmaps.

    Positives:

    • Can bake in tons of lights, and lighting effects (Soft Shadows, Translucent Shadows, Radiosity, Ambient Occlusion, etc) and have them apply to any surface normal map
    • Versus traditional lightmaps, they can have high-resolution surface details without having to increase the lightmap resolution
    • Responds to dynamically changing normal map (ex. water/lava flow, ripples in water, etc)
    • Supports detail normal mapping
    Negatives:

    • Three lightmaps per surface requires more storage space. As such, their resolution needs to be lowered, potentially sacrificing some quality. However, the nature of these maps makes it so that the surface's normal map will likely hide this drop in resolution. Also, it tends to be significantly less than traditional lightmaps that try to have normal map detail.
    • Longer bake times, since the baking app needs to cover three lightmaps versus one
    • More shader calculations, since it needs to sample the extra lightmaps, convert the normal map to the new basis, and then combine the contributions of the lightmaps. Standard lightmaps would just be a texture sample and a multiply.
    Does that explain it well enough?

    @bigkahuna:


    1. What do you mean by "not seeing the effect? Can you take a screenshot, and explain what you mean? If there is a problem, I definitely want to fix it.
    2. Last I'd checked, Blender doesn't support them. However, I haven't really been looking.

    @dreamora:
    That doesn't surprise me since this particular batch of shaders were customized to accommodate my artist's feature requests for the PC. During their development, detail maps added the most extra instructions, with cubemaps being a close second. These were further exacerbated by having lots of tweakable variables for all of them.

    Chances are good that I could trim down the most basic RNM shader to make it run efficiently. However, to have the best chance of making it run efficiently, I would have to take a look at UDKs approach to simplifying/compressing RNMs down to two maps as opposed to the current three maps. Sadly, that introduces another processing step to convert the output of a typical baking tool and converting it to the UDK-style RNMs.

    Thanks for testing it out, by the way. Your assistance is much appreciated. ;)

    @all:
    Is there anyone here who would be interested in helping me build a simple UI/tool for converting these maps from their standard form to UDK's style? I can easily write the conversion code myself, but I don't have much experience making artist-friendly UIs.
    Last edited: Dec 22, 2010
  11. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,420
    I'm not at my dev machine at the moment, but all that I'm seeing is a flat texture, no relief at all. I'll give it another try when I get back later.

    I did a search for tools that support RNM and apparently xNormal does, so I've downloaded the latest version of it (it's free).
  12. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    I came up with my own CRNM technique that only stores directional intensity instead of color for this reason.
  13. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    Cool cool. I take it yours are more optimized and would be better suited to iPhone games?
  14. bigkahuna

    bigkahuna

    Member

    Joined:
    Apr 30, 2006
    Messages:
    5,420
    @n00body - Ignore my earlier post. Everything seems to work fine, just typical "operator error". :p
  15. xenius

    xenius

    Member

    Joined:
    Sep 30, 2010
    Messages:
    195
    @dreamora: If you'd like, I can whip of a up a sample scene for you to test the basic RNM shader on the iphone. The sample scene probably chugged due to the cube-detail shader being used, which is crazy complex by comparison.

    If you downloaded the sample scene package, try changing all the currently applied shaders to RNM and RNM-cutout respectively. It should give you a more realistic representation of possibly performance.

    @gnoblin: Speaking as an artist using RNMs, i'd say one of the not-yet-mentioned benefits is being able to have the normal map and specular characteristics reeeeeally convey a material, instead of painted detail that fakes a lot of this in the diffuse channel. Look at Mirror's Edge as an example; the game is filled with tons of minimalist, largely flat-tone materials. Its the RNM, env map spec, and normal map that really make everything 'pop' hence why the technique is so useful.

    Example from Mirror's Edge:
    $MirrorsEdge-2010-12-06-20-34-06-79.jpg
  16. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    My shaders are optimized as best as they can be for use on just about anything. Mind you, that isn't to say all of my RNM shaders will run on on iOS. Though my CRNM + SSBump shaders should run quite well.
    Last edited: Dec 22, 2010
  17. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @Geenz:
    Well yes, that is the ideal combination in terms of cutting down instructions. However, I feel like SS Bump maps would be bad for iPhone development since they don't compress well. So you are left with maps that need to be raw RGBA8, and will eat up memory in a hurry.

    I'm curious, have you found a solution to this problem?
  18. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    In terms of compression, you only really notice compression artifacts when the surface uses very low texture repeats and the surface is _right_ in front of the camera. There's no real way around it unless you use something like virtual texturing to stream full resolution uncompressed textures, and if you have the technology to use virtual texturing, then I'd question why you'd use RNMs :p
    Last edited: Dec 22, 2010
  19. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @Geenz:
    Well yes, looking back at my own experiments with the tech, it looks passable if you use RGB565 as the format. Especially since the specular is likely to be subtle, so you will be less likely to see the banding. Also, since it is intended for a small screen, it really would be hard to see it except in contrived scenarios where you are looking straight at the wall.

    It looked bad for cases where I was using straight up environment map reflections with no diffuse. In that case, I should instead be using standard normal maps for the bumped reflection.

    @all:
    For anyone who is interested, feel free to check out my prior work with RNM in my SS Bump map article. There you get links to all the articles on RNM and SS Bump maps, tons of images breaking down how it works, and a video showing the tech running in a demo program I cooked up. Also, anyone wondering about the detail mapping technique used in my shaders can check out my article on Partial Derivative Normal maps. It may focus on an alternative encoding for normal maps, but it is also a pretty exhaustive article on detail mapping with tons of images.

    Cheers! ;)
  20. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    If you even intend to have "real" specular. On iOS, you pretty much have to fake specular if you want to use lightmaps with it.
  21. francksitbon

    francksitbon

    Member

    Joined:
    Jan 22, 2010
    Messages:
    260
    Hi, everything is black when i use your shader, do i need unity pro ?
  22. Dreamora

    Dreamora

    Member

    Joined:
    Apr 5, 2008
    Messages:
    26,586

    Will try that when I find time and see how it impacts.
    But I guess better cause the cubemap ones are the worst as they ramp up the the whole thing to another level of "worseness" for the mobile gpu
  23. francksitbon

    francksitbon

    Member

    Joined:
    Jan 22, 2010
    Messages:
    260
    Oups ok it works, have to turn off emulation
  24. francksitbon

    francksitbon

    Member

    Joined:
    Jan 22, 2010
    Messages:
    260
    Ok, same problem than with standard Normal maps, on the iPad, i have 3.54 fps on a simple square. (openGl 2.0)
    If i put the zbrush object 35000 poly, with no normal maps opengl 1.1, I get 30 fps.
    Is there any solutions to make normal mapping works on iPad ?
  25. megmaltese

    megmaltese

    Member

    Joined:
    Mar 19, 2009
    Messages:
    1,897
  26. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @francksitbon:
    I haven't run the shaders with emulation, so I never knew about that problem. Since most of them are SM 3.0 only, that is probably the reason for it not working correctly. Rest assured, they run in both versions of Unity, as my artist has Pro and I have Basic. These shaders have been tested and retested in both versions several times, so I am reasonably certain they will work. :p

    For your iPad test, which shader were you using? Were you using the most basic RNM shader in the package?

    As for the normal mapping problem, that is probably why Geenz defaults to using SS Bump maps in his implementation on the iOS platforms. It requires significantly fewer calculations at runtime since you don't have to recover the normal map, or convert it using Valve's basis.

    @dreamora:
    Yeah, asking for normal mapped cube maps really piles on the extra varying variables. Makes me think specular isn't worth it on the platform, except in a really hacky form that is dirt cheap. Even that is a stretch, I think.

    @megmaltese:
    While I see the point you are trying to make, I feel like it is arguing semantics. To me, it is "translucent" if it is see-through but still visible, and "transparent" if it is completely see-through. Still, thanks for chiming in on the matter. ;)

    @all:
    Thanks for all the feedback guys. Keep it coming! ;)

    Also, for anyone using my project's shaders, I was wondering if you would be willing to take some screenshots of my shaders running in your projects when you get far enough along to really start using them. I'm a little excited by the idea of other people getting use my tech, and am curious to see how it will turn out for everyone else! :D
    Last edited: Dec 23, 2010
  27. shadow explorer

    shadow explorer

    New Member

    Joined:
    Dec 13, 2010
    Messages:
    61
    i suppose they are no use for 2.6.1 right?
  28. reissgrant

    reissgrant

    Member

    Joined:
    Aug 20, 2009
    Messages:
    727
    Thanks for posting this! Truly a great contribution! :D
  29. megmaltese

    megmaltese

    Member

    Joined:
    Mar 19, 2009
    Messages:
    1,897
    Well I didn't want to point it out only for semantics.
    A coloured glass and an umbrella of textile are two completely different materials.
    The first is transparent, the second is translucent!
    I hope you can get what I mean because this translucent shader would be very useful exactly for tents, umbrellas, dirty plexiglas, grained plexiglas and plastic panels and much more.
    Actually, that shader is a TRANSPARENT one.

    Then, if you want to continue to call something transparent as translucent, for me it doesn't matter ;)
  30. Daniel Brauer

    Daniel Brauer

    Member

    Joined:
    Aug 11, 2006
    Messages:
    3,262
    "Transparent" is the correct term for something that allows light transmission without diffusion. Multiplicative blending is an appropriate model for transparency.

    Semi-transparency is when light is partially reflected with diffusion, but also partly transmitted without diffusion. Alpha blending is an appropriate model for semi-transparency, and it looks like that is what the "transluscent" version of the shader is using.

    Translucency is when light is transmitted with diffusion, as with frosted glass. Translucency is less commonly used in real-time, as it cannot be modelled with standard blending functions.
  31. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @shadow explorer:
    Sadly no, these shaders use Unity 3D's new Surface Shaders system, and thus would not run in Unity 2.6.1. This is not to say that the tech is incompatible with prior versions of Unity. However, I have no plans to backport them, as my current project is strictly built on the latest version of Unity.

    @reissgrant:
    Glad you appreciate our efforts! I hope you will find them useful. ;)

    @megmaltese Daniel Brauer:
    That was certainly informative, and again I appreciate your input. Though I am going to continue using the current terminology, because that makes the most sense to both myself and my project's artist.
  32. rea

    rea

    Member

    Joined:
    Oct 10, 2009
    Messages:
    915
    Uh question, is there another way to generate the lightmap without turtle? how about non maya user?
  33. francksitbon

    francksitbon

    Member

    Joined:
    Jan 22, 2010
    Messages:
    260
    Yes i was using the most basic RNM normal map shader. Same problem with the unity basic normal map shader. Both run about 4fps on my iPad with the last iOS ( no jailbreak). I don't know if it is an hardware problem, or if it is a problem with Unity with normal maps.
  34. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @rea:
    I believe Modo and xNormal support RNM export. However, I am not familiar with either tool, and can't say with any certainty.
  35. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    Modo doesn't directly support exporting RNMs. You have to do a bit of trickery in order to get Modo to bake RNMs. By far, the easiest way to generate RNMs is using Turtle.
  36. scarletsnake

    scarletsnake

    New Member

    Joined:
    Nov 27, 2009
    Messages:
    87
    I downloaded the demo project and I think some materials look really good(bent metal) while others don't look so good(Tall concrete wall). But it seems like a pretty solid start so thanks for the contribution. Now if you'll excuse my ignorance, while doing some rather simple research on the matter I came across this :

    http://www.valvesoftware.com/public...ficientSelfShadowedRadiosityNormalMapping.pdf

    Is this feature already available or are you thinking about doing it?
    I gather there are no dynamic lights in the scene so I couldn't really see similar effects.
    I am mainly an artist/mechanics designer and have little programming experience so this all seems like gibberish to me but the screenshots provided in the pdf presentation do look good.
  37. Geenz

    Geenz

    Member

    Joined:
    Sep 1, 2010
    Messages:
    98
    Mine already support that technique :p
  38. Doza3D

    Doza3D

    New Member

    Joined:
    Dec 14, 2010
    Messages:
    15
    Wow, how did I miss this? Thank you for this! I can't believe how awesome this will make my work.
  39. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    @scarletsnake:
    In the past, I've experimented with SS Bump maps and managed to get some impressive results. However, they carry with them quite a few negatives that made me feel like they wouldn't be well suited to my current project. In particular, deferred shading doesn't benefit from their directional occlusion effect. In fact, they may look worse since we would have to recover a normal from an SS Bump map, which will be a bit distorted.

    @Doza3D:
    Glad you like our work. I hope that the shaders will prove useful to you. ;)
    Last edited: Dec 25, 2010
  40. IMyMe

    IMyMe

    New Member

    Joined:
    Apr 10, 2012
    Messages:
    1
    Hi, N00body!

    Great job! I have just one question:

    How can I bake these 3 different lightmaps to feed the material's lightmap slots?
    Can I bake them in 3dsMax? (I already know how to bake a lightmap in this software, but I can't figure out how can I bake 3 different ones properly)

    Thank you so much!
  41. n00body

    n00body

    Member

    Joined:
    Dec 17, 2010
    Messages:
    157
    These shaders are deprecated now that Unity has integrated RNMs into the engine. Unless of course you are using Unity Basic.

    In any case, I don't know how it would work with 3DSMax. My artist handled the lightmap UVs and baking using a combination of Maya and Turtle. I just took the data he handed me and rendered it.

    Sorry if that doesn't really help you much. :(
  42. serpin

    serpin

    Member

    Joined:
    Nov 13, 2011
    Messages:
    42
    What are you talking about? They only made Beast acknowledge normal maps, that's all! I've double checked it: nothing that even remotely looks like RNM is there in the setting window or docs.

    Even here they say the same thing: http://www.youtube.com/watch?v=NxlWHx5JOns

    Please don't abandon the project. It's gonna be AGES before Unity team implements hassle-free RNM, trust me.
  43. xenius

    xenius

    Member

    Joined:
    Sep 30, 2010
    Messages:
    195
    @serpin: As n00body's collaborator, I can tell ya right now that Unity does indeed have fairly hassle-free RNM support now. They're called Directional Lightmaps.

    $directional.jpg

    You can enable them right there (weird that i couldn't find mention in the manual though). My suggestion in using them (if you have the memory/file space in your build) is to use them in Truecolor mode, or you'll get a lot of color noise.
  44. serpin

    serpin

    Member

    Joined:
    Nov 13, 2011
    Messages:
    42
    Hmm. Thanks!

    The only official mention of RNM/directional lightmaps I could find (aside from the 3.5 road-map) was this page: http://unity3d.com/unity/whats-new/unity-3.5

    Right, it's right there in the dropdown... Silly me.

    Thank you for the truecolor advice. Think I'll then try compressing it with PVRTexTool (again - because I haven't found any info on which PVR compressor it's using, but in 3.4 it was giving mediocre to terrible results, that's for sure!).

    [OFFTOP]I love Unity and Unity developer team, I really do. But lack of proper up-to-date documentation is something you can't just ignore. Look at UDK (yes... UDK) - each update comes with plethora of docs and examples. I understand that it's like comparing a steam train to a toy truck, but would it really hurt anyone if they released new versions with docs and examples?.. Do we really need "cutting-edge" tech if there is no knowledge base to refer to?
    Sorry for this angry rattle...[/OFFTOP]


    UPDATE:

    OH MY! IT REALLY WORKS! Ans it IS as hassle-free as it can possibly be!

    And after you bake you just set 3 new color lightmaps to the lowest acceptable res (64-256) and voia!

    Xenius, thank you for you help. Unity team - thank you for you =)
    I'm off to make another "Mirror's edge" clone, eee-ha!
    Last edited: Dec 4, 2012
  45. Fishman92

    Fishman92

    Member

    Joined:
    Feb 9, 2010
    Messages:
    2,553
    I assume that's pro only too...
  46. serpin

    serpin

    Member

    Joined:
    Nov 13, 2011
    Messages:
    42
    Sadly, - yes. But nothing is stopping you from developing your levels and lighting in free version and switching to pro directional lightmaps and other pro features only when you're sure you need them.
    And regarding lightmapping - you won't have to redo anything since directional lightmaps just sample color vectors and provide more possibilities and don't change diffuse lightmaps at all.
    Last edited: Dec 5, 2012
  47. Fishman92

    Fishman92

    Member

    Joined:
    Feb 9, 2010
    Messages:
    2,553
    Apart from money, of course. I don't exactly have 1k to shell out just like that.
  48. kilik128

    kilik128

    Member

    Joined:
    Jul 15, 2013
    Messages:
    311
  49. omarzonex

    omarzonex

    Member

    Joined:
    Jan 16, 2012
    Messages:
    131
    WOW

    Beautiful RT Rendering