コード例 #1
0
    private void PersistLookupTexture()
    {
        ShinyShadingLookupTexture l = target as ShinyShadingLookupTexture;

        if (!l)
        {
            return;
        }

        string assetName = (l.gameObject.name) + kLookupTexturePropertyName;

        // Dr Paranoia, featuring his sidekick, Punk Patch.
        assetName = assetName.Replace(":", "_");

        Texture2D persistentTexture = PersistLookupTexture(assetName, l.lookupTexture);

        foreach (Material m in l.GetComponent <Renderer>().sharedMaterials)
        {
            if (HasLookupTextureSlot(m))
            {
                m.SetTexture(kLookupTexturePropertyName, persistentTexture);
                l.SetParameters(m);
            }
        }
    }
コード例 #2
0
    public override void OnInspectorGUI()
    {
        ShinyShadingLookupTexture l = target as ShinyShadingLookupTexture;

        EditorGUI.indentLevel++;

        //l.diffuseIntensity = EditorGUILayout.Slider ("Diffuse", l.diffuseIntensity, 0f, 2f);
        {
            EditorGUILayout.Space();
            GUILayout.Label("FRESNEL", EditorStyles.miniBoldLabel);
            l.reflectivityAt0     = EditorGUILayout.Slider(" Reflectivity (0 degrees)", l.reflectivityAt0, 0f, 1f);
            l.reflectivityAt90    = EditorGUILayout.Slider(" Reflectivity (90 degrees)", l.reflectivityAt90, 0f, 1f);
            l.reflectivityFalloff = EditorGUILayout.Slider(" Falloff", l.reflectivityFalloff, 0f, 20.0f);
        }

        EditorGUI.indentLevel--;

        EditorGUILayout.Space();

        GUILayout.Label("SPECULAR", EditorStyles.miniBoldLabel);
        EditorGUI.indentLevel++;

        l.specularIntensity = EditorGUILayout.Slider("Specular 1", l.specularIntensity, 0f, 10f);
        if (l.specularIntensity > 1e-6)
        {
            EditorGUI.indentLevel++;
            l.specularShininess = EditorGUILayout.Slider(" Roughness", l.specularShininess, 0f, 1f);
            EditorGUI.indentLevel--;
        }
        l.specularIntensity2 = EditorGUILayout.Slider("Specular 2", l.specularIntensity2, 0f, 10f);
        if (l.specularIntensity2 > 1e-6)
        {
            EditorGUI.indentLevel++;
            l.specularShininess2 = EditorGUILayout.Slider(" Roughness", l.specularShininess2, 0f, 1f);
            EditorGUI.indentLevel--;
        }
        EditorGUI.indentLevel--;

        EditorGUILayout.Space();

        GUILayout.Label("MISC", EditorStyles.miniBoldLabel);

        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)
        {
            EditorUtility.SetDirty(l);
            Undo.RegisterUndo(l, "BRDFTexture Params Change");
            baked = false;
        }

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

        if (lowResPreview && !baked)
        {
            GUILayout.BeginHorizontal();
            GUILayout.FlexibleSpace();
            if (GUILayout.Button("Bake", GUILayout.MinWidth(64)))
            {
                l.Bake();
                baked = true;
            }
            GUILayout.EndHorizontal();
        }

        if (GUI.changed || !l.lookupTexture)
        {
            if (lowResPreview)
            {
                if (!baked)
                {
                    l.Preview();
                }
            }
            else
            {
                l.Bake();
            }

            PersistLookupTexture();
        }

        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);
        }

        // persist lookup-texture on Undo
        if (Event.current.type == EventType.ValidateCommand)
        {
            switch (Event.current.commandName)
            {
            case "UndoRedoPerformed":
            {
                l.Bake();
                PersistLookupTexture();
                baked = false;
            }
            break;
            }
        }
    }