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 async Task PlaceSegmentAsync(Texture segmentTexture, PlacementDetails placementDetails) { var segmentPlacement0 = CalculateSegmentPlacement(placementDetails.ModuledPositionInGrid); UniformsPack uniforms0 = new UniformsPack(); uniforms0.SetTexture("_SegmentHeightTexture", segmentTexture); uniforms0.SetUniform("_SegmentCoords", segmentPlacement0.Uvs.ToVector4()); await _renderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, CreateTexture2D = false, RenderTextureToModify = _heightMap, ShaderName = "Custom/ETerrain/SegmentPlacer", UniformPack = uniforms0, RenderingRectangle = segmentPlacement0.Pixels, RenderTargetSize = _floorTextureSize, RenderTextureArraySlice = _heightMapSliceIndex }); if (_modifyCorners) { var modifiedCornerBuffer = await _commonExecutor.AddAction(() => { var tex = new RenderTexture(_modifiedCornerBufferSize.X, _modifiedCornerBufferSize.Y, 0, _heightMap.format); tex.Create(); return(tex); }); foreach (var cornerModification in placementDetails.CornersToModify) { var cornerMask = _cornerMaskInformations[cornerModification.Corner]; var segmentPlacement1 = CalculateSegmentPlacement(cornerModification.ModuledPositionOfSegment); var uniforms1 = new UniformsPack(); uniforms1.SetTexture("_HeightMap", _heightMap); uniforms1.SetUniform("_WeldingAreaCoords", RectangleUtils.CalculateSubPosition(segmentPlacement1.Uvs, cornerMask.SegmentSubPositionUv) .ToVector4()); uniforms1.SetUniform("_MarginSize", _interSegmentMarginSize); uniforms1.SetUniform("_CornerToWeld", cornerMask.CornerToWeldVector); uniforms1.SetUniform("_PixelSizeInUv", 1f / _floorTextureSize.X); uniforms1.SetUniform("_HeightMapSliceIndex", _heightMapSliceIndex); await _renderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, CreateTexture2D = false, RenderTextureToModify = modifiedCornerBuffer, ShaderName = "Custom/ETerrain/GenerateNewCorner", UniformPack = uniforms1, RenderingRectangle = new IntRectangle(0, 0, segmentPlacement1.Pixels.Width, segmentPlacement1.Pixels.Height), RenderTargetSize = new IntVector2(segmentPlacement1.Pixels.Width, segmentPlacement1.Pixels.Height) }); var uniforms2 = new UniformsPack(); uniforms2.SetTexture("_ModifiedCornerBuffer", modifiedCornerBuffer); await _renderer.AddOrder(new TextureRenderingTemplate() { CanMultistep = false, CreateTexture2D = false, RenderTextureToModify = _heightMap, ShaderName = "Custom/ETerrain/CornerPlacer", UniformPack = uniforms2, RenderingRectangle = RectangleUtils.CalculateSubPosition(segmentPlacement1.Pixels.ToFloatRectangle(), cornerMask.SegmentSubPositionUv).ToIntRectange(), RenderTargetSize = _floorTextureSize, RenderTextureArraySlice = _heightMapSliceIndex }); } await _commonExecutor.AddAction(() => GameObject.Destroy(modifiedCornerBuffer)); } }