// Set voids public void SetKernelSettings(GNS_Layer Layer) { // Rotation GNSKernel.SetFloat("_RandomPitch", Layer.RandomPitchAngle * Mathf.Deg2Rad); // set rotation pitch GNSKernel.SetVector("_RotationNoise", new Vector3(Layer.RotationNoiseFrequency, Layer.NoisePitchAngle * Mathf.Deg2Rad, 0f)); // set rotation noice GNSKernel.SetVector("_RotationAxis", Layer.RotationNoiseAxis.normalized); // set rotation axis // Scale GNSKernel.SetVector("_BaseScale", Layer.BaseScale); GNSKernel.SetVector("_RandomScale", new Vector2(Layer.MinRandomScale, Layer.MaxRandomScale)); GNSKernel.SetVector("_ScaleNoise", new Vector2(Layer.ScaleNoiseFrequency, Layer.ScaleNoiseAmplitude)); // Paint GNSKernel.SetFloat("_PaintResolution", (float)(int)PaintResolution); GNSKernel.SetVector("_PaintPatchSize", new Vector4(PatchRounded.x, PatchRounded.y)); GNSKernel.SetVector("_TerrainSize", new Vector4(_Terrain.terrainData.size.x, _Terrain.terrainData.size.y, _Terrain.terrainData.size.z, 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 }
private void OnEnable() { ListLabelWidth = 70; // Data GNS_Layer Layer = (GNS_Layer)target; ReorderableList MeshList = AddReorderableList <GNS_Model>("Meshes", Layer.LODModels, (Rect rect, int index, bool isActive, bool isFocused) => { float HalfWidth = rect.width * 0.5f; string Name = (Layer.LODModels[index] != null)?Layer.LODModels[index].name:"Empty Mesh"; Layer.LODModels[index] = (GNS_Model)EditorGUI.ObjectField(new Rect( rect.position.x, rect.position.y, HalfWidth, rect.height ), Layer.LODModels[index], typeof(GNS_Model)); Layer.LODMeshesPercentiles[index] = EditorGUI.Slider(new Rect( rect.position.x + (HalfWidth + 16f), rect.position.y, (HalfWidth) - 16f, rect.height ), "Percentile:", Layer.LODMeshesPercentiles[index], 0f, 100f); }, false); MeshList.onAddCallback = (ReorderableList List) => { Layer.LODModels.Add(null); Layer.LODMeshesPercentiles.Add(100f); }; MeshList.onRemoveCallback = (ReorderableList list) => { Layer.LODModels.RemoveAt(list.index); Layer.LODMeshesPercentiles.RemoveAt(list.index); }; }
public override void OnInspectorGUI() { // Data GNS_Layer Layer = (GNS_Layer)target; // Mesh settings EditorGUILayout.Space(); EditorGUILayout.LabelField("Meshes Settings", EditorStyles.boldLabel); RenderListAt(0); // render mesh list EditorGUILayout.Space(); EditorGUILayout.LabelField("Render Settings", EditorStyles.boldLabel); Layer.Density = EditorGUILayout.Slider(new GUIContent("Layer Density"), Layer.Density, 0f, 1f); EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Rotation Settings", EditorStyles.boldLabel); Layer.RandomPitchAngle = EditorGUILayout.Slider(new GUIContent("Random Pitch Angle"), Layer.RandomPitchAngle, 0f, 90f); Layer.NoisePitchAngle = EditorGUILayout.Slider(new GUIContent("Noise Pitch Angle"), Layer.NoisePitchAngle, 0f, 90f); Layer.RotationNoiseFrequency = EditorGUILayout.Slider(new GUIContent("Rotation Noise Frequency"), Layer.RotationNoiseFrequency, 0f, 10f); Layer.RotationNoiseAxis = EditorGUILayout.Vector3Field(new GUIContent("Rotation Noise Axis"), Layer.RotationNoiseAxis); // check if value has changed Rotation if (EditorGUI.EndChangeCheck()) { ForEachManager((GrassNStuff Manager) => { Manager.RegenerateRotationTextures(); // update managers }); } EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Scale Settings", EditorStyles.boldLabel); Layer.BaseScale = EditorGUILayout.Vector3Field(new GUIContent("Base Scale"), Layer.BaseScale); Layer.MinRandomScale = EditorGUILayout.Slider(new GUIContent("Min Random Scale"), Layer.MinRandomScale, 0f, 5f); Layer.MaxRandomScale = EditorGUILayout.Slider(new GUIContent("Max Random Scale"), Layer.MaxRandomScale, 0f, 5f); Layer.ScaleNoiseAmplitude = EditorGUILayout.Slider(new GUIContent("Scale Noise Amplitude"), Layer.ScaleNoiseAmplitude, 0f, 5f); Layer.ScaleNoiseFrequency = EditorGUILayout.Slider(new GUIContent("Scale Noise Frequency"), Layer.ScaleNoiseFrequency, 0f, 2000f); // check if value has changed Scale if (EditorGUI.EndChangeCheck()) { ForEachManager((GrassNStuff Manager) => { Manager.RegenerateScaleTextures(); // update managers }); } // material settings EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField("Material Settings", EditorStyles.boldLabel); Layer.Color = EditorGUILayout.ColorField(new GUIContent("Main Color"), Layer.Color); Layer.Albedo = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("Albedo"), Layer.Albedo, typeof(Texture2D), false); Layer.Normal = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("Normal"), Layer.Normal, typeof(Texture2D), false); Layer.SpecGloss = (Texture2D)EditorGUILayout.ObjectField(new GUIContent("Specular(R) + Gloss(G)"), Layer.SpecGloss, typeof(Texture2D), false); Layer.SpecularStrength = EditorGUILayout.Slider(new GUIContent("Specular Strength"), Layer.SpecularStrength, 0f, 1f); Layer.GlossStrength = EditorGUILayout.Slider(new GUIContent("Gloss Strength"), Layer.GlossStrength, 0f, 1f); Layer.CutOff = EditorGUILayout.Slider(new GUIContent("Cut Off"), Layer.CutOff, 0f, 1f); Layer.OcclusionHeight = EditorGUILayout.Slider(new GUIContent("Occlusion Height"), Layer.OcclusionHeight, 0f, 10f); Layer.OcclusionStrength = EditorGUILayout.Slider(new GUIContent("Occlusion Strength"), Layer.OcclusionStrength, 0f, 10f); Layer.OcclusionToColor = EditorGUILayout.Slider(new GUIContent("Occlusion To Color"), Layer.OcclusionToColor, 0f, 1f); if (EditorGUI.EndChangeCheck()) { ForEachManager((GrassNStuff Manager) => { Manager.UpdateMaterialBuffers(); // update managers }); } base.OnInspectorGUI(); // draw base EditorUtility.SetDirty(Layer); // set dirty }