public void PaintRenderTexture(StrokeVector stroke, TextureMeta image, BrushConfig bc, PlaytimePainter painter) { var vt = painter.GetVolumeTexture(); if (!vt) { Debug.LogError("Painted volume was not found"); return; } if (_enableRayTracing) { rayTraceCameraConfiguration.From(stroke); bc.useAlphaBuffer = false; delayedPaintingConfiguration = new BrushStrokePainterImage(stroke, image, bc, painter); PainterCamera.GetProjectorCamera().RenderRightNow(this); } else { PaintRenderTexture(new BrushStrokePainterImage(stroke, image, bc, painter)); } }
public void PaintRenderTextureUvSpace(PaintCommand.UV command) { Stroke stroke = command.Stroke; TextureMeta image = command.TextureData; Brush bc = command.Brush; var vt = image.GetVolumeTextureData(); if (!vt) { Debug.LogError("Painted volume was not found"); return; } if (_enableRayTracing) { rayTraceCameraConfiguration.From(stroke); bc.useAlphaBuffer = false; delayedPaintingConfiguration = new PaintCommand.UV(stroke, image, bc); PainterCamera.GetOrCreateProjectorCamera().RenderRightNow(this); } else { PaintRenderTextureInternal(command); // Maybe wrong } }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id) { var tex = id.CurrentTexture(); if (!painter.terrain) { return(false); } if (!field.HasUsageTag(PainterShaderVariables.TERRAIN_CONTROL_TEXTURE)) { return(false); } var no = field.NameForDisplayPEGI()[0].CharToInt(); if (no == 0) { PainterShaderVariables.TerrainControlMain.GlobalValue = tex; } painter.terrain.terrainData.alphamapTextures[no] = id.texture2D; return(true); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels == null) { ExtractPixels(set.diffuse, id?.width ?? set.width, id?.height ?? set.height); } return(pixels); }
private void SetUsedTextureOrImage( Dictionary <TextureInfo, TextureMeta> dict, int cbufSlot, int handle, SamplerType type, TextureFormat format, bool intCoords, bool write, bool accurateType) { var dimensions = type.GetDimensions(); var isIndexed = type.HasFlag(SamplerType.Indexed); var usageFlags = TextureUsageFlags.None; if (intCoords) { usageFlags |= TextureUsageFlags.NeedsScaleValue; var canScale = (Stage == ShaderStage.Fragment || Stage == ShaderStage.Compute) && !isIndexed && !write && dimensions == 2; if (!canScale) { // Resolution scaling cannot be applied to this texture right now. // Flag so that we know to blacklist scaling on related textures when binding them. usageFlags |= TextureUsageFlags.ResScaleUnsupported; } } if (write) { usageFlags |= TextureUsageFlags.ImageStore; } int arraySize = isIndexed ? SamplerArraySize : 1; for (int layer = 0; layer < arraySize; layer++) { var info = new TextureInfo(cbufSlot, handle + layer * 2, isIndexed, format); var meta = new TextureMeta() { AccurateType = accurateType, Type = type, UsageFlags = usageFlags }; if (dict.TryGetValue(info, out var existingMeta)) { dict[info] = MergeTextureMeta(meta, existingMeta); } else { dict.Add(info, meta); } } }
public bool TryGetTextureMeta(ResourceLocation textureName, out TextureMeta meta) { if (_textureMetaCache.TryGetValue(textureName, out meta)) { return(true); } meta = null; return(false); }
public bool TryGetTextureMeta(string textureName, out TextureMeta meta) { if (_textureMetaCache.TryGetValue(textureName, out meta)) { return(true); } meta = null; return(false); }
private void ProcessBlockStateModel(McResourcePack resourcePack, Dictionary <ResourceLocation, ImageEntry> textures, BlockStateModel bsModel) { var model = bsModel.Model; foreach (var texture in model.Textures) { var text = texture.Value; if (text[0] == '#') { var substr = text.Substring(1); if (model.Textures.TryGetValue(substr, out var p)) { text = p; } else { var parent = model.Parent; while (parent != null) { if (parent.Textures.TryGetValue(substr, out string parentName)) { text = parentName; break; } parent = parent.Parent; } } } var key = new ResourceLocation(text); var alreadyLoaded = textures.ContainsKey(key); if (!alreadyLoaded && resourcePack.TryGetBitmap(key, out var bmp)) { TextureMeta meta = null; resourcePack.TryGetTextureMeta(key, out meta); textures.TryAdd(key, new ImageEntry(bmp, meta)); } else if (!alreadyLoaded) { if (texture.Value[0] != '#' || text[0] != '#') { Log.Warn( $"Could not get bitmap {texture.Value} or {text} (Key: {texture.Key} Model: {bsModel.ModelName})"); } } } }
public List <Color[]> GetMipPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (mipLevels != null) { return(mipLevels); } var width = id?.width ?? set.width; var height = id?.height ?? set.height; mipLevels = new List <Color[]>(); var w = width; var h = height; while (w > 1 && h > 1) { w /= 2; h /= 2; var dest = new Color[w * h]; var dx = width / w; var dy = height / h; float pixelsPerSector = dx * dy; for (var y = 0; y < h; y++) { for (var x = 0; x < w; x++) { var col = new Color(0, 0, 0, 0); var start = y * dy * width + x * dx; for (var sy = 0; sy < dy; sy++) { for (var sx = 0; sx < dx; sx++) { col += pixels[start + sy * width + sx]; } } col /= pixelsPerSector; dest[y * w + x] = col; } } mipLevels.Add(dest); } return(mipLevels); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { var width = id?.width ?? set.width; var height = id?.height ?? set.height; if (pixels == null) { ExtractPixels(set.ambient ? set.ambient : set.heightMap, width, height); } return(pixels); }
private void GetTextures(McResourcePack resourcePack, Dictionary <ResourceLocation, ImageEntry> textures, IProgressReceiver progressReceiver) { foreach (var texture in resourcePack.Textures.Where(x => x.Key.Path.StartsWith("block/", StringComparison.InvariantCultureIgnoreCase))) { if (textures.ContainsKey(texture.Key)) { continue; } TextureMeta meta = null; resourcePack.TryGetTextureMeta(texture.Key, out meta); textures.Add(texture.Key, new ImageEntry(texture.Value, meta)); } /* * progressReceiver.UpdateProgress(0, "Processing blockstate textures..."); * int blockstatesProcessed = 0; * int totalStates = resourcePack.BlockStates.Count; * * foreach (var kv in resourcePack.BlockStates) * { * progressReceiver.UpdateProgress( * (int) (100D * ((double) blockstatesProcessed / (double) totalStates)), null, kv.Key); * * var state = kv.Value; * * foreach (var variant in state.Variants) * { * foreach (var va in variant.Value) * { * ProcessBlockStateModel(resourcePack, textures, va); * } * } * * * foreach (var part in state.Parts) * { * if (part.Apply == null) * continue; * * foreach (var applied in part.Apply) * { * ProcessBlockStateModel(resourcePack, textures, applied); * } * } * * blockstatesProcessed++; * // state. * }*/ }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels != null) { return(pixels); } var width = id?.width ?? set.width; var height = id?.height ?? set.height; ExtractPixels(set.reflectivity ? set.reflectivity : set.gloss, width, height); return(pixels); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (id != null) { return(id.Pixels); } if (pixels == null) { ExtractPixels(set.lastProduct, set.width, set.height); } return(pixels); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels == null) { var width = id?.width ?? set.width; var height = id?.height ?? set.height; ExtractPixels(set.normalMap, width, height); } #if UNITY_EDITOR _texture = set.normalMap; #endif return(pixels); }
private static TextureMeta MergeTextureMeta(TextureMeta meta, TextureMeta existingMeta) { meta.UsageFlags |= existingMeta.UsageFlags; // If the texture we have has inaccurate type information, then // we prefer the most accurate one. if (existingMeta.AccurateType) { meta.AccurateType = true; meta.Type = existingMeta.Type; } return(meta); }
public void GetTextures(McResourcePack resourcePack, Dictionary <ResourceLocation, ImageEntry> textures, IProgressReceiver progressReceiver) { /*List<ResourceLocation> texturePaths = new List<ResourceLocation>(); * foreach (var model in resourcePack.BlockModels) * { * foreach (var texture in model.Value.Textures) * { * if (!texturePaths.Contains(texture.Value)) * texturePaths.Add(texture.Value); * } * // model.Value.Textures * }*/ int done = 0; // var items = resourcePack.Textures.Where(x => texturePaths.Contains(x.Key)).ToArray(); var texturePaths = resourcePack.Textures.Where(x => x.Key.Path.Contains("block/")).ToArray(); foreach (var path in texturePaths) { progressReceiver?.UpdateProgress(done++, texturePaths.Length, "Resolving textures...", path.ToString()); if (resourcePack.TryGetBitmap(path.Key, out var texture)) { TextureMeta meta = null; resourcePack.TryGetTextureMeta(path.Key, out meta); //var entry = new ImageEntry(texture.Value.Value, meta); if (textures.ContainsKey(path.Key)) { if (meta != null) { textures[path.Key].Meta = meta; } if (texture != null) { textures[path.Key].Image = texture; } //textures[texture.Key] = entry; } else { textures.Add(path.Key, new ImageEntry(texture, meta)); } } } }
private TextureMeta LoadBitmapMeta(ZipArchiveEntry entry, Match match) { TextureMeta meta; using (var stream = entry.Open()) { //using (StreamReader sr = new StreamReader(stream)) { //string content = sr.ReadToEnd(); meta = TextureMeta.FromJson(Encoding.UTF8.GetString(stream.ReadToSpan(entry.Length))); } } _textureMetaCache[match.Groups["filename"].Value] = meta; return(meta); }
private void GetTextures(McResourcePack resourcePack, Dictionary <ResourceLocation, ImageEntry> textures, IProgressReceiver progressReceiver) { foreach (var texture in resourcePack.Textures.Where(x => x.Key.Path.StartsWith("block/", StringComparison.OrdinalIgnoreCase))) { if (textures.ContainsKey(texture.Key)) { continue; } TextureMeta meta = null; resourcePack.TryGetTextureMeta(texture.Key, out meta); textures.Add(texture.Key, new ImageEntry(texture.Value.Value, meta)); } }
private TextureMeta LoadBitmapMeta(ZipArchiveEntry entry, Match match) { TextureMeta meta; using (var stream = entry.Open()) { using (StreamReader sr = new StreamReader(stream)) { string content = sr.ReadToEnd(); meta = TextureMeta.FromJson(content); } } _textureMetaCache[match.Groups["filename"].Value] = meta; return(meta); }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id) { if (!CorrectField(field, painter)) { return(false); } if (id != null && id.texture2D) { painter.terrainHeightTexture = id.texture2D; } var tex = id.CurrentTexture(); PainterShaderVariables.TerrainHeight.GlobalValue = tex; return(true); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels != null) { return(pixels); } var width = id?.width ?? set.width; var height = id?.height ?? set.height; ExtractPixels(set.gloss ? set.gloss : set.reflectivity, width, height); if (set.Profile.glossNoiseFromHeight && set.heightMap) { GlossMipmapsFromHeightNoise(set.heightMap, width, height, set.Profile.bumpNoiseInGlossFraction); } return(pixels); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels != null) { return(pixels); } _width = id?.width ?? set.width; _height = id?.height ?? set.height; ExtractPixels(set.heightMap ? set.heightMap : set.ambient, _width, _height); var strength = set.Profile.bumpStrength; for (var bY = 0; bY < _height; bY++) { for (var bX = 0; bX < _width; bX++) { var dstIndex = IndexFrom(bX, bY); var col = pixels[dstIndex]; col.b = col.grayscale; var xLeft = pixels[IndexFrom(bX - 1, bY)].a; var xRight = pixels[IndexFrom(bX + 1, bY)].a; var yUp = pixels[IndexFrom(bX, bY - 1)].a; var yDown = pixels[IndexFrom(bX, bY + 1)].a; var xDelta = (-xRight + xLeft) * strength; var yDelta = (-yDown + yUp) * strength; col.r = Mathf.Clamp01(xDelta * Mathf.Abs(xDelta) + 0.5f); col.g = Mathf.Clamp01(yDelta * Mathf.Abs(yDelta) + 0.5f); pixels[dstIndex] = col; } } return(pixels); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id) { if (pixels != null) { return(pixels); } var noID = id == null; var width = noID ? set.width : id.width; var height = noID ? set.height : id.height; var col = set.Profile.fillColor; var size = width * height; pixels = new Color[size]; for (var i = 0; i < size; i++) { pixels[i] = col; } return(pixels); }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id) { var tex = id.CurrentTexture(); if (!painter.terrain) { return(false); } if (!field.HasUsageTag(PainterShaderVariables.TERRAIN_SPLAT_DIFFUSE)) { return(false); } var no = field.NameForDisplayPEGI()[0].CharToInt(); painter.terrain.SetSplashPrototypeTexture(id.texture2D, no); if (tex.GetType() != typeof(Texture2D)) { Debug.Log("Can only use Texture2D for Splat Prototypes. If using regular terrain may not see changes."); } else { #if UNITY_EDITOR var texImporter = ((Texture2D)tex).GetTextureImporter(); if (texImporter == null) { return(true); } var needReimport = texImporter.WasClamped(); needReimport |= texImporter.HadNoMipmaps(); if (needReimport) { texImporter.SaveAndReimport(); } #endif } return(true); }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id) { var tex = id.CurrentTexture(); if (!painter.terrain || !field.Equals(PainterShaderVariables.TerrainLight)) { return(false); } FindMergingTerrain(painter); if (mergingTerrain && id != null) { mergingTerrain.lightTexture = id.texture2D; } #if UNITY_EDITOR var t2D = tex as Texture2D; if (t2D) { var importer = (t2D).GetTextureImporter(); if (importer != null) { var needReimport = importer.WasClamped(); needReimport |= importer.HadNoMipmaps(); if (needReimport) { importer.SaveAndReimport(); } } } #endif PainterShaderVariables.TerrainLight.GlobalValue = tex; return(true); }
public bool IsEnabledFor(PlaytimePainter painter, TextureMeta id, Brush cfg) => painter.IsAtlased() && !id.TargetIsRenderTexture();
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta id) { if (!volumeTexture) { return(false); } if (field.ToString() == volumeTexture.name) { volumeTexture.ImageMeta = id; return(true); } return(false); }
public bool IsEnabledFor(PlaytimePainter painter, TextureMeta img, Brush cfg) => img.GetVolumeTextureData();
public void PaintPixelsInRam(PaintCommand.UV command) { Stroke stroke = command.Stroke; float brushAlpha = command.strokeAlphaPortion; TextureMeta image = command.TextureData; Brush bc = command.Brush; var volume = image.texture2D.GetVolumeTextureData(); if (!volume) { return; } bc.brush3DRadius = Mathf.Min(BrushScaleMaxForCpu(volume), bc.brush3DRadius); var volumeScale = volume.size; var pos = (stroke.posFrom - volume.transform.position) / volumeScale + 0.5f * Vector3.one; var height = volume.Height; var texWidth = image.width; BlitFunctions.brAlpha = brushAlpha; bc.PrepareCpuBlit(image); BlitFunctions.half = bc.Size(true) / volumeScale; var pixels = image.Pixels; var iHalf = (int)(BlitFunctions.half - 0.5f); var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst; if (smooth) { iHalf += 1; } BlitFunctions.alphaMode = BlitFunctions.SphereAlpha; var sliceWidth = texWidth / volume.hSlices; var hw = sliceWidth / 2; var y = (int)pos.y; var z = (int)(pos.z + hw); var x = (int)(pos.x + hw); for (BlitFunctions.y = -iHalf; BlitFunctions.y < iHalf + 1; BlitFunctions.y++) { var h = y + BlitFunctions.y; if (h >= height) { return; } if (h < 0) { continue; } var hy = h / volume.hSlices; var hx = h % volume.hSlices; var hTexIndex = (hy * texWidth + hx) * sliceWidth; for (BlitFunctions.z = -iHalf; BlitFunctions.z < iHalf + 1; BlitFunctions.z++) { var trueZ = z + BlitFunctions.z; if (trueZ < 0 || trueZ >= sliceWidth) { continue; } var yTexIndex = hTexIndex + trueZ * texWidth; for (BlitFunctions.x = -iHalf; BlitFunctions.x < iHalf + 1; BlitFunctions.x++) { if (!BlitFunctions.alphaMode()) { continue; } var trueX = x + BlitFunctions.x; if (trueX < 0 || trueX >= sliceWidth) { continue; } var texIndex = yTexIndex + trueX; BlitFunctions.blitMode(ref pixels[texIndex]); } } } }
public ImageEntry(Image <Rgba32> image, TextureMeta meta) { Image = image; Meta = meta; }