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.
  2. Dismiss Notice

ImagePunch - Free Bump/Normal Map Editor Extension

Discussion in 'Works In Progress - Archive' started by ENNEMMEE, May 6, 2014.

  1. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    I have created a small editor extension that I've called ImagePunch.

    It is used to create bump/normal maps and height maps from textures or other images/photos (although I'm pretty sure that it will not give satisfactory results when you try to use it with uv mapped textures).

    This is just a small extension and there's still a lot to do (performance, additional image processing methods), but I've decided to share this one... completely... for free... :D

    Maybe this can become sort of a community project - if anyone wants to contribute to this, just go ahead :cool:


    Here's a few screenshots:
    $IPEditor.PNG
    $Screenshot01.png
    $Screenshot02.png
    $Screenshot03.png

    I have used Surface Shaders with DX11 Tessellation for that screenshots to better present the heightmaps. With a little effort such displacement could also be realized in a non-DX11 shader without tesselation but with a mesh that has enough vertices.
     

    Attached Files:

    Last edited: May 8, 2014
  2. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    How to use:

    * import the package :mrgreen:
    (one script is being placed in a folder named 'Editor' - leave it there!)

    * create a mesh (sphere, plane, whatever you like), a light source and a material but leave the textures empty (don't forget to use a shader that uses normal maps)
    (for my screenshots I used the distance based tesselation shader from here: Surface Shaders with DX11 Tessellation)

    * assign the material to your mesh :mrgreen:

    * add the ImagePunch script to your mesh



    Now to the ImagePunch section in your inspector:

    * select a source texture (could be a usual square texture or an image/photo)

    * select your material as target material

    * once this is done you can select the texture names that your shader provides so that the script knows which texture has to be set
    $IPEditor.PNG

    * hit the button labeled 'Generate' and wait (yep, it is painfully s-l-o-w in its current version)

    * watch your result and play around with the provided properties
     
    Last edited: May 8, 2014
  3. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Looks cool, i good integrated normal map/height map generator would be really neat!
     
  4. JohnRossitter

    JohnRossitter

    Joined:
    Dec 18, 2013
    Posts:
    1,027
    It looks very interesting!
    Once you have the basics down, you should look at how to make it work with UV Maps and create procedural textures like dDo.
    I do a lot of editor extension work too, PM me if you ever want to talk shop.
     
  5. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Ok, I have edited my posts:
    provided new screenshots and the full package with the complete script - for free

    Have fun with it, hope you enjoy it :cool:


    grrrrr, I can't rename the thread :-(
     
    Last edited: May 8, 2014
  6. virror

    virror

    Joined:
    Feb 3, 2012
    Posts:
    2,963
    Would be nice to be able to only generate heightmap or only normalmaps, maybe just two checkboxes or something? : )
     
  7. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    If the corresponding 'Shader Name' is set to '--undefined--' then it will not generate that texture. So if the shader name for the heightmap is not defined, then it will leave that out ;)
     
  8. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,827
    Looks amazing, i would love to see a non DX11 version too

    BTW, is it possible to bake DX11 real time tesselation inside Unity ?

    Like just copy the object in game mode and then copy back the changed item, or save to disk with code

    Anyone tried that ?
     
    Last edited: May 8, 2014
  9. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    Ok, I've just written a tiny simple non-DX11 displacement shader for you to show - nothing sophisticated. In fact, it's just the sample DX11-shader but without the tesselation part.

    non-DX11 with Unity's standard low-poly spheres and a plane (I don't have high poly models here)
    $Screenshot05.png

    DX11 with tesselation = high poly
    $Screenshot02.png

    Code (csharp):
    1. Shader "Custom/DisplacementShader" {
    2.     Properties {
    3.         _MainTex ("Base (RGB)", 2D) = "white" {}
    4.         _NormalMap ("Normalmap", 2D) = "bump" {}
    5.         _DispTex ("Disp Texture", 2D) = "gray" {}
    6.         _DispAmount ("Displacement Amount", Range(0.0,1.0)) = 0.5
    7.     }
    8.     SubShader {
    9.         Tags { "RenderType"="Opaque" }
    10.         LOD 200
    11.        
    12.         CGPROGRAM
    13.         #pragma glsl
    14.         #pragma target 3.0
    15.         #pragma surface surf BlinnPhong addshadow fullforwardshadows vertex:vert nolightmap
    16.  
    17.         sampler2D _MainTex;
    18.         sampler2D _NormalMap;
    19.        
    20.         struct Input {
    21.             float2 uv_MainTex;
    22.         };
    23.  
    24.         void surf (Input IN, inout SurfaceOutput o) {
    25.             half4 c = tex2D (_MainTex, IN.uv_MainTex);
    26.             o.Albedo = c.rgb;
    27.             o.Alpha = c.a;
    28.                         o.Specular = 0.2;
    29.                         o.Gloss = 1.0;
    30.             o.Normal = UnpackNormal(tex2D(_NormalMap, IN.uv_MainTex));
    31.         }
    32.        
    33.         sampler2D _DispTex;
    34.         float _DispAmount;
    35.         void vert (inout appdata_full v) {
    36.             float d = tex2Dlod(_DispTex, float4(v.texcoord.xy,0,0)).r * _DispAmount;
    37.             v.vertex.xyz += v.normal * d;
    38.         }
    39.         ENDCG
    40.     }
    41.     FallBack "Diffuse"
    42. }
    43.  

    I don't know if I understand what you mean, but DX11 tesselation is a GPU thing and I don't think you can simply grab and save that data to disk. What you can do is tesselate (=subdivide) with a modelling tool of your choice but it will not be as fast as DX11 tesselation. I just chose DX11 and that tesselation shader to show what's possible and because it was ready to go, copy&paste ;-)
     
    Last edited: May 8, 2014
  10. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,827
    Thanks, you are amazing :)

    I can definitly use the non DX11 one in my game

    I try to avoid DX11 so i keep the project available to as many platforms as possible, though the DX11 version could also come in handy for other projects
     
  11. ENNEMMEE

    ENNEMMEE

    Joined:
    Apr 4, 2012
    Posts:
    32
    But keep in mind, that those two lines raise the minimum hardware specifications of the shader:
    Code (csharp):
    1. #pragma glsl
    2. #pragma target 3.0
    I don't know if vertex displacement is possible on platforms like android, etc. as it requires a graphics adapter with shader model 3 - those two lines are necessary for the vertex displacement to work
     
  12. nasos_333

    nasos_333

    Joined:
    Feb 13, 2013
    Posts:
    12,827
    My game would probably make cellphones explode :), so it is fine

    And that is before i insert the Unity Pro effects when i finally get Pro

    The target platforms are PC and anything next gen (PS4 hopefully, long shot), with a slight hope to have time to bake many of the 3D assets to my 2D pipeline and produce an iPad version at a later time, which at that point probably iPad will be a super PC of today :)