コード例 #1
0
ファイル: SubTerrain.cs プロジェクト: alextalvan/Ships2
    //
    // This function creates a RenderToTexture for the diffuse map and stores it as a png in the Resources folders.
    //
    public void RenderDiffuse(ProceduralMaterial Diffuse, int slot)
    {
        GameObject rtObject = (GameObject)Instantiate(Resources.Load("RTTSubTerrain"));
        Camera cam = rtObject.transform.Find("RTTSubCamera").GetComponent<Camera>();

        // Create Render To Texture
        Vector2 TexSize = new Vector2((float)Math.Pow(2,Diffuse.GetProceduralVector("$outputsize").x), (float)Math.Pow(2,Diffuse.GetProceduralVector("$outputsize").y));
        RenderTexture rt = new RenderTexture((int)TexSize.x, (int)TexSize.y, 32);
        cam.targetTexture = rt;
        rtObject.transform.Find("RTTSubPlane").GetComponent<Renderer>().sharedMaterial.mainTexture = Diffuse.GetTexture ("_MainTex");
        cam.Render();
        RenderTexture.active = rt;
        Texture2D dif = new Texture2D((int)TexSize.x, (int)TexSize.y, TextureFormat.ARGB32, false);
        dif.ReadPixels(new Rect(0, 0, (int)TexSize.x, (int)TexSize.y), 0, 0);

        // Clean up
        cam.targetTexture = null;
        RenderTexture.active = null; // added to avoid errors
        DestroyImmediate(rt,true);
        DestroyImmediate(rtObject,true);

        // Write Diffuse map as PNG
          	byte[] bytes = dif.EncodeToPNG();
        string filename = Application.dataPath + "/SubTerrain/Resources/" + gameObject.name+"_splat" + slot.ToString() + ".png";
        System.IO.File.WriteAllBytes(filename, bytes);
        AssetDatabase.ImportAsset( "Assets/SubTerrain/Resources/" + gameObject.name+"_splat" + slot.ToString() + ".png" );

        DestroyImmediate(dif,true);
    }
コード例 #2
0
 protected void ShowProceduralTexturesGUI(ProceduralMaterial material)
 {
     if (base.targets.Length <= 1)
     {
         EditorGUILayout.Space();
         Shader s = material.shader;
         if (s != null)
         {
             EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
             GUILayout.Space(4f);
             GUILayout.FlexibleSpace();
             float pixels = 10f;
             bool flag = true;
             for (int i = 0; i < ShaderUtil.GetPropertyCount(s); i++)
             {
                 if (ShaderUtil.GetPropertyType(s, i) == ShaderUtil.ShaderPropertyType.TexEnv)
                 {
                     string propertyName = ShaderUtil.GetPropertyName(s, i);
                     Texture tex = material.GetTexture(propertyName);
                     if (SubstanceImporter.IsProceduralTextureSlot(material, tex, propertyName))
                     {
                         string propertyDescription = ShaderUtil.GetPropertyDescription(s, i);
                         Type textureTypeFromDimension = MaterialEditor.GetTextureTypeFromDimension(ShaderUtil.GetTexDim(s, i));
                         GUIStyle style = "ObjectPickerResultsGridLabel";
                         if (flag)
                         {
                             flag = false;
                         }
                         else
                         {
                             GUILayout.Space(pixels);
                         }
                         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(((72f + style.fixedHeight) + style.fixedHeight) + 8f) };
                         GUILayout.BeginVertical(options);
                         Rect position = GUILayoutUtility.GetRect((float) 72f, (float) 72f);
                         DoObjectPingField(position, position, GUIUtility.GetControlID(0x3042, FocusType.Keyboard, position), tex, textureTypeFromDimension);
                         this.ShowAlphaSourceGUI(material, tex as ProceduralTexture, ref position);
                         position.height = style.fixedHeight;
                         GUI.Label(position, propertyDescription, style);
                         GUILayout.EndVertical();
                         GUILayout.FlexibleSpace();
                     }
                 }
             }
             GUILayout.Space(4f);
             EditorGUILayout.EndHorizontal();
         }
     }
 }
