Ejemplo n.º 1
0
        private void OnEnable()
        {
            GrassNStuff GNS       = (GrassNStuff)target;
            var         LayerList = this.AddReorderableList <GNS_Layer> ("Layers", GNS.Layers, (Rect rect, int index, bool isActive, bool isFocused) => {
                GNS.Layers[index] = (GNS_Layer)EditorGUI.ObjectField(rect, (GNS.Layers[index] != null)?GNS.Layers[index].name:"Empty Layer", GNS.Layers[index], typeof(GNS_Layer));
            });

            LayerList.onAddCallback = (UnityEditorInternal.ReorderableList list) => {
                LayerList.list.Add(null);
            };

            this.AddReorderableList <Vector2> ("LOD Levels", GNS.LODDistances, (Rect rect, int index, bool isActive, bool isFocused) => {
                float HalfWidth = rect.width * 0.5f;

                float LODDistance = EditorGUI.FloatField(new Rect(
                                                             rect.position.x,
                                                             rect.position.y,
                                                             HalfWidth,
                                                             rect.height
                                                             ), (index + 1) + ". Distance:", GNS.LODDistances[index].x);

                float LODPercentage = EditorGUI.Slider(new Rect(
                                                           rect.position.x + (HalfWidth + 16f),
                                                           rect.position.y,
                                                           HalfWidth - 16f,
                                                           rect.height
                                                           ), "Detail:", GNS.LODDistances[index].y, 0f, 100f);

                GNS.LODDistances[index] = new Vector2(LODDistance, LODPercentage);
            }, false);
        }
Ejemplo n.º 2
0
        public void InitializeObjectPatch(GrassNStuff Manager, Vector3 ParentPosition, Vector2 PatchSize, GNS_BulkMesh[][] Meshes, Material[] LayerMaterials, UnityEngine.Rendering.ShadowCastingMode Shadows)
        {
            this.Manager = Manager;
            LayerPatches = new GNS_Object[Meshes.Length];
            CrossFaders  = new IEnumerator[Meshes[0].Length];

            for (int x = 0; x < Meshes.Length; x++)
            {
                LayerPatches [x] = new GNS_Object(RelativePosition, ParentPosition, PatchSize, Meshes[x], LayerMaterials[x], Shadows, (int)Manager.PaintResolution);
            }
        }
Ejemplo n.º 3
0
 public GNS_BulkMesh[] Meshes(GrassNStuff Manager)
 {
     if (Manager.LODDistances.Count > 0)
     {
         GNS_BulkMesh[] Meshes = new GNS_BulkMesh[Manager.LODDistances.Count];
         for (int i = 0; i < Manager.LODDistances.Count; i++)
         {
             Meshes [i] = new GNS_BulkMesh();
             Meshes [i].InitializeBulkMesh(_LODModels, _LODMeshesPercentiles,
                                           (int)(GNS.GrassNStuff.MaxMeshVertexCount * (Manager.LODDistances[i].y / 100f) * _Density) // calculate max vertex count (Max vertex * LOD percentile * Density)
                                           , i, new Vector3(Manager.PatchRounded.x, Mathf.Max(Manager.PatchRounded.x, Manager.PatchRounded.y), Manager.PatchRounded.y));
         }
         return(Meshes);
     }
     return(new GNS_BulkMesh[0]);
 }
Ejemplo n.º 4
0
        public void PaintLayer(GrassNStuff Manager, GNS_Layer Layer, Vector2 Point, Vector2 Bounds, bool Visible, Texture2D BrushTexture = null)
        {
            if (BrushTexture == null)               // if null
            {
                BrushTexture = new Texture2D(1, 1);
                BrushTexture.SetPixel(0, 0, Color.white);
                BrushTexture.Apply();
            }

            int TargetStrength = (Visible) ? 1 : 0;             // get target strength

            if (PaintBuffer == null)
            {
                PaintBuffer = CreateTempBuffer(PaintResolution);
            }
            RenderTexture TempBuffer = CreateTempBuffer(PaintResolution);             // check if layer is null

            // Set kernel settings
            Manager.SetKernelSettings(Layer);

            Material Kernel = Manager.GNSKernel;

            Kernel.SetTexture("_PaintTexture", PaintBuffer);                       // set texture paint buffer
            Kernel.SetVector("_PaintMin", new Vector4(Point.x, Point.y, 0, 0));    // set min
            Kernel.SetVector("_PaintArea", new Vector4(Bounds.x, Bounds.y, 0, 0)); // set max
            Kernel.SetTexture("_PaintBrush", BrushTexture);
            Kernel.SetFloat("_PaintTarget", TargetStrength);
            Kernel.SetVector("_CurrentPatchMin", (CachePosition - Manager.Terrain.transform.position) - MinOffset);

            Graphics.Blit(null, TempBuffer, Manager.GNSKernel, 5);              // Update paint buffer

            if (PaintBuffer != null)
            {
                PaintBuffer.Release();
            }
            PaintBuffer = TempBuffer;
            UpdateBlocks();              // update materials
        }
