public override void OnInspectorGUI()
        {
            TerrainVolumeRenderer renderer = target as TerrainVolumeRenderer;

            float labelWidth = 120.0f;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Receive Shadows:", GUILayout.Width(labelWidth));
            renderer.receiveShadows = EditorGUILayout.Toggle(renderer.receiveShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cast Shadows:", GUILayout.Width(labelWidth));
            renderer.castShadows = EditorGUILayout.Toggle(renderer.castShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Show Wireframe:", GUILayout.Width(labelWidth));
            renderer.showWireframe = EditorGUILayout.Toggle(renderer.showWireframe);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            renderer.material = EditorGUILayout.ObjectField("Material: ", renderer.material, typeof(Material), true) as Material;
            EditorGUILayout.EndHorizontal();

            // Although the LOD system is partially functional I don't feel it's ready
            // for release yet. Therefore the LOD GUI components below are disabled.

            /*EditorGUILayout.LabelField("*Experimental* LOD support:", EditorStyles.boldLabel);
             *
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField("Minimum LOD level:", GUILayout.Width(labelWidth));
             * renderer.minimumLOD = EditorGUILayout.IntSlider(renderer.minimumLOD, 0, 2);
             * EditorGUILayout.EndHorizontal();
             *
             * EditorGUILayout.BeginHorizontal();
             * EditorGUILayout.LabelField("LOD Threshold:", GUILayout.Width(labelWidth));
             * renderer.lodThreshold = EditorGUILayout.Slider(renderer.lodThreshold, 0.5f, 2.0f);
             * EditorGUILayout.EndHorizontal();*/

            // If any of the above caused a change then we need to update
            // the volume, so that the new properties can be synced with it.
            if (renderer.hasChanged)
            {
                Volume volume = renderer.gameObject.GetComponent <Volume>();
                if (volume != null)
                {
                    volume.ForceUpdate();
                }
            }
        }
Example #2
0
        public override void OnInspectorGUI()
        {
            TerrainVolumeRenderer renderer = target as TerrainVolumeRenderer;

            float labelWidth = 120.0f;

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Receive Shadows:", GUILayout.Width(labelWidth));
            renderer.receiveShadows = EditorGUILayout.Toggle(renderer.receiveShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            EditorGUILayout.LabelField("Cast Shadows:", GUILayout.Width(labelWidth));
            renderer.castShadows = EditorGUILayout.Toggle(renderer.castShadows);
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            renderer.material = EditorGUILayout.ObjectField("Material: ", renderer.material, typeof(Material), true) as Material;
            EditorGUILayout.EndHorizontal();
        }
Example #3
0
        public void OnSceneGUI()
        {
            // We use these 'Handles' functions to allow us to embed OnGUI() code into OnSceneGUI().
            // See http://answers.unity3d.com/questions/26669/using-editorguilayout-controls-in-onscenegui.html
            Handles.BeginGUI();
            terrainVolume.OnGUI();
            Handles.EndGUI();

            // If we don't have a renderer then there's no terrain being
            // displayed, and so not much we can do in this function.
            TerrainVolumeRenderer terrainVolumeRenderer = terrainVolume.GetComponent <TerrainVolumeRenderer>();

            if (terrainVolumeRenderer == null)
            {
                return;
            }

            // By default we disable the brush marker, and only turn it on if we later find a hit.
            Material      material = terrainVolumeRenderer.material;
            List <string> keywords = new List <string> {
                "BRUSH_MARKER_OFF"
            };

            if (sculptPressed || smoothPressed || paintPressed)
            {
                Event e = Event.current;

                Ray ray = Camera.current.ScreenPointToRay(new Vector3(e.mousePosition.x, -e.mousePosition.y + Camera.current.pixelHeight));

                // Perform the raycasting.
                PickSurfaceResult pickResult;
                bool hit = Picking.PickSurface(terrainVolume, ray.origin, ray.direction, 1000.0f, out pickResult);

                if (hit)
                {
                    //Debug.Log("Hit");
                    // Selected brush is in the range 0 to NoOfBrushes - 1. Convert this to a 0 to 1 range.
                    float brushInnerScaleFactor = (float)selectedBrush / ((float)(NoOfBrushes - 1));
                    // Use this value to compute the inner radius as a proportion of the outer radius.
                    float brushInnerRadius = brushOuterRadius * brushInnerScaleFactor;

                    if (material != null)
                    {
                        keywords = new List <string> {
                            "BRUSH_MARKER_ON"
                        };
                        material.SetVector("BrushCenter", pickResult.volumeSpacePos);
                        material.SetVector("BrushSettings", new Vector4(brushInnerRadius, brushOuterRadius, brushOpacity, 0.0f));
                        material.SetVector("BrushColor", new Vector4(0.0f, 0.5f, 1.0f, 1.0f));
                    }

                    if (((e.type == EventType.MouseDown) || (e.type == EventType.MouseDrag)) && (e.button == 0))
                    {
                        if (sculptPressed)
                        {
                            float multiplier = 1.0f;
                            if (e.modifiers == EventModifiers.Shift)
                            {
                                multiplier = -1.0f;
                            }
                            TerrainVolumeEditor.SculptTerrainVolume(terrainVolume, pickResult.volumeSpacePos.x, pickResult.volumeSpacePos.y, pickResult.volumeSpacePos.z, brushInnerRadius, brushOuterRadius, brushOpacity * multiplier);
                        }
                        else if (smoothPressed)
                        {
                            TerrainVolumeEditor.BlurTerrainVolume(terrainVolume, pickResult.volumeSpacePos.x, pickResult.volumeSpacePos.y, pickResult.volumeSpacePos.z, brushInnerRadius, brushOuterRadius, brushOpacity);
                        }
                        else if (paintPressed)
                        {
                            TerrainVolumeEditor.PaintTerrainVolume(terrainVolume, pickResult.volumeSpacePos.x, pickResult.volumeSpacePos.y, pickResult.volumeSpacePos.z, brushInnerRadius, brushOuterRadius, brushOpacity, (uint)selectedTexture);
                        }
                    }


                    // Forcing the update seems to be requireded in Unity 5, whereas in Unity 4 it seems to happen automatically
                    // later as a result of assigning the shader keywords. Seems best to manually call it just in case.
                    terrainVolume.ForceUpdate();
                }

                if (e.type == EventType.Layout)
                {
                    // See: http://answers.unity3d.com/questions/303248/how-to-paint-objects-in-the-editor.html
                    HandleUtility.AddDefaultControl(GUIUtility.GetControlID(GetHashCode(), FocusType.Passive));
                }

                // We need to repaint so that the brush marker follows the mouse even when a mouse button is not pressed.
                HandleUtility.Repaint();
            }

            if (material != null)
            {
                material.shaderKeywords = keywords.ToArray();
            }
        }