Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Grayscale bumpmaps

Discussion in 'Shaders' started by Jessy, Oct 27, 2009.

  1. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Unity provides no shaders to deal with these. I would like to know how you can use them because

    • My girlfriend is in a games texturing class where she's supposed to create one this week.
    • I wonder if they could work on the old iPhone.
    I have some ideas about how to use them, but I'd like to know how the pros do it...er, did it? :?
     
  2. bigkahuna

    bigkahuna

    Joined:
    Apr 30, 2006
    Posts:
    5,434
    Unity converts them to normal maps and then uses them... but you knew that already, right? Perhaps I don't understand what you're asking.
     
  3. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    First of all, I don't believe in that sort of nonsense. 8) If I want to use a normal map, then I'll model a hi-res version of the object and bake the normals. (But yes, I'm quite aware that there is an option to do this in Unity.)

    I want to know how to write a shader that uses a real bumpmap, not a normal map. She has to make it for class, and I'd like to see it in action, and normal maps don't work on the iPhone.
     
  4. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    Unity iPhone does support normal maps, just not tangent-space normal maps. Instead, it supports object-space normal maps, which work fine for rigid meshes.

    Height maps aren't useful for perturbing a normal in a shader because unless you take at least three offset samples from the height map, you can't calculate the normal. Even once you've taken your samples, it's a fair bit of work to put together the normal. The math to do this with four samples is pretty straightforward, and you can probably even get some code from a normal map generator somewhere.

    So, it can definitely be done, but it's a lot of math and extra lookups in a fragment shader for something that you can easily pre-compute. The fragment shader requirement means it won't work on the iPhone for the same reason that tangent space normal mapping doesn't work.
     
  5. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    The Dot3 operator does support tangent space normal maps, but you'd have to recalculate the normal of light for each texel every frame, and store that in an RGB texture. That's completely unrealistic (at least to my understanding). Might as well just use 64x the geometry.

    Other than that, I'm not sure where you're going. This thread has nothing to do with normal mapping. Bump mapping will just darken or lighten a surface, and not pay any attention to normals, as far as I understand it. So if you've got a bump on something, and light comes from its right side, its left side will be as bright as the right side.
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    Bumpmaps actually don't give anything about lights at all. They just give a fictive detail on the surface and are therefor great for vertex lit environments.

    Thats why they were replaced by normal mapping technics as soon as pixel lights were reasonably fast as surface details that does not interact with lights is kind of useless.

    Bumpmap though is impossible on the iPhone (bumpmaps are a programmable pipeline thing). Dot3 is the only thing present and that either requires you to use a cube / sphere map that contains the corresponding color data or update the mesh which is unrealistic. (updating a 6 pixel texture would be easy if the iphone supported cube maps)
     
  7. Aras

    Aras

    Unity Technologies

    Joined:
    Nov 7, 2005
    Posts:
    4,770
    Terminology confusion for the win!

    The way I (and others in this thread, it seems) understand "bumpmapping" is that a bumpmap is a grayscale heightmap. So when you use it, you compute normal from the heightmap for each pixel you render, and use that in your lighting calculations. Of course, this is a serious amount of work to do per pixel, so what everyone does is precomputes the normals into the texture directly (hence "normal mapping").

    What do you mean by "bump mapping"?

    I'd want to ask dreamora the same question :) Your explanation is not my understanding of bumpmaps. Maybe you meant emboss bump-mapping? (which still takes light direction into account...)
     
  8. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
    Here's a shader that demonstrates what I thought old-school bumpmapping meant. However, from doing some research yesterday, it does seem like that's not in line with reality. I was under the impression that some Xbox 1 games used bumpmapping (not normal mapping), and I owned the Riddick game that apparently was the first console game to use normal maps. I never saw anything as next-gen-looking as Riddick prior to its release, even with a bad framerate. I am indeed confused by several relevant things. :wink:

    (Also, although I've been told that bumpmaps use 50% grey as no "raising or lowering of the surface", I don't see how you could do this without using white as the baseline, and indenting from there. Otherwise, you could be adding light where there is no light, which adds even more to the terrible unrealisticness of it! :eek:)

    Code (csharp):
    1. Shader "Bumpmapped by Alpha" {
    2.    
    3.  
    4. Properties
    5. {
    6.     _Bumpiness ("Bumpiness", Range (0,1) ) = .5
    7.     _MainTex ("Texture (RGB) + Bumpmap (A)", 2D) = ""
    8. }
    9.  
    10.  
    11. SubShader
    12. {
    13.     Lighting On
    14.        
    15.     Material
    16.     {
    17.         Diffuse (1,1,1)    
    18.     }
    19.  
    20.     Pass
    21.     {
    22.         // subtract the inverted heightmap
    23.         SetTexture [_MainTex]
    24.         {
    25.             combine primary - one - texture alpha
    26.         }
    27.        
    28.         SetTexture [_]
    29.         {
    30.             constantcolor (0,0,0, [_Bumpiness])
    31.             combine previous lerp (constant) primary
    32.         }
    33.        
    34.         SetTexture [_MainTex]
    35.         {
    36.             combine texture * previous
    37.         }
    38.     }
    39. }
    40.  
    41.  
    42. }
     
  9. Daniel_Brauer

    Daniel_Brauer

    Unity Technologies

    Joined:
    Aug 11, 2006
    Posts:
    3,355
    I don't think anyone would consider that "supporting" tangent space normal maps.