コード例 #3
0
 protected void ShowProceduralTexturesGUI(ProceduralMaterial material)
 {
   if (this.targets.Length > 1)
     return;
   EditorGUILayout.Space();
   Shader shader = material.shader;
   if ((UnityEngine.Object) shader == (UnityEngine.Object) null)
     return;
   EditorGUILayout.BeginHorizontal();
   GUILayout.Space(4f);
   GUILayout.FlexibleSpace();
   float pixels = 10f;
   bool flag = true;
   for (int propertyIdx = 0; propertyIdx < ShaderUtil.GetPropertyCount(shader); ++propertyIdx)
   {
     if (ShaderUtil.GetPropertyType(shader, propertyIdx) == ShaderUtil.ShaderPropertyType.TexEnv)
     {
       string propertyName = ShaderUtil.GetPropertyName(shader, propertyIdx);
       Texture texture = material.GetTexture(propertyName);
       if (SubstanceImporter.IsProceduralTextureSlot((Material) material, texture, propertyName))
       {
         string propertyDescription = ShaderUtil.GetPropertyDescription(shader, propertyIdx);
         System.Type objType;
         switch (ShaderUtil.GetTexDim(shader, propertyIdx))
         {
           case ShaderUtil.ShaderPropertyTexDim.TexDim2D:
             objType = typeof (Texture);
             break;
           case ShaderUtil.ShaderPropertyTexDim.TexDim3D:
             objType = typeof (Texture3D);
             break;
           case ShaderUtil.ShaderPropertyTexDim.TexDimCUBE:
             objType = typeof (Cubemap);
             break;
           case ShaderUtil.ShaderPropertyTexDim.TexDimAny:
             objType = typeof (Texture);
             break;
           default:
             objType = (System.Type) null;
             break;
         }
         GUIStyle style = (GUIStyle) "ObjectPickerResultsGridLabel";
         if (flag)
           flag = false;
         else
           GUILayout.Space(pixels);
         GUILayout.BeginVertical(GUILayout.Height((float) (72.0 + (double) style.fixedHeight + (double) style.fixedHeight + 8.0)));
         Rect rect = GUILayoutUtility.GetRect(72f, 72f);
         ProceduralMaterialInspector.DoObjectPingField(rect, rect, GUIUtility.GetControlID(12354, EditorGUIUtility.native, rect), (UnityEngine.Object) texture, objType);
         this.ShowAlphaSourceGUI(material, texture as ProceduralTexture, ref rect);
         rect.height = style.fixedHeight;
         GUI.Label(rect, propertyDescription, style);
         GUILayout.EndVertical();
         GUILayout.FlexibleSpace();
       }
     }
   }
   GUILayout.Space(4f);
   EditorGUILayout.EndHorizontal();
 }
コード例 #4
0
        protected void ShowProceduralTexturesGUI(ProceduralMaterial material)
        {
            if (base.targets.Length <= 1)
            {
                EditorGUILayout.Space();
                Shader s = material.shader;
                if (s != null)
                {
                    EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
                    GUILayout.Space(4f);
                    GUILayout.FlexibleSpace();
                    float pixels = 10f;
                    bool flag = true;
                    for (int i = 0; i < ShaderUtil.GetPropertyCount(s); i++)
                    {
                        if (ShaderUtil.GetPropertyType(s, i) != ShaderUtil.ShaderPropertyType.TexEnv)
                        {
                            continue;
                        }
                        string propertyName = ShaderUtil.GetPropertyName(s, i);
                        Texture tex = material.GetTexture(propertyName);
                        if (SubstanceImporter.IsProceduralTextureSlot(material, tex, propertyName))
                        {
                            System.Type type;
                            string propertyDescription = ShaderUtil.GetPropertyDescription(s, i);
                            switch (ShaderUtil.GetTexDim(s, i))
                            {
                                case ShaderUtil.ShaderPropertyTexDim.TexDim2D:
                                    type = typeof(Texture);
                                    break;

                                case ShaderUtil.ShaderPropertyTexDim.TexDim3D:
                                    type = typeof(Texture3D);
                                    break;

                                case ShaderUtil.ShaderPropertyTexDim.TexDimCUBE:
                                    type = typeof(Cubemap);
                                    break;

                                case ShaderUtil.ShaderPropertyTexDim.TexDimAny:
                                    type = typeof(Texture);
                                    break;

                                default:
                                    type = null;
                                    break;
                            }
                            GUIStyle style = "ObjectPickerResultsGridLabel";
                            if (flag)
                            {
                                flag = false;
                            }
                            else
                            {
                                GUILayout.Space(pixels);
                            }
                            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.Height(((72f + style.fixedHeight) + style.fixedHeight) + 8f) };
                            GUILayout.BeginVertical(options);
                            Rect position = GUILayoutUtility.GetRect((float) 72f, (float) 72f);
                            DoObjectPingField(position, position, GUIUtility.GetControlID(0x3042, EditorGUIUtility.native, position), tex, type);
                            this.ShowAlphaSourceGUI(material, tex as ProceduralTexture, ref position);
                            position.height = style.fixedHeight;
                            GUI.Label(position, propertyDescription, style);
                            GUILayout.EndVertical();
                            GUILayout.FlexibleSpace();
                        }
                    }
                    GUILayout.Space(4f);
                    EditorGUILayout.EndHorizontal();
                }
            }
        }
コード例 #5
0
		protected void ShowProceduralTexturesGUI(ProceduralMaterial material)
		{
			if (base.targets.Length > 1)
			{
				return;
			}
			EditorGUILayout.Space();
			Shader shader = material.shader;
			if (shader == null)
			{
				return;
			}
			EditorGUILayout.BeginHorizontal(new GUILayoutOption[0]);
			GUILayout.Space(4f);
			GUILayout.FlexibleSpace();
			float pixels = 10f;
			bool flag = true;
			for (int i = 0; i < ShaderUtil.GetPropertyCount(shader); i++)
			{
				if (ShaderUtil.GetPropertyType(shader, i) == ShaderUtil.ShaderPropertyType.TexEnv)
				{
					string propertyName = ShaderUtil.GetPropertyName(shader, i);
					Texture texture = material.GetTexture(propertyName);
					if (SubstanceImporter.IsProceduralTextureSlot(material, texture, propertyName))
					{
						string propertyDescription = ShaderUtil.GetPropertyDescription(shader, i);
						Type objType;
						switch (ShaderUtil.GetTexDim(shader, i))
						{
						case ShaderUtil.ShaderPropertyTexDim.TexDim2D:
							objType = typeof(Texture);
							break;
						case ShaderUtil.ShaderPropertyTexDim.TexDim3D:
							objType = typeof(Texture3D);
							break;
						case ShaderUtil.ShaderPropertyTexDim.TexDimCUBE:
							objType = typeof(Cubemap);
							break;
						case ShaderUtil.ShaderPropertyTexDim.TexDimAny:
							objType = typeof(Texture);
							break;
						default:
							objType = null;
							break;
						}
						GUIStyle gUIStyle = "ObjectPickerResultsGridLabel";
						if (flag)
						{
							flag = false;
						}
						else
						{
							GUILayout.Space(pixels);
						}
						GUILayout.BeginVertical(new GUILayoutOption[]
						{
							GUILayout.Height(72f + gUIStyle.fixedHeight + gUIStyle.fixedHeight + 8f)
						});
						Rect rect = GUILayoutUtility.GetRect(72f, 72f);
						ProceduralMaterialInspector.DoObjectPingField(rect, rect, GUIUtility.GetControlID(12354, EditorGUIUtility.native, rect), texture, objType);
						this.ShowAlphaSourceGUI(material, texture as ProceduralTexture, ref rect);
						rect.height = gUIStyle.fixedHeight;
						GUI.Label(rect, propertyDescription, gUIStyle);
						GUILayout.EndVertical();
						GUILayout.FlexibleSpace();
					}
				}
			}
			GUILayout.Space(4f);
			EditorGUILayout.EndHorizontal();
		}