using System.Collections; using System.Collections.Generic; using Godot; using System; using System.Threading.Tasks; namespace Rokojori { /** A node to render foliage. The GrassPatch has various settings to create a different styles of grass. It allows to change the shapes of the blades, their number and distribution, their triangle count, rotation and scale, LOD levels and much more. */ [Tool] [GlobalClass] public partial class SceneFoliageData:FoliageData { [Export] public SceneReference sceneReference; public override void Initialize( FoliageRenderLayer renderLayer ) { var particles = renderLayer.renderer.CreateChild(); renderLayer.gpuParticles3D = particles; var processMaterial = new GPUFoliageShaderMaterial(); particles.ProcessMaterial = processMaterial; particles.Lifetime = 0.01f; particles.Explosiveness = 1f; particles.FixedFps = 0; particles.Interpolate = false; particles.FractDelta = false; particles.CustomAabb = Box3.WithSize( 10000 ); processMaterial.positionVariance.Set( renderLayer.renderer.noise ); processMaterial.rotationVariance.Set( renderLayer.renderer.noise ); processMaterial.scaleVariance.Set( renderLayer.renderer.noise ); processMaterial.occupancyVariance.Set( renderLayer.renderer.noise ); renderLayer.gpuFoliageShaderMaterial = processMaterial; var packedScene = sceneReference.LoadScene(); var sceneRoot = packedScene.Instantiate(); this.LogInfo( packedScene, sceneRoot ); var meshInstance = sceneRoot.GetSelfOrChildOf(); particles.DrawPasses = 1; particles.DrawPass1 = meshInstance.Mesh; } } }