public void Start(ComputeShaderContainerGameObject computeShaderContainer) { var commonExecutor = new CommonExecutorUTProxy(); var shaderExecutorObject = new UnityThreadComputeShaderExecutorObject(); var updater = new DesignBodySpotUpdater(new DesignBodySpotChangeCalculator(computeShaderContainer, shaderExecutorObject, commonExecutor, HeightDenormalizer.Identity)); _designBodySpotUpdaterProxy = new DesignBodySpotUpdaterProxy(updater); updater.SetChangesListener(new LambdaSpotPositionChangesListener(null, dict => { foreach (var pair in dict) { _grassGroupsPlanter.GrassGroupSpotChanged(pair.Key, pair.Value); } })); _designBodySpotUpdaterProxy.StartThreading(() => { }); var meshGenerator = new GrassMeshGenerator(); var mesh = meshGenerator.GetGrassBladeMesh(1); var instancingMaterial = new Material(Shader.Find("Custom/Vegetation/Grass.Instanced")); instancingMaterial.enableInstancing = true; var commonUniforms = new UniformsPack(); commonUniforms.SetUniform("_BendingStrength", 0.0f); commonUniforms.SetUniform("_WindDirection", Vector4.one); var instancingContainer = new GpuInstancingVegetationSubjectContainer( new GpuInstancerCommonData(mesh, instancingMaterial, commonUniforms), new GpuInstancingUniformsArrayTemplate(new List <GpuInstancingUniformTemplate>() { new GpuInstancingUniformTemplate("_Color", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_InitialBendingValue", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantBendingStiffness", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantDirection", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_RandSeed", GpuInstancingUniformType.Float), }) ); _globalGpuInstancingContainer = new GlobalGpuInstancingContainer(); var bucketId = _globalGpuInstancingContainer.CreateBucket(instancingContainer); GrassGroupsContainer grassGroupsContainer = new GrassGroupsContainer(_globalGpuInstancingContainer, bucketId); IGrassPositionResolver grassPositionResolver = new SimpleRandomSamplerPositionResolver(); GrassDetailInstancer grassDetailInstancer = new GrassDetailInstancer(); _grassGroupsPlanter = new GrassGroupsPlanter( grassDetailInstancer, grassPositionResolver, grassGroupsContainer, _designBodySpotUpdaterProxy, new LegacyGrass2BladeAspectsGenerator(), GrassDebugUtils.TemplatesDictionary, Repositioner.Identity); }
public void Start(ComputeShaderContainerGameObject computeShaderContainer) { var commonExecutor = new CommonExecutorUTProxy(); var shaderExecutorObject = new UnityThreadComputeShaderExecutorObject(); var updater = new DesignBodySpotUpdater(new DesignBodySpotChangeCalculator(computeShaderContainer, shaderExecutorObject, commonExecutor, HeightDenormalizer.Identity)); _designBodySpotUpdaterProxy = new DesignBodySpotUpdaterProxy(updater); updater.SetChangesListener(new LambdaSpotPositionChangesListener(null, dict => { foreach (var pair in dict) { _grassGroupsPlanter.GrassGroupSpotChanged(pair.Key, pair.Value); } })); _designBodySpotUpdaterProxy.StartThreading(() => { }); var meshGenerator = new GrassMeshGenerator(); var mesh = meshGenerator.GetGrassBillboardMesh(0, 1); var instancingMaterial = new Material(Shader.Find("Custom/Vegetation/GrassBushBillboard.Instanced")); instancingMaterial.enableInstancing = true; /// CLAN var billboardsFileManger = new Grass2BillboardClanFilesManager(); var clan = billboardsFileManger.Load(@"C:\inz\billboards\", new IntVector2(256, 256)); var singleToDuo = new Grass2BakingBillboardClanGenerator(computeShaderContainer, shaderExecutorObject); var bakedClan = singleToDuo.GenerateBakedAsync(clan).Result; /// var commonUniforms = new UniformsPack(); commonUniforms.SetUniform("_BendingStrength", 0.0f); commonUniforms.SetUniform("_WindDirection", Vector4.one); commonUniforms.SetTexture("_DetailTex", bakedClan.DetailTextureArray); commonUniforms.SetTexture("_BladeSeedTex", bakedClan.BladeSeedTextureArray); var instancingContainer = new GpuInstancingVegetationSubjectContainer( new GpuInstancerCommonData(mesh, instancingMaterial, commonUniforms), new GpuInstancingUniformsArrayTemplate(new List <GpuInstancingUniformTemplate>() { new GpuInstancingUniformTemplate("_Color", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_InitialBendingValue", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantBendingStiffness", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_PlantDirection", GpuInstancingUniformType.Vector4), new GpuInstancingUniformTemplate("_RandSeed", GpuInstancingUniformType.Float), new GpuInstancingUniformTemplate("_ArrayTextureIndex", GpuInstancingUniformType.Float), }) ); _globalGpuInstancingContainer = new GlobalGpuInstancingContainer(); var bucketId = _globalGpuInstancingContainer.CreateBucket(instancingContainer); GrassGroupsContainer grassGroupsContainer = new GrassGroupsContainer(_globalGpuInstancingContainer, bucketId); IGrassPositionResolver grassPositionResolver = new PoissonDiskSamplerPositionResolver(new MyRange(1.5f * 0.4f * 10, 10 * 2 * 1.3f)); //IGrassPositionResolver grassPositionResolver = new SimpleRandomSamplerPositionResolver(); GrassDetailInstancer grassDetailInstancer = new GrassDetailInstancer(); _grassGroupsPlanter = new GrassGroupsPlanter( grassDetailInstancer, grassPositionResolver, grassGroupsContainer, _designBodySpotUpdaterProxy, new Grass2BushAspectsGenerator(bakedClan), //todo! GrassDebugUtils.BushTemplates, Repositioner.Identity); }