コード例 #1
0
	static Material FindCompatibleMaterial (BRDFLookupTexture l)
	{
		Renderer r = l.gameObject.renderer;
		if (!r) return null;
		
		Material m = r.sharedMaterial;
		if (m && m.HasProperty (kLookupTexturePropertyName))
			return m;
		
		return null;
	}
コード例 #2
0
    private void PersistLookupTexture()
    {
        BRDFLookupTexture l = target as BRDFLookupTexture;

        if (!l)
        {
            return;
        }

        Material m = FindCompatibleMaterial(l);

        string    assetName         = (m ? m.name : l.gameObject.name) + kLookupTexturePropertyName;
        Texture2D persistentTexture = PersistLookupTexture(assetName, l.lookupTexture);

        if (m)
        {
            m.SetTexture(kLookupTexturePropertyName, persistentTexture);
        }
    }
コード例 #3
0
    public override void OnInspectorGUI()
    {
        BRDFLookupTexture l = target as BRDFLookupTexture;

        l.intensity = EditorGUILayout.Slider("Intensity", l.intensity, 0f, 8f);

        EditorGUILayout.Space();
        l.diffuseIntensity = EditorGUILayout.Slider("Diffuse", l.diffuseIntensity, 0f, 2f);
        if (l.diffuseIntensity > 1e-6)
        {
            EditorGUI.indentLevel++;

            l.keyColor   = EditorGUILayout.ColorField("Key Color", l.keyColor);
            l.fillColor  = EditorGUILayout.ColorField("Fill Color", l.fillColor);
            l.backColor  = EditorGUILayout.ColorField("Back Color", l.backColor);
            l.wrapAround = EditorGUILayout.Slider("Wrap Around", l.wrapAround, -1f, 1f);
            l.metalic    = EditorGUILayout.Slider("Metalic", l.metalic, 0f, 4f);

            EditorGUI.indentLevel--;
        }

        EditorGUILayout.Space();
        l.specularIntensity = EditorGUILayout.Slider("Specular", l.specularIntensity, 0f, 8f);
        if (l.specularIntensity > 1e-6)
        {
            EditorGUI.indentLevel++;
            l.specularShininess = 1f - EditorGUILayout.Slider("Glossiness", 1f - l.specularShininess, 0f, 1f - 0.03f);
            EditorGUI.indentLevel--;
        }

        EditorGUILayout.Space();
        l.translucency = EditorGUILayout.Slider("Translucency", l.translucency, 0f, 1f);
        if (l.translucency > 1e-6)
        {
            EditorGUI.indentLevel++;
            l.translucentColor = EditorGUILayout.ColorField("Color", l.translucentColor);
            EditorGUI.indentLevel--;
        }


        EditorGUILayout.Space();
        GUILayout.BeginHorizontal();
        EditorGUILayout.PrefixLabel("Lookup Texture", "MiniPopup");
        l.lookupTextureWidth = EditorGUILayout.IntPopup(l.lookupTextureWidth, kTextureSizes, kTextureSizesValues, GUILayout.MinWidth(40));
        GUILayout.Label("x");
        l.lookupTextureHeight = EditorGUILayout.IntPopup(l.lookupTextureHeight, kTextureSizes, kTextureSizesValues, GUILayout.MinWidth(40));
        GUILayout.FlexibleSpace();
        GUILayout.EndHorizontal();

        if (GUI.changed)
        {
            Undo.RegisterUndo(l, "BRDFTexture Params Change");
            changed = true;
        }

        // preview
        GUILayout.BeginHorizontal();
        l.fastPreview = EditorGUILayout.Toggle("Fast Preview", l.fastPreview);
        GUILayout.FlexibleSpace();
        if (GUILayout.Button(previewRGB? "RGB": "Alpha", "MiniButton", GUILayout.MinWidth(38)))
        {
            previewRGB = !previewRGB;
        }
        GUILayout.EndHorizontal();

        if (changed || !l.lookupTexture)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Bake", GUILayout.MinWidth(64)))
            {
                l.Bake();
                PersistLookupTexture();
                changed = false;
            }
            else
            {
                if (l.fastPreview)
                {
                    l.Preview();
                }
                else
                {
                    l.Bake();
                }
            }
            GUILayout.EndHorizontal();
        }

        Rect r = GUILayoutUtility.GetAspectRect(1.0f);

        r.x      += kTexturePreviewBorder;
        r.y      += kTexturePreviewBorder;
        r.width  -= kTexturePreviewBorder * 2;
        r.height -= kTexturePreviewBorder * 2;
        if (previewRGB)
        {
            EditorGUI.DrawPreviewTexture(r, l.lookupTexture);
        }
        else
        {
            EditorGUI.DrawTextureAlpha(r, l.lookupTexture);
        }

        // save preview to disk
        if (GUI.changed && changed && l.lookupTexture && l.fastPreview)
        {
            PersistLookupTexture();
        }
    }