private List <Grass2PositionedEntity> PositionEntitiesFromAspect(Grass2Aspect aspect, DesignBodySpotModification modification) { var flatPos = aspect.FlatPos; //var rotation = Quaternion.LookRotation(modification.Normal.normalized).eulerAngles * Mathf.Deg2Rad; //TODO recreate if (!WarningWasSaid) { Debug.Log("W4 WARNING. GRASS ROTATION IS NOT SET. DO STH!!!"); WarningWasSaid = true; } var centerTriplet = new MyTransformTriplet( new Vector3(flatPos.x, 0, flatPos.y), Vector3.zero, //rotation, Vector3.one ); if (modification.SpotData != null) { centerTriplet.Position = new Vector3(centerTriplet.Position.x, modification.SpotData.Height, centerTriplet.Position.z); } var centerMatrix = centerTriplet.ToLocalToWorldMatrix(); var additionalUniforms = new UniformsPack(); if (modification.Uniforms != null) { additionalUniforms = modification.Uniforms; } return(aspect.Entities.Select(c => new Grass2PositionedEntity() { LocalToWorldMatrix = centerMatrix * c.DeltaTransformTriplet.ToLocalToWorldMatrix(), Uniforms = UniformsPack.MergeTwo(c.Uniforms, additionalUniforms) }).ToList()); }
public Grass2Aspect GenerateAspect(UnplantedGrassInstance unplantedInstance, Vector2 flatPosition) { var rotationInRad = unplantedInstance.FlatRotationInRadians; MyTransformTriplet transformTriplet = new MyTransformTriplet( new Vector3(0, 0, 0), new Vector3(Mathf.Deg2Rad * unplantedInstance.InitialBendingValue * 20, rotationInRad, 0), //TODO i use properties from Grass2 as inputs to EVegetation unplantedInstance.Size); UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_Color", unplantedInstance.Color); return(new Grass2Aspect() { Entities = new List <Grass2Entity>() { new Grass2Entity() { DeltaTransformTriplet = transformTriplet, Uniforms = uniforms, FlatRotation = rotationInRad } }, FlatPos = flatPosition }); }
private async Task <Texture> GenerateTextureWithMipMapsAsync(TextureWithSize tex) { IntVector2 outTextureSize = tex.Size; UniformsPack pack = new UniformsPack(); pack.SetTexture("_SourceTexture", tex.Texture); ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true); TextureRenderingTemplate template = new TextureRenderingTemplate() { CanMultistep = false, Coords = new MyRectangle(0, 0, 1, 1), OutTextureInfo = outTextureInfo, RenderTextureFormat = RenderTextureFormat.RFloat, ShaderName = "Custom/TerGen/Cutting", UniformPack = pack, CreateTexture2D = false, RenderTextureMipMaps = true }; var outTex = await _rendererProxy.AddOrder(template); await _commonExecutor.AddAction(() => outTex.wrapMode = TextureWrapMode.Clamp); return(outTex); }
public async Task <List <GRingSurfaceDetail> > ProvideSurfaceDetail() { var stainResourceWithCoords = await _stainTerrainServiceProxy.RetriveResource(_inGamePosition); var uniformsPack = new UniformsPack(); uniformsPack.SetTexture("_PaletteTex", stainResourceWithCoords.Resource.TerrainPaletteTexture); uniformsPack.SetTexture("_PaletteIndexTex", stainResourceWithCoords.Resource.PaletteIndexTexture); uniformsPack.SetTexture("_ControlTex", stainResourceWithCoords.Resource.ControlTexture); uniformsPack.SetUniform("_TerrainStainUv", stainResourceWithCoords.Coords.ToVector4()); uniformsPack.SetUniform("_TerrainTextureSize", stainResourceWithCoords.Resource.TerrainTextureSize); uniformsPack.SetUniform("_PaletteMaxIndex", stainResourceWithCoords.Resource.PaletteMaxIndex); return(new List <GRingSurfaceDetail>() { new GRingSurfaceDetail() { UniformsWithKeywords = new UniformsWithKeywords() { Keywords = new ShaderKeywordSet(), Uniforms = uniformsPack }, ShaderName = "Custom/Terrain/Ring1" } }); }
private static UniformsPack CreatePackWithPointerUniform(EPropElevationPointer elevationId) { var uniformsPack = new UniformsPack(); uniformsPack.SetUniform("_Pointer", CastUtils.BitwiseCastUIntToFloat(elevationId.Value)); return(uniformsPack); }
public override void OnInspectorGUI() { DrawDefaultInspector(); var terrainLoader = (TerrainLoaderGameObject)target; _seedValue = EditorGUILayout.Slider("Seed value", _seedValue, 0.0f, 10.0f, new GUILayoutOption[] {}); _heightMultiplier = EditorGUILayout.Slider("_heightMultiplier", _heightMultiplier, 0.0f, 10.0f, new GUILayoutOption[] {}); var uniformsPack = new UniformsPack(); uniformsPack.SetUniform("_Seed", _seedValue); uniformsPack.SetUniform("_HeightMultiplier", _heightMultiplier); if (GUILayout.Button("RegenerateTextureObject")) { terrainLoader.Ring1Tree.RegenerateTextureShowingObject(uniformsPack); } if (GUILayout.Button("RegenerateTerrainObject")) { terrainLoader.Ring1Tree.RegenerateTerrainShowingObject(uniformsPack); } if (GUILayout.Button("UpdateLod")) { terrainLoader.UpdateHeightmap(); } }
public Grass2Aspect GenerateAspect(UnplantedGrassInstance unplantedInstance, Vector2 flatPosition) { var rotationInRad = unplantedInstance.FlatRotationInRadians; MyTransformTriplet transformTriplet = new MyTransformTriplet( new Vector3(0, 0, 0), new Vector3(0, rotationInRad, 0), unplantedInstance.Size); UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_InitialBendingValue", unplantedInstance.InitialBendingValue); uniforms.SetUniform("_PlantBendingStiffness", unplantedInstance.InitialBendingStiffness); uniforms.SetUniform("_PlantDirection", new Vector4(Mathf.Sin(rotationInRad), Mathf.Cos(rotationInRad), 0, 0)); //todo! uniforms.SetUniform("_Color", unplantedInstance.Color); return(new Grass2Aspect() { Entities = new List <Grass2Entity>() { new Grass2Entity() { DeltaTransformTriplet = transformTriplet, Uniforms = uniforms, FlatRotation = rotationInRad } }, FlatPos = flatPosition }); }
public async Task <TextureWithSize> ExtractMipmapAsync(TextureWithSize inputTexture, RenderTextureFormat format, int mipmapLevelToExtract) { var pack = new UniformsPack(); pack.SetTexture("_InputTexture", inputTexture.Texture); pack.SetUniform("_MipmapLevelToExtract", mipmapLevelToExtract); var outSize = ComputeMipmappedOutSize(inputTexture.Size, mipmapLevelToExtract); var newTexture = await _textureRenderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = true, Coords = new MyRectangle(0, 0, 1, 1), CreateTexture2D = false, OutTextureInfo = new ConventionalTextureInfo(outSize.X, outSize.Y, TextureFormat.ARGB32, true), RenderTextureFormat = format, RenderTextureMipMaps = true, ShaderName = "Custom/Tool/ExtractMipmap", UniformPack = pack, }); return(new TextureWithSize() { Texture = newTexture, Size = outSize }); }
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); }
private async Task <GRingTerrainId> CreateTerrainAsync() { //Debug.Log("G34 Start"); var triplet = _tripletProvider.ProvideTriplet(); var meshDetails = await _terrainMeshProvider.ProvideMeshDetailsAsync(); //Debug.Log("G35 Mesh detail"); var groundShapeDetails = await _groundShapeProvider.ProvideGroundTextureDetail(); //Debug.Log("G36 Ground shape detail"); var surfaceProviderDetails = await _surfaceProvider.ProvideSurfaceDetail(); var weldingDetails = _weldingUpdater.ProvideWeldingDetails(groundShapeDetails.HeightDetailOutput, meshDetails.HeightmapLod); _groundShapeToken = groundShapeDetails.GroundShapeToken; var creationTemplatesList = new List <Ring1GroundPieceCreationTemplate>(); int layerIndex = surfaceProviderDetails.Count; foreach (var surfaceDetail in surfaceProviderDetails) { UniformsPack pack = new UniformsPack(); pack.MergeWith(meshDetails.Uniforms); pack.MergeWith(groundShapeDetails.Uniforms); pack.MergeWith(surfaceDetail.UniformsWithKeywords.Uniforms); pack.MergeWith(weldingDetails.UniformsPack); var keywordsSet = ShaderKeywordSet.Merge(groundShapeDetails.ShaderKeywordSet, surfaceDetail.UniformsWithKeywords.Keywords); var layerTriplet = triplet.Clone(); var oldPosition = layerTriplet.Position; layerTriplet.Position = new Vector3(oldPosition.x, oldPosition.y + layerIndex / 2000f, oldPosition.z); creationTemplatesList.Add( new Ring1GroundPieceCreationTemplate() { Name = $"TerrainElementLayer l:{layerIndex} ql:{_flatLod.SourceQuadLod} fl:{_flatLod.ScalarValue} wd {weldingDetails.WeldingIndex}", ParentGameObject = _parentObject, PieceMesh = meshDetails.Mesh, TransformTriplet = layerTriplet, ShaderName = surfaceDetail.ShaderName, ShaderKeywordSet = keywordsSet, Uniforms = pack, Modifier = weldingDetails.Modifier }); layerIndex--; } return(new GRingTerrainId() { ElementsIds = creationTemplatesList.Select(c => _orderGrabber.AddCreationOrder(c)).ToList() }); }
private Texture2D RenderConventionalRing1Texture(Texture2D inputTexture, UniformsPack uniformsPack) { var conventionalRing1Texture = _textureRenderer.RenderTexture("Custom/Heightmap/Ring1Creator", inputTexture, uniformsPack, new RenderTextureInfo(RING1_WIDTH, RING1_HEIGHT, RenderTextureFormat.ARGB32), new ConventionalTextureInfo(RING1_WIDTH, RING1_HEIGHT, TextureFormat.ARGB32)); return(conventionalRing1Texture); }
public GRingWeldingDetail ProvideWeldingDetails(TerrainDetailElementOutput heightmapDetail, int heightmapOffset) { if (!_weldingPack.WeldingEnabled) { return(new GRingWeldingDetail() { Modifier = new Ring1GroundPieceModifier(), UniformsPack = new UniformsPack() }); } if (_weldingPack == null) { Debug.LogError("WARNING. Welding pack not set!!. Only for testing!!"); return(new GRingWeldingDetail() { Modifier = new Ring1GroundPieceModifier(), UniformsPack = new UniformsPack() }); } var groundPieceModifier = new Ring1GroundPieceModifier(); _weldingTerrainIndex = _weldingPack.RegisterTerrain(new WeldingRegistrationTerrain() { Texture = heightmapDetail.TokenizedElement.DetailElement.Texture, DetailGlobalArea = heightmapDetail.TokenizedElement.DetailElement.DetailArea, Resolution = heightmapDetail.TokenizedElement.DetailElement.Resolution, TerrainLod = heightmapOffset, UvCoordsPositions2D = heightmapDetail.UvBase }, (t) => groundPieceModifier.ModifyMaterial((material) => { t.SetToMaterial(material); })); var pack = new UniformsPack(); pack.SetTexture("_WeldTexture", _weldingPack.WeldTexture.Texture); var emptyUvs = new TerrainWeldUvs(); pack.SetUniform("_LeftWeldTextureUvRange", emptyUvs.LeftUv); pack.SetUniform("_RightWeldTextureUvRange", emptyUvs.RightUv); pack.SetUniform("_TopWeldTextureUvRange", emptyUvs.TopUv); pack.SetUniform("_BottomWeldTextureUvRange", emptyUvs.BottomUv); return(new GRingWeldingDetail() { UniformsPack = pack, Modifier = groundPieceModifier, WeldingIndex = _weldingTerrainIndex }); }
public async Task <TextureWithCoords> ApplyFeatureAsync(TextureWithCoords texture, TerrainCardinalResolution resolution, bool canMultistep) { var configuration = _configurations[resolution]; var detailedHeightmapArray = await TaskUtils .RunInThreadPool( () => { var creator = new DiamondSquareCreator(_randomProviderGenerator.GetRandom()); var initialArray = creator.CreateDiamondSquareNoiseArray( texture.TextureSize, configuration.DiamondSquareWorkingArrayLength); return(initialArray); }); var detailedTexture = await _commonExecutor .AddAction(() => HeightmapUtils.CreateTextureFromHeightmap(detailedHeightmapArray)); UniformsPack pack = new UniformsPack(); pack.SetTexture("_Texture1", texture.Texture); pack.SetTexture("_Texture2", detailedTexture); pack.SetUniform("_Texture2Weight", configuration.DiamondSquareWeight); var renderCoords = new MyRectangle(0, 0, 1, 1); var outTextureSize = texture.TextureSize; ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true); TextureRenderingTemplate template = new TextureRenderingTemplate() { CanMultistep = canMultistep, Coords = renderCoords, OutTextureInfo = outTextureInfo, RenderTextureFormat = RenderTextureFormat.RFloat, ShaderName = "Custom/TerrainCreation/DiamondSquareTextureAddingPlain", UniformPack = pack, CreateTexture2D = false }; var renderedTexture = await _rendererProxy.AddOrder(template); await _commonExecutor.AddAction(() => GameObject.Destroy(detailedTexture)); return(new TextureWithCoords(sizedTexture: new TextureWithSize() { Texture = renderedTexture, Size = texture.TextureSize }, coords: texture.Coords)); }
private void AlignUniforms() { var debugRendererPack = ShaderCustomizationUtils.RetriveUniforms(StrokeSeedGridMapDebugRendererMaterial); var stage1Pack = ShaderCustomizationUtils.RetriveUniforms(Stage1RenderingMaterial); var geometryPack = ShaderCustomizationUtils.RetriveUniforms(SelectedGeometryMaterial); _masterUniformsPack = UniformsPack.MergeTwo(UniformsPack.MergeTwo(debugRendererPack, stage1Pack), geometryPack).WithoutDebugUniforms(); new List <Material>() { StrokeSeedGridMapDebugRendererMaterial, Stage1RenderingMaterial, SelectedGeometryMaterial }.ForEach(m => { ShaderCustomizationUtils.FilterNonPresentUniforms(m, _masterUniformsPack).SetUniformsToMaterial(m); }); }
public async Task <GRingMeshDetail> ProvideMeshDetailsAsync() { var mesh = await _meshGenerator.AddOrder( () => PlaneGenerator.CreateFlatPlaneMesh(_gameObjectMeshResolution.X, _gameObjectMeshResolution.Y)); var pack = new UniformsPack(); pack.SetUniform("_HeightmapLodOffset", _heightmapLodOffset); return(new GRingMeshDetail() { Mesh = mesh, Uniforms = pack, HeightmapLod = _heightmapLodOffset }); }
public DebugFlatTerrainShapeDb(UTTextureRendererProxy textureRenderer) { var size = new IntVector2(241, 241); var tex = new Texture2D(size.X, size.Y, TextureFormat.ARGB32, true, true); for (int x = 0; x < size.X; x++) { for (int y = 0; y < size.Y; y++) { tex.SetPixel(x, y, new Color(0, 0, 0, 0)); } } tex.Apply(); _blankTexture = new TextureWithSize() { Texture = tex, Size = size }; var pack = new UniformsPack(); pack.SetTexture("_HeightmapTex", tex); pack.SetUniform("_HeightMultiplier", 80); ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(size.X, size.Y, TextureFormat.ARGB32, true); var renderCoords = new MyRectangle(0, 0, 1, 1); TextureRenderingTemplate template = new TextureRenderingTemplate() { CanMultistep = false, Coords = renderCoords, OutTextureInfo = outTextureInfo, RenderTextureFormat = RenderTextureFormat.ARGB32, ShaderName = "Custom/Terrain/NormalmapGenerator", UniformPack = pack, CreateTexture2D = false }; var outNormalTex = textureRenderer.AddOrder(template).Result; _normalTexture = new TextureWithSize() { Size = size, Texture = outNormalTex }; }
private async Task <UniformsPack> CreateUniformsPack(Ring1Node ring1Node) { UniformsPack pack = new UniformsPack(); var terrainOutput = await _terrainShapeDb.Query(new TerrainDescriptionQuery() { QueryArea = Ring1Node.Ring1Position, RequestedElementDetails = new List <TerrainDescriptionQueryElementDetail>() { new TerrainDescriptionQueryElementDetail() { //PixelsPerMeter = 10, //todo Resolution = TerrainCardinalResolution.FromRing1NodeLodLevel(Ring1Node.QuadLodLevel), Type = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY }, new TerrainDescriptionQueryElementDetail() { //PixelsPerMeter = 10, //todo Resolution = TerrainCardinalResolution.FromRing1NodeLodLevel(Ring1Node.QuadLodLevel), Type = TerrainDescriptionElementTypeEnum.TESSALATION_REQ_ARRAY }, } }); var uvPosition = _coordsCalculator.CalculateUvPosition(Ring1Node.Ring1Position); //_submapTextures.UvPosition; var heightmapTexture = terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY); var tessalationTexture = terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.TESSALATION_REQ_ARRAY); pack.SetUniform("_TerrainTextureUvPositions", new Vector4(uvPosition.X, uvPosition.Y, uvPosition.Width, uvPosition.Height)); pack.SetTexture("_HeightmapTex", heightmapTexture.TokenizedElement.DetailElement.Texture.Texture); pack.SetTexture("_TessalationTex", tessalationTexture.TokenizedElement.DetailElement.Texture.Texture); pack.SetTexture("_LodTexture", _visibilityTexture); pack.SetUniform("_MaxHeight", 100); pack.SetUniform("_LodTextureUvOffset", _coordsCalculator.CalculateTextureUvLodOffset(ring1Node.Ring1Position)); pack.SetUniform("_BaseTrianglesCount", _coordsCalculator.CalculateGameObjectSize(ring1Node.Ring1Position).X - 1); return(pack); }
public async Task <TextureWithCoords> ApplyFeatureAsync(TextureWithCoords inputTexture, TerrainCardinalResolution resolution, bool CanMultistep = false) { if (!TaskUtils.GetGlobalMultithreading()) { Preconditions.Assert(inputTexture.Texture.width == inputTexture.Texture.height, "Only square inputTextures are supported"); } UniformsPack pack = new UniformsPack(); await _commonExecutor.AddAction(() => inputTexture.Texture.filterMode = FilterMode.Point); pack.SetTexture("_SourceTexture", inputTexture.Texture); pack.SetUniform("_InputGlobalCoords", inputTexture.Coords.ToVector4()); pack.SetUniform("_QuantingResolution", inputTexture.TextureSize.X - 1); var configuration = _configurations[resolution]; pack.SetUniform("_DetailResolutionMultiplier", configuration.DetailResolutionMultiplier); pack.SetUniform("_NoiseStrengthMultiplier", configuration.NoiseStrengthMultiplier); var renderCoords = new MyRectangle(0, 0, 1, 1); var outTextureSize = inputTexture.TextureSize; ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo(outTextureSize.X, outTextureSize.Y, TextureFormat.ARGB32, true); TextureRenderingTemplate template = new TextureRenderingTemplate() { CanMultistep = false, Coords = renderCoords, OutTextureInfo = outTextureInfo, RenderTextureFormat = RenderTextureFormat.RFloat, ShaderName = "Custom/TerrainCreation/NoiseAddingPlain", UniformPack = pack, CreateTexture2D = false }; return(new TextureWithCoords(sizedTexture: new TextureWithSize() { Texture = await _rendererProxy.AddOrder(template), Size = inputTexture.TextureSize }, coords: inputTexture.Coords)); }
public static GameObject CreateFlatTerrainPlane(Point2D gameObjectSize, MyRectangle inGamePosition, UniformsPack pack) { var gameObject = new GameObject("Ring1 terrain object " + inGamePosition.ToString()); var terrainMaterial = new Material(Shader.Find("Custom/Terrain/Terrain1")); pack.SetUniformsToMaterial(terrainMaterial); gameObject.AddComponent <MeshRenderer>(); gameObject.GetComponent <Renderer>().material = terrainMaterial; gameObject.AddComponent <MeshFilter>().mesh = PlaneGenerator.CreateFlatPlaneMesh(gameObjectSize.X, gameObjectSize.Y); gameObject.transform.localScale = new Vector3(inGamePosition.Width, 1, inGamePosition.Height); gameObject.transform.localPosition = new Vector3(inGamePosition.X, 0, inGamePosition.Y); return(gameObject); }
public Grass2Aspect GenerateAspect(UnplantedGrassInstance unplantedInstance, Vector2 flatPosition) { var entityRotationInRad = unplantedInstance.FlatRotationInRadians; var usedBillboardIndex = _billboardClan.QueryRandom((int)(entityRotationInRad * 543.21)); //todo seed var entities = new List <Grass2Entity>(); int billboardsCount = 3; for (int i = 0; i < billboardsCount; i++) { var additionalRotation = ((Mathf.PI) / (billboardsCount)) * i; var finalRotationInRad = additionalRotation + entityRotationInRad; MyTransformTriplet transformTriplet = new MyTransformTriplet( new Vector3(0, 0, 0), new Vector3(0, finalRotationInRad, 0), unplantedInstance.Size); UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_InitialBendingValue", unplantedInstance.InitialBendingValue); uniforms.SetUniform("_PlantBendingStiffness", unplantedInstance.InitialBendingStiffness); uniforms.SetUniform("_PlantDirection", new Vector4(Mathf.Sin(finalRotationInRad), Mathf.Cos(finalRotationInRad), finalRotationInRad, 0)); //todo! uniforms.SetUniform("_Color", unplantedInstance.Color); uniforms.SetUniform("_ArrayTextureIndex", usedBillboardIndex); var newEntity = new Grass2Entity() { DeltaTransformTriplet = transformTriplet, Uniforms = uniforms, FlatRotation = finalRotationInRad }; entities.Add(newEntity); } return(new Grass2Aspect() { Entities = entities, FlatPos = flatPosition }); }
private async Task <GRingTerrainId> CreateTerrainAsync() { var triplet = _tripletProvider.ProvideTriplet(); var mesh = await _meshGeneratorUtProxy.AddOrder(() => PlaneGenerator.CreateFlatPlaneMesh(65, 65)); var creationTemplatesList = new List <Ring1GroundPieceCreationTemplate>(); int layerIndex = 0; UniformsPack pack = new UniformsPack(); pack.SetUniform("_LodLevel", _flatLod.ScalarValue); pack.SetUniform("_NodeId", LastId); var groundShapeDetails = await _groundShapeProvider.ProvideGroundTextureDetail(); _groundShapeToken = groundShapeDetails.GroundShapeToken; pack.MergeWith(groundShapeDetails.Uniforms); creationTemplatesList.Add( new Ring1GroundPieceCreationTemplate() { Name = $"TerrainElementLayer l:{layerIndex} fl:{_flatLod.ScalarValue}, X:{LastId++}", ParentGameObject = _parentObject, PieceMesh = mesh, TransformTriplet = triplet, ShaderName = "Custom/Terrain/DebugTerrainedLod", //ShaderName = "Custom/Terrain/Ring0", ShaderKeywordSet = groundShapeDetails.ShaderKeywordSet, Uniforms = pack, Modifier = new Ring1GroundPieceModifier() }); var toReturn = new GRingTerrainId() { ElementsIds = creationTemplatesList.Select(c => _orderGrabber.AddCreationOrder(c)).ToList() }; return(toReturn); }
protected override async Task <UInt32> CreateTerrainAsync() { var ring1Position = Ring1Node.Ring1Position; var xOffset = _globalHeightmap.Width * ring1Position.X; var yOffset = _globalHeightmap.Height * ring1Position.Y; var width = _globalHeightmap.Width * ring1Position.Width; var height = _globalHeightmap.Height * ring1Position.Height; var subArray = slicer.GetSubarrayWithEmptyMarginsSafe(_globalHeightmap.HeightmapAsArray, (int)xOffset, (int)yOffset, (int)width, (int)height); Point2D newGameObjectSize = new Point2D(33, 33); var simplifiedMap = simplyfyer.SimplyfyHeightmap(new HeightmapArray(subArray), newGameObjectSize.X - 1, newGameObjectSize.Y - 1); var mesh = await _meshGenerator.AddOrder( () => PlaneGenerator.CreatePlaneMesh(1, 1, simplifiedMap.HeightmapAsArray)); UniformsPack pack = await CreateUniformsPack(Ring1Node); var inGamePosition = _coordsCalculator.CalculateGlobalObjectPosition(Ring1Node.Ring1Position); var triplet = new MyTransformTriplet(new Vector3(inGamePosition.X, 0, inGamePosition.Y), Vector3.zero, new Vector3(inGamePosition.Width, 1, inGamePosition.Height)); var creationTemplate = new Ring1GroundPieceCreationTemplate() { Name = "Ring1 terrain object " + inGamePosition.ToString(), ParentGameObject = ParentObject, PieceMesh = mesh, ShaderName = "Custom/Terrain/Ring1DirectHeight", TransformTriplet = triplet, Uniforms = pack }; var objectId = OrderGrabber.AddCreationOrder(creationTemplate); return(objectId); }
public Texture2D WrapTexture(Texture2D inputTexture) { UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_Margin", _configuration.Margin); uniforms.SetTexture("_InputTex", inputTexture); var outSize = (new Vector2(inputTexture.width, inputTexture.height) / (1 + 2 * _configuration.Margin)).ToIntVector2(); outSize = new IntVector2(Mathf.ClosestPowerOfTwo(outSize.X), Mathf.ClosestPowerOfTwo(outSize.Y)); return((Texture2D)_textureRenderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, Coords = new MyRectangle(0, 0, 1, 1), CreateTexture2D = true, OutTextureInfo = new ConventionalTextureInfo(outSize.X, outSize.Y, inputTexture.format, false), UniformPack = uniforms, ShaderName = "Custom/NPR/ArtMapWrapping" }).Result); //todo async }
public async Task <Texture2D> GenerateBillboardImageAsync(int bladesCount, float seed) { UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_Seed", seed); uniforms.SetUniform("_BladesCount", bladesCount); return((await _textureRenderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, Coords = new MyRectangle(0, 0, 1, 1), CreateTexture2D = true, OutTextureInfo = new ConventionalTextureInfo(_configuration.BillboardSize.X, _configuration.BillboardSize.Y, TextureFormat.ARGB32, true), Keywords = new ShaderKeywordSet(), RenderTextureFormat = RenderTextureFormat.ARGB32, RenderTextureMipMaps = false, ShaderName = "Custom/Precomputation/GrassBushBillboardGenerator", UniformPack = uniforms })) as Texture2D); }
public Task PlaceSegmentAsync(Texture segmentTexture, PlacementDetails placementDetails) { var segmentPlacement0 = CalculateSegmentPlacement(placementDetails.ModuledPositionInGrid); UniformsPack uniforms = new UniformsPack(); uniforms.SetTexture("_SegmentSurfaceTexture", segmentTexture); uniforms.SetUniform("_SegmentCoords", segmentPlacement0.Uvs.ToVector4()); uniforms.SetUniform("_TextureArraySliceIndex", _ceilArraySliceIndex); return(_renderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, CreateTexture2D = false, RenderTextureToModify = _floorTextureArray, ShaderName = "Custom/ESurface/SegmentPlacer", UniformPack = uniforms, RenderingRectangle = segmentPlacement0.Pixels, RenderTargetSize = _floorTextureSize, RenderTextureArraySlice = _ceilArraySliceIndex })); }
public IntensityFieldFigure Generate(RandomFieldNature nature, float seed, MyRectangle segmentCoords) //todo use nature { UniformsPack uniforms = new UniformsPack(); uniforms.SetUniform("_Seed", seed); uniforms.SetUniform("_Coords", new Vector4(segmentCoords.X, segmentCoords.Y, segmentCoords.Width, segmentCoords.Height)); Vector2 imageSize = new Vector2( (int)Mathf.Round(_configuration.PixelsPerUnit.x * segmentCoords.Width), (int)Mathf.Round(_configuration.PixelsPerUnit.y * segmentCoords.Height) ); RenderTextureInfo renderTextureInfo = new RenderTextureInfo( (int)imageSize.x, (int)imageSize.y, RenderTextureFormat.ARGB32 ); ConventionalTextureInfo outTextureInfo = new ConventionalTextureInfo( (int)imageSize.x, (int)imageSize.y, TextureFormat.ARGB32 ); Texture2D outTexture = _textureRenderer.RenderTexture(_shaderName, _inputBlankTexture, uniforms, renderTextureInfo, outTextureInfo); var toReturn = CopyToRandomFieldFigure(outTexture); if (DebugLastGeneratedTexture != null) { GameObject.Destroy(DebugLastGeneratedTexture); } DebugLastGeneratedTexture = outTexture; //GameObject.Destroy(outTexture); return(toReturn); }
public async Task <List <GRingSurfaceDetail> > ProvideSurfaceDetail() { var devisedPatches = await _patchesCreator.CreatePatchAsync(_inGamePosition.ToRectangle(), _flatLod.ScalarValue); Preconditions.Assert(devisedPatches.Count <= 1, $"More than one patches created: {devisedPatches.Count}, rect is {_inGamePosition}"); if (!devisedPatches.Any()) { return(new List <GRingSurfaceDetail>()); } var onlyPatch = devisedPatches.First(); var stampedSlice = await _patchStamper.FinalizeGPatchCreation(onlyPatch, _flatLod.ScalarValue); if (stampedSlice != null) { UniformsPack pack = new UniformsPack(); pack.SetTexture("_MainTex", stampedSlice.ColorStamp); pack.SetTexture("_NormalTex", stampedSlice.NormalStamp); var uniforms = new UniformsWithKeywords() { Uniforms = pack, Keywords = new ShaderKeywordSet() }; return(new List <GRingSurfaceDetail>() { new GRingSurfaceDetail() { ShaderName = "Custom/Terrain/Ring2Stamped", UniformsWithKeywords = uniforms } }); } return(new List <GRingSurfaceDetail>()); }
private async Task <UniformsPack> CreateUniformsPack( List <TerrainDescriptionQueryElementDetail> queryElementDetails, UniformsPack uniformsPack, StainTerrainResourceWithCoords stainResourceWithCoords) { var terrainDetailAreaPosition = _coordsCalculator.CalculateGlobalObjectPosition(Ring1Node.Ring1Position); var terrainOutput = await _terrainShapeDb.Query(new TerrainDescriptionQuery() { QueryArea = terrainDetailAreaPosition, RequestedElementDetails = queryElementDetails }); var heightmapTexture = terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY); uniformsPack.SetTexture("_HeightmapTex", heightmapTexture.TokenizedElement.DetailElement.Texture.Texture); uniformsPack.SetUniform("_HeightmapUv", heightmapTexture.UvBase.ToVector4()); if (terrainOutput.HasElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY)) { var normalAsTexture = terrainOutput.GetElementOfType(TerrainDescriptionElementTypeEnum.NORMAL_ARRAY); uniformsPack.SetTexture("_NormalmapTex", normalAsTexture.TokenizedElement.DetailElement.Texture.Texture); uniformsPack.SetUniform("_NormalmapUv", normalAsTexture.UvBase.ToVector4()); } uniformsPack.SetTexture("_PaletteTex", stainResourceWithCoords.Resource.TerrainPaletteTexture); uniformsPack.SetTexture("_PaletteIndexTex", stainResourceWithCoords.Resource.PaletteIndexTexture); uniformsPack.SetTexture("_ControlTex", stainResourceWithCoords.Resource.ControlTexture); uniformsPack.SetUniform("_TerrainStainUv", stainResourceWithCoords.Coords.ToVector4()); uniformsPack.SetUniform("_TerrainTextureSize", stainResourceWithCoords.Resource.TerrainTextureSize); uniformsPack.SetUniform("_PaletteMaxIndex", stainResourceWithCoords.Resource.PaletteMaxIndex); return(uniformsPack); }
protected override async Task <UInt32> CreateTerrainAsync() { //todo DOPISZ REAGOWANIE NA ZNIKNIeCIE elementu terenu - trzeba odeslac do TerrainShapeDb informacje o odblokowaniu tekstury!! var creationDetails = CalculateQueryDetails(Ring1Node.QuadLodLevel); var gameObjectMeshResolution = creationDetails.TerrainMeshResolution; //new IntVector2(241, 241); var inGamePosition = _coordsCalculator.CalculateGlobalObjectPosition(Ring1Node.Ring1Position); var mesh = await _meshGenerator.AddOrder( () => PlaneGenerator.CreateFlatPlaneMesh(gameObjectMeshResolution.X, gameObjectMeshResolution.Y)); var debugTestDivider = 240f; var triplet = new MyTransformTriplet( new Vector3(inGamePosition.X / debugTestDivider, 0, inGamePosition.Y / debugTestDivider), Vector3.zero, new Vector3(inGamePosition.Width / debugTestDivider, 20, inGamePosition.Height / debugTestDivider)); //todo! var stainResourceWithCoords = await _stainTerrainServiceProxy.RetriveResource(inGamePosition); UniformsPack pack = await CreateUniformsPack(creationDetails.QueryElementDetails, creationDetails.Pack, stainResourceWithCoords); var creationTemplate = new Ring1GroundPieceCreationTemplate() { Name = "Ring1 terrain object " + inGamePosition.ToString(), ParentGameObject = ParentObject, PieceMesh = mesh, ShaderName = "Custom/Terrain/Ring1", TransformTriplet = triplet, Uniforms = pack, ShaderKeywordSet = creationDetails.KeywordSet }; var objectId = OrderGrabber.AddCreationOrder(creationTemplate); return(objectId); }
private GroundPieceCreationDetails CalculateQueryDetails(int quadLodLevel) { TerrainCardinalResolution detailResolution = TerrainCardinalResolution.MIN_RESOLUTION; int meshLodPower = 0; bool directNormalCalculation = false; if (quadLodLevel == 1) { detailResolution = TerrainCardinalResolution.MIN_RESOLUTION; meshLodPower = 3; } else if (quadLodLevel == 2) { detailResolution = TerrainCardinalResolution.MIN_RESOLUTION; meshLodPower = 3; } else if (quadLodLevel == 3) { detailResolution = TerrainCardinalResolution.MIN_RESOLUTION; meshLodPower = 2; } else if (quadLodLevel == 4) { detailResolution = TerrainCardinalResolution.MID_RESOLUTION; meshLodPower = 2; } else if (quadLodLevel == 5) { detailResolution = TerrainCardinalResolution.MID_RESOLUTION; meshLodPower = 1; } else if (quadLodLevel == 6) { detailResolution = TerrainCardinalResolution.MID_RESOLUTION; meshLodPower = 0; directNormalCalculation = true; } else if (quadLodLevel == 7) { detailResolution = TerrainCardinalResolution.MAX_RESOLUTION; meshLodPower = 0; directNormalCalculation = true; } //else if (lodLevel == 8) //{ // detailResolution = TerrainCardinalResolution.MAX_RESOLUTION; // meshLodPower = 0; //} else { Preconditions.Fail("Unsupported lod level: " + quadLodLevel); } int baseMeshResolution = 240; int finalMeshResolution = Mathf.RoundToInt(baseMeshResolution / Mathf.Pow(2, meshLodPower)); IntVector2 terrainMeshResolution = new IntVector2(finalMeshResolution + 1, finalMeshResolution + 1); var queryElementDetails = new List <TerrainDescriptionQueryElementDetail>() { new TerrainDescriptionQueryElementDetail() { Resolution = detailResolution, Type = TerrainDescriptionElementTypeEnum.HEIGHT_ARRAY }, }; if (!directNormalCalculation) { queryElementDetails.Add( new TerrainDescriptionQueryElementDetail() { Resolution = detailResolution, Type = TerrainDescriptionElementTypeEnum.NORMAL_ARRAY } ); } var pack = new UniformsPack(); pack.SetUniform("_LodLevel", quadLodLevel); pack.SetUniform("_HeightmapLodOffset", meshLodPower); List <string> keywords = new List <string>(); if (directNormalCalculation) { keywords.Add("DYNAMIC_NORMAL_GENERATION"); } return(new GroundPieceCreationDetails() { KeywordSet = new ShaderKeywordSet(keywords), QueryElementDetails = queryElementDetails, Pack = pack, TerrainMeshResolution = terrainMeshResolution }); }