Ejemplo n.º 5
0
        public override void OnInspectorGUI()
        {
            // Base Data
            GrassNStuff GNS = (GrassNStuff)target;

            // Terrain settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Global Settings", EditorStyles.boldLabel);
            GNS.Terrain = (Terrain)EditorGUILayout.ObjectField(new GUIContent("Terrain"), GNS.Terrain, typeof(Terrain), true);
            GNS.Camera  = (Camera)EditorGUILayout.ObjectField(new GUIContent("Camera"), GNS.Camera, typeof(Camera), true);

            // Layer settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Layer Settings", EditorStyles.boldLabel);
            this.RenderListAt(0);

            // Performance Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Performance Settings", EditorStyles.boldLabel);

            EditorGUI.BeginChangeCheck();
            GNS.PatchSize           = EditorGUILayout.Slider(new GUIContent("Patch Size"), GNS.PatchSize, 1f, 200f);
            GNS.TransformResolution = (GrassNStuff.TextureResolution)EditorGUILayout.EnumPopup(new GUIContent("Transform Resolution", "The resolution for the textures that store the grass transform data"), GNS.TransformResolution);
            GNS.PaintResolution     = (GrassNStuff.PatchResolution)EditorGUILayout.EnumPopup(new GUIContent("Paint Resolution", "The resolution for the textures that store the visibility information for the layers"), GNS.PaintResolution);
            GNS.Shadows             = (UnityEngine.Rendering.ShadowCastingMode)EditorGUILayout.EnumPopup(new GUIContent("Shadows"), GNS.Shadows);
            if (EditorGUI.EndChangeCheck())                // check if Patch values have changed
            {
                GNS.NotifyPatchesChanged();
            }

            EditorGUI.BeginChangeCheck();
            GNS.LODFadeDistance = EditorGUILayout.Slider(new GUIContent("LOD Fade Distance"), GNS.LODFadeDistance, 0f, 200f);
            if (EditorGUI.EndChangeCheck())
            {
                GNS.UpdateMaterialBuffers();
            }
            GNS.CrossFade         = EditorGUILayout.Toggle(new GUIContent("Cross Fade"), GNS.CrossFade);
            GNS.CrossFadeDuration = EditorGUILayout.Slider(new GUIContent("Cross Fade Duration"), GNS.CrossFadeDuration, 0f, 5f);

            // Render lod list
            EditorGUILayout.Space();
            this.RenderListAt(1);

            // Editor Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Wind Settings", EditorStyles.boldLabel);
            EditorGUI.BeginChangeCheck();
            GNS.WindQuality  = (GrassNStuff.TextureResolution)EditorGUILayout.EnumPopup(new GUIContent("Wind Resolution", "The resolution for the textures that store the wind offset data"), GNS.WindQuality);
            GNS.WindSpeed    = EditorGUILayout.Slider(new GUIContent("Wind Speed"), GNS.WindSpeed, 0f, 15f);
            GNS.WindStrength = EditorGUILayout.Slider(new GUIContent("Wind Strength"), GNS.WindStrength, 0f, 5f);
            if (EditorGUI.EndChangeCheck())
            {
                GNS.UpdateWindValues();
            }

            EditorGUI.BeginChangeCheck();
            GNS.WindNoiseFrequency = EditorGUILayout.Slider(new GUIContent("Wind Noise Frequency"), GNS.WindNoiseFrequency, 0f, 2000f);
            GNS.WindNoiseAmplitude = EditorGUILayout.Slider(new GUIContent("Wind Noise Amplitude"), GNS.WindNoiseAmplitude, 0f, 10f);
            if (EditorGUI.EndChangeCheck())
            {
                GNS.RegenerateWindTexture();
            }

            // Editor Settings
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Editor Settings", EditorStyles.boldLabel);
            GNS.GridColor = EditorGUILayout.ColorField(new GUIContent("Grid Color"), GNS.GridColor);
            GNS.Debug     = EditorGUILayout.Toggle(new GUIContent("Debug"), GNS.Debug);

            // Value display
            EditorGUILayout.Space();
            EditorGUILayout.LabelField("Details", EditorStyles.boldLabel);

            // Total patch count
            if (GNS.TotalPatchCount > GrassNStuff.MaxEditorGridCount)
            {
                EditorGUILayout.HelpBox("There are to much patches to render. Max render patch count: " + GrassNStuff.MaxEditorGridCount, MessageType.Warning);
            }
            EditorGUILayout.LabelField("Total Patch Count: " + GNS.TotalPatchCount, EditorStyles.helpBox);
            EditorGUILayout.LabelField("Max Patch Render Count: " + GNS.MaxPatchRenderCount, EditorStyles.helpBox);
            EditorGUILayout.LabelField("Estimated Drawcalls: " + GNS.EstimatedDrawCalls, EditorStyles.helpBox);

            EditorUtility.SetDirty(GNS);              // set dirty
        }
Ejemplo n.º 6
0
 public void UpdateVisibility(GrassNStuff Manager)
 {
 }
Ejemplo n.º 7
0
 public GNS_ObjectRenderer(GrassNStuff Manager, GNS_Data RenderData) : base(Manager, RenderData)
 {
 }
Ejemplo n.º 8
0
 public GNS_Renderer(GrassNStuff Manager, GNS_Data RenderData)
 {
     this.Manager    = Manager;
     this.RenderData = RenderData;
 }