// Update voids private void UpdatePatchCullingGroups() { if (Application.isPlaying) // only generate if application is playing { InitializeRenderer(); // Cache values Vector3 _CacheBoundSize = BoundSize; Vector3 _TerrainPosition = _Terrain.transform.position; for (int i = 0; i < Layers.Count; i++) { SetKernelSettings(Layers[i]); // update kernel settings if (_HeightBuffer == null) { _HeightBuffer = CreateBuffer((int)PatchCount.x, (int)PatchCount.y); } GNSKernel.SetTexture("_PaintTexture", _TerrainHeightBuffer); // set texture paint buffer Graphics.Blit(null, _HeightBuffer, GNSKernel, 4); // Update paint buffer Texture2D Tex = _HeightBuffer.ToTexture2D(); // Convert Buffer to texture Color[] Colors = Tex.GetPixels(); for (int x = 0; x < Colors.Length; x++) { Renderer.UpdatePatchHeight(x, (_CacheBoundSize.y * Colors [x].r) + _TerrainPosition.y); } } } }
// 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)); }
private void SetKernelWindSettings() { GNSKernel.SetVector("_BaseScale", new Vector3(1, 1, 1)); GNSKernel.SetVector("_ScaleNoise", new Vector2(_WindNoiseFrequency, _WindNoiseAmplitude)); }