Esempio n. 1
0
 void ConvertTexture()
 {
     normal = NormalMapTools.CreateNormalmap(diffuse, 3);
     //normal = ImageFilter.GenerateNormal(diffuse);
     //normal = NormalGeneration.Diff2Normal(diffuse);
     //normal = Normalizer.CreateNormalMap(diffuse);
 }
Esempio n. 2
0
        public static Texture2D LoadSpecular(string resref)
        {
            if (!loadedSpeculars.ContainsKey(resref))
            {
                loadedSpeculars[resref] = NormalMapTools.CreateSpecular(loadedTextures[resref], 1f, 0.5f);
            }

            return(loadedSpeculars[resref]);
        }
Esempio n. 3
0
        public static Texture2D LoadNormal(string resref)
        {
            if (!loadedTextures.ContainsKey(resref))
            {
                return(new Texture2D(1, 1));
            }
            if (!loadedNormals.ContainsKey(resref))
            //if (!loadedNormals.ContainsKey(resref + "_base"))
            {
                loadedNormals[resref] = NormalMapTools.CreateNormalmap(loadedTextures[resref], 1f);
                //loadedNormals[resref] = NormalMapTools.CreateNormalmap(loadedTextures[resref + "_base"], 1f);
            }

            return(loadedNormals[resref]);
        }
Esempio n. 4
0
    // example: Loads texture using WWW, then filters it, converts to normalmap, creates specular map and assigns them to material
    IEnumerator LoadImageFromWebAndConvertToNormalMap()
    {
        Debug.Log("Loading texture: " + url);
        WWW www = new WWW(url);

        yield return(www);

        Debug.Log("Finished loading");
        if (!String.IsNullOrEmpty(www.error))
        {
            Debug.Log("Texture loading error:" + www.error);
        }


        // assign as maintexture
        GetComponent <Renderer>().material.mainTexture = www.texture;

        // OPTIONAL: filter the texture first before creating normal map
        Debug.Log("Filtering texture..");
        Texture2D filteredTex = NormalMapTools.FilterMedian(www.texture, 5);

        // create normal map
        Debug.Log("Creating normal map");
        Texture2D normalTex = NormalMapTools.CreateNormalmap(filteredTex, 6);

        //Texture2D normalTex = NormalMapTools.CreateNormalmap(www.texture,5); // if want to use original texture, instead of filtered
        GetComponent <Renderer>().material.SetTexture("_BumpMap", normalTex);
        // NOTE: Normal map shader needs to be modified, UnpackNormal() is not needed, it breaks the runtime normalmap..
        // http://forum.unity3d.com/threads/creating-runtime-normal-maps-using-rendertotexture.135841/#post-924587


        // create specular map
        //		Texture2D specularTex = NormalMapTools.CreateSpecular(www.texture,1.2f,0.35f); // using original texture
        Debug.Log("Creating specular map");
        Texture2D specularTex = NormalMapTools.CreateSpecular(filteredTex, 1.2f, 0.5f); // using filtered texture

        GetComponent <Renderer>().material.SetTexture("_SpecMap", specularTex);


        // EXTRA TOOLS: combine rgb texture + specular texture (if you want to use unity default specular shader which takes main texture as RGB + A = gloss)
        //Debug.Log ("Combining RGB + Specular");
        //Texture2D RGBSpecTex = NormalMapTools.CombineRGBAndSpecular(www.texture,specularTex);
        //renderer.material.mainTexture = RGBSpecTex;
    }
Esempio n. 5
0
 public static Texture2D GenerateBumpMap(Texture2D diffuse, float strength = 1f)
 {
     return(NormalMapTools.CreateNormalmap(diffuse, strength));
 }
Esempio n. 6
0
        public static Texture2D GenerateSpecularMap(Texture2D diffuse, float strength = 1f, float cutoff = 0.5f)
        {
            Texture2D spec = NormalMapTools.CreateSpecular(diffuse, strength, cutoff);

            return(NormalMapTools.CombineRGBAndSpecular(diffuse, spec));
        }