bool ColorSliders() { bool changed = false; PlaytimePainter painter = PlaytimePainter.inspectedPainter; bool slider = BlitMode.ShowColorSliders; if ((painter != null) && (painter.IsTerrainHeightTexture())) { changed |= ChannelSlider(BrushMask.A, ref colorLinear.a, null, true); } else if ((painter != null) && painter.IsTerrainControlTexture()) { // Debug.Log("Is control texture"); changed |= ChannelSlider(BrushMask.R, ref colorLinear.r, painter.terrain.GetSplashPrototypeTexture(0), slider); changed |= ChannelSlider(BrushMask.G, ref colorLinear.g, painter.terrain.GetSplashPrototypeTexture(1), slider); changed |= ChannelSlider(BrushMask.B, ref colorLinear.b, painter.terrain.GetSplashPrototypeTexture(2), slider); changed |= ChannelSlider(BrushMask.A, ref colorLinear.a, painter.terrain.GetSplashPrototypeTexture(3), slider); } else { var id = painter.ImgData; if ((id.TargetIsRenderTexture()) && (id.renderTexture != null)) { changed |= ChannelSlider(BrushMask.R, ref colorLinear.r); changed |= ChannelSlider(BrushMask.G, ref colorLinear.g); changed |= ChannelSlider(BrushMask.B, ref colorLinear.b); } else { changed |= ChannelSlider(BrushMask.R, ref colorLinear.r, null, slider); changed |= ChannelSlider(BrushMask.G, ref colorLinear.g, null, slider); changed |= ChannelSlider(BrushMask.B, ref colorLinear.b, null, slider); changed |= ChannelSlider(BrushMask.A, ref colorLinear.a, null, slider); } } return(changed); }
/* * public void MirrorVerticlesAgainsThePlane(Vector3 ptdPos) * { * * Vector3 Mirror = GridNavigator.inst().getGridPerpendicularVector();//new Vector3(0,0,0); * * int Count = vertices.Count; * for (int i = 0; i < Count; i++) * { * vertexpointDta vp; * vertexpointDta newvp; * Vector3 diff; * * vp = vertices[i]; * diff = 2 * (Vector3.Scale(ptdPos - vp.localPos, Mirror)); * * newvp = vp.DeepCopy(); * newvp.localPos += diff; * * * vertices.Add(newvp); * * } * * * Count = triangles.Count; * * for (int i = 0; i < Count; i++) * triangles.Add(triangles[i].NewForCopiedVerticles()); * * for (int i = Count; i < triangles.Count; i++) * triangles[i].InvertNormal(); * Debug.Log("Dirty"); * dirty = true; * * } */ public void Edit(PlaytimePainter pntr) { //Temporary submeshCount = 1; if (pntr.SavedEditableMesh != null) { Decode(pntr.SavedEditableMesh); if (triangles.Count == 0) { BreakMesh(pntr.meshFilter.sharedMesh); } } else { BreakMesh(pntr.meshFilter.sharedMesh); pntr.selectedMeshProfile = pntr.GetMaterial(false).GetMeshProfileByTag(); } // Temporary while (baseVertex.Count < submeshCount) { baseVertex.Add(0); } }
public override bool SetTextureOnMaterial(string fieldName, ImageData id, PlaytimePainter painter) { Texture tex = id.CurrentTexture(); if (painter.terrain != null) { if (fieldName.Contains(PainterDataAndConfig.terrainTexture)) { int no = fieldName[0].CharToInt(); painter.terrain.SetSplashPrototypeTexture(id.texture2D, no); if (tex.GetType() != typeof(Texture2D)) { //else Debug.Log("Can only use Texture2D for Splat Prototypes. If using regular terrain may not see changes."); } else { #if UNITY_EDITOR UnityEditor.TextureImporter timp = ((Texture2D)tex).GetTextureImporter(); if (timp != null) { bool needReimport = timp.WasClamped(); needReimport |= timp.HadNoMipmaps(); if (needReimport) { timp.SaveAndReimport(); } } #endif } return(true); } } return(false); }
// public bool NeedsGrid(PlaytimePainter p) => false; public Shader GetPreviewShader(PlaytimePainter p) => null;
public Shader GetBrushShaderSingleBuffer(PlaytimePainter p) => null;
public void OnChangeMaterial(PlaytimePainter painter) { #if UNITY_EDITOR if (originalMaterial != null) { originalTextures = originalMaterial.GetTextures(); } if ((DestinationMaterial != null) && (DestinationMaterial.HasProperty(PainterDataAndConfig.isAtlasedProperty))) { List <string> aTextures = DestinationMaterial.GetTextures(); fields.Clear(); for (int i = 0; i < aTextures.Count; i++) { FieldAtlas ac = new FieldAtlas(); fields.Add(ac); ac.atlasedField = aTextures[i]; } #if PEGI atlasedShader = DestinationMaterial.shader; #endif foreach (var p in MaterialEditor.GetMaterialProperties(new Material[] { DestinationMaterial })) { if (p.displayName.Contains(PainterDataAndConfig.isAtlasableDisaplyNameTag)) { foreach (var f in fields) { if (f.atlasedField.SameAs(p.name)) { f.enabled = true; continue; } } } } if (AtlasedMaterial == null) { for (int i = 0; i < fields.Count; i++) { fields[i].originField = i; } } else if (originalMaterial != null) { var orTexs = originalMaterial.GetTextures(); foreach (var f in fields) { for (int i = 0; i < orTexs.Count; i++) { if (orTexs[i].SameAs(f.atlasedField)) { f.originField = i; } } } } } if (originalMaterial != null) { for (int i = 0; i < fields.Count; i++) { FindAtlas(i); } } #endif }
public StdEncoder EncodeStrokeFor(PlaytimePainter painter) { var id = painter.ImgData; bool rt = id.TargetIsRenderTexture(); BlitMode mode = BlitMode; BrushType type = Type(!rt); bool worldSpace = rt && IsA3Dbrush(painter); StdEncoder cody = new StdEncoder() .Add(rt ? "typeGPU" : "typeCPU", _type(!rt)); if (worldSpace) { cody.Add("size3D", Brush3D_Radius); } else { cody.Add("size2D", Brush2D_Radius / ((float)id.width)); } cody.Add_Bool("useMask", useMask) .Add("mode", _bliTMode); if (useMask) { cody.Add("mask", (int)mask); } cody.Add("bc", colorLinear); if (mode.UsingSourceTexture) { cody.Add("source", selectedSourceTexture); } if (rt) { if ((mode.GetType() == typeof(BlitModeBlur))) { cody.Add("blur", blurAmount); } if (type.IsUsingDecals) { cody.Add("decA", decalAngle) .Add("decNo", selectedDecal); } if (useMask) { cody.Add("Smask", selectedSourceMask) .Add("maskTil", maskTiling) .Add_Bool("maskFlip", flipMaskAlpha) .Add("maskOff", maskOffset); } } cody.Add("hard", Hardness) .Add("speed", speed); return(cody); }
public PaintingCollision(PlaytimePainter p) { painter = p; vector = new Stroke(); }
public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr) { if (pntr.IsAtlased()) { Vector2 uvCoords = stroke.uvFrom; Vector2 AtlasedSection = GetAtlasedSection(); sectorSize = image.width / atlasRows; atlasSector.From(AtlasedSection * sectorSize); Blit_Functions.brAlpha = brushAlpha; Blit_Functions.half = (bc.Size(false)) / 2; int ihalf = Mathf.FloorToInt(Blit_Functions.half - 0.5f); bool smooth = bc.Type(true) != BrushTypePixel.Inst; if (smooth) { Blit_Functions._alphaMode = Blit_Functions.circleAlpha; } else { Blit_Functions._alphaMode = Blit_Functions.noAlpha; } Blit_Functions._blitMode = bc.BlitMode.BlitFunctionTex2D; if (smooth) { ihalf += 1; } Blit_Functions.alpha = 1; Blit_Functions.r = bc.mask.GetFlag(BrushMask.R); Blit_Functions.g = bc.mask.GetFlag(BrushMask.G); Blit_Functions.b = bc.mask.GetFlag(BrushMask.B); Blit_Functions.a = bc.mask.GetFlag(BrushMask.A); Blit_Functions.csrc = bc.colorLinear.ToGamma(); MyIntVec2 tmp = image.UvToPixelNumber(uvCoords);//new myIntVec2 (pixIndex); int fromx = tmp.x - ihalf; tmp.y -= ihalf; var pixels = image.Pixels; for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++) { tmp.x = fromx; for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++) { if (Blit_Functions._alphaMode()) { int sx = tmp.x - atlasSector.x; int sy = tmp.y - atlasSector.y; sx %= sectorSize; if (sx < 0) { sx += sectorSize; } sy %= sectorSize; if (sy < 0) { sy += sectorSize; } Blit_Functions._blitMode(ref pixels[((atlasSector.y + sy)) * image.width + (atlasSector.x + sx)]); } tmp.x += 1; } tmp.y += 1; } return(true); } return(false); }
public bool NeedsGrid(PlaytimePainter p) { return(useGrid && p.GetVolumeTexture() != null); }
public virtual bool IsA3Dbrush(PlaytimePainter pntr, BrushConfig bc, ref bool overrideOther) { return(false); }
public override bool PaintRenderTexture(StrokeVector stroke, ImageData image, BrushConfig bc, PlaytimePainter pntr) { var vt = pntr.GetVolumeTexture(); if (vt != null) { BrushTypeSphere.Inst.BeforeStroke(pntr, bc, stroke); Shader.SetGlobalVector(VOLUME_POSITION_N_SIZE + "_BRUSH", vt.PosNsize4Shader); Shader.SetGlobalVector(VOLUME_H_SLICES + "_BRUSH", vt.Slices4Shader); if (stroke.mouseDwn) { stroke.posFrom = stroke.posTo; } stroke.useTexcoord2 = false; TexMGMT.ShaderPrepareStroke(bc, bc.speed * 0.05f, image, stroke, pntr); stroke.SetWorldPosInShader(); TexMGMT.brushRendy.FullScreenQuad(); TexMGMT.Render(); BrushTypeSphere.Inst.AfterStroke(pntr, bc, stroke); return(true); } return(false); }
public bool BrushConfigPEGI(ref bool overrideBlitMode, BrushConfig br) { bool changed = false; PlaytimePainter p = InspectedPainter; var volTex = p.GetVolumeTexture(); if (volTex != null) { overrideBlitMode = true; var id = p.ImgData; "Grid".toggle(50, ref useGrid).nl(); if ((volTex.name + " " + id.texture2D.VolumeSize(volTex.h_slices).ToString()).foldout(ref exploreVolumeData).nl()) { changed |= volTex.Nested_Inspect(); } if (volTex.NeedsToManageMaterials) { var pmat = InspectedPainter.Material; if (pmat != null) { if (!volTex.materials.Contains(pmat)) { if ("Add This Material".Click().nl()) { volTex.AddIfNew(p); } } } } bool cpuBlit = id.TargetIsTexture2D(); pegi.newLine(); if (!cpuBlit) { changed |= "Hardness:".edit("Makes edges more rough.", 70, ref br.Hardness, 1f, 512f).nl(); } changed |= "Speed".edit(40, ref br.speed, 0.01f, 20).nl(); float maxScale = volTex.size * volTex.Width * 0.25f; changed |= "Scale:".edit(40, ref br.Brush3D_Radius, 0.001f * maxScale, maxScale * 0.5f).nl(); if ((br.BlitMode.UsingSourceTexture) && (id == null || id.TargetIsRenderTexture())) { if (TexMGMTdata.sourceTextures.Count > 0) { pegi.write("Copy From:", 70); changed |= pegi.selectOrAdd(ref br.selectedSourceTexture, ref TexMGMTdata.sourceTextures); } else { "Add Textures to Render Camera to copy from".nl(); } } } if (changed) { this.SetToDirty(); } return(changed); }
public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr) { var volume = image.texture2D.GetVolumeTextureData(); if (volume != null) { if (volume.VolumeJobIsRunning) { return(false); } float volumeScale = volume.size; Vector3 pos = (stroke.posFrom - volume.transform.position) / volumeScale + 0.5f * Vector3.one; int height = volume.Height; int texWidth = image.width; Blit_Functions.brAlpha = brushAlpha; bc.PrepareCPUBlit(); Blit_Functions.half = bc.Size(true) / volumeScale; var pixels = image.Pixels; int ihalf = (int)(Blit_Functions.half - 0.5f); bool smooth = bc.Type(true) != BrushTypePixel.Inst; if (smooth) { ihalf += 1; } Blit_Functions._alphaMode = Blit_Functions.SphereAlpha; int sliceWidth = texWidth / volume.h_slices; int hw = sliceWidth / 2; int y = (int)pos.y; int z = (int)(pos.z + hw); int x = (int)(pos.x + hw); for (Blit_Functions.y = -ihalf; Blit_Functions.y < ihalf + 1; Blit_Functions.y++) { int h = y + Blit_Functions.y; if (h >= height) { return(true); } if (h >= 0) { int hy = h / volume.h_slices; int hx = h % volume.h_slices; int hTex_index = (hy * texWidth + hx) * sliceWidth; for (Blit_Functions.z = -ihalf; Blit_Functions.z < ihalf + 1; Blit_Functions.z++) { int trueZ = z + Blit_Functions.z; if (trueZ >= 0 && trueZ < sliceWidth) { int yTex_index = hTex_index + trueZ * texWidth; for (Blit_Functions.x = -ihalf; Blit_Functions.x < ihalf + 1; Blit_Functions.x++) { if (Blit_Functions._alphaMode()) { int trueX = x + Blit_Functions.x; if (trueX >= 0 && trueX < sliceWidth) { int texIndex = yTex_index + trueX; Blit_Functions._blitMode(ref pixels[texIndex]); } } } } } } } return(true); } return(false); }
public void MergeWith(PlaytimePainter other) => MergeWith(new EditableMesh(other), other);
public EditableMesh(PlaytimePainter painter) { Edit(painter); }
public bool IsEnabledFor(PlaytimePainter painter, TextureMeta id, Brush cfg) => painter.IsAtlased() && !id.TargetIsRenderTexture();
public virtual Shader GetPreviewShader(PlaytimePainter p) { return(null); }
public virtual Shader GetBrushShaderSingleBuffer(PlaytimePainter p) { return(null); }
public static bool IsProjected(this PlaytimePainter p) { return(p.GetMaterial(false).IsProjected()); }
public virtual bool PaintRenderTexture(StrokeVector stroke, ImageData image, BrushConfig bc, PlaytimePainter pntr) { return(false); }
public virtual bool PEGI() { PlaytimePainter p = PlaytimePainter.inspectedPainter; if (p == null) { "No Painter Detected".nl(); return(false); } if ((p.skinnedMeshRendy != null) && (pegi.Click("Update Collider from Skinned Mesh"))) { p.UpdateColliderForSkinnedMesh(); } pegi.newLine(); ImageData id = p.ImgData; bool changed = false; bool cpuBlit = id.destination == TexTarget.Texture2D; pegi.newLine(); changed |= p.PreviewShaderToggle_PEGI(); if ((PainterCamera.GotBuffers() || (id.renderTexture != null)) && (id.texture2D != null)) { if ((cpuBlit ? icon.CPU : icon.GPU).Click( cpuBlit ? "Switch to Render Texture" : "Switch to Texture2D", 45)) { p.UpdateOrSetTexTarget(cpuBlit ? TexTarget.RenderTexture : TexTarget.Texture2D); SetSupportedFor(cpuBlit, id.renderTexture == null); changed = true; } } if (cpuBlit) { bool smooth = _type(cpuBlit) != BrushTypePixel.Inst.index; if (pegi.toggle(ref smooth, icon.Round, icon.Square, "Smooth/Pixels Brush", 45)) { changed = true; TypeSet(cpuBlit, smooth ? (BrushType)BrushTypeNormal.Inst : (BrushType)BrushTypePixel.Inst); } } pegi.newLine(); #if UNITY_EDITOR if (Tools.current != Tool.None) { Msg.LockToolToUseTransform.Get().writeWarning(); if (Msg.HideTransformTool.Get().Click().nl()) { PlaytimePainter.HideUnityTool(); } } #endif if //( (!p.IsOriginalShader) // && (cfg.moreOptions)) { changed |= pegi.toggle(ref Cfg.previewAlphaChanel, "Preview Enabled Chanels", 130); } if (Mode_Type_PEGI()) { if (Type(cpuBlit) == BrushTypeDecal.Inst) { MaskSet(BrushMask.A, true); } changed = true; } if (p.terrain != null) { if ((p.ImgData != null) && ((p.IsTerrainHeightTexture())) && (p.IsOriginalShader)) { pegi.writeWarning(" You need to use Preview Shader to see changes"); } pegi.newLine(); if ((p.terrain != null) && (pegi.Click("Update Terrain").nl())) { p.UpdateShaderGlobals(); } } return(changed); }
public static bool PaintTexture2D(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr) { var pl = pntr.GetPlugin <TileableAtlasingPainterPlugin>(); if (pl != null) { return(pl.PaintTexture2D(stroke, brushAlpha, image, bc, pntr)); } else { return(false); } }
public Shader GetPreviewShader(PlaytimePainter p) => p.TexMeta.isAVolumeTexture ? _preview : null;
public override void Update_Brush_Parameters_For_Preview_Shader(PlaytimePainter p) { BlitModeExtensions.SetShaderToggle(!p.IsAtlased(), PainterDataAndConfig.UV_NORMAL, PainterDataAndConfig.UV_ATLASED); }
public Shader GetBrushShaderDoubleBuffer(PlaytimePainter p) => p.TexMeta.isAVolumeTexture ? (_enableRayTracing ? _brushShaderFroRayTrace : _brush) : null;
public void ConvertToAtlased(PlaytimePainter painter) { #if UNITY_EDITOR if (AtlasedMaterial == null) { AtlasedMaterial = painter.InstantiateMaterial(true); } painter.SetOriginalShaderOnThis(); painter.UpdateOrSetTexTarget(TexTarget.Texture2D); Material mat = painter.GetMaterial(false); List <string> tfields = mat.GetTextures(); int index = 0; List <FieldAtlas> passedFields = new List <FieldAtlas>(); List <Texture2D> passedTextures = new List <Texture2D>(); List <Color> passedColors = new List <Color>(); foreach (var f in fields) { if ((f.enabled) && (f.AtlasCreator != null) && (tfields.Contains(originalTextures[f.originField]))) { string original = originalTextures[f.originField]; Texture tex = mat.GetTexture(original); Texture2D texture = null; if (tex == null) { var note = painter.name + " no " + original + " texture. Using Color."; #if PEGI note.showNotification(); #endif Debug.Log(note); } else { if (tex.GetType() != typeof(Texture2D)) { Debug.Log("Not a Texture 2D: " + original); return; } texture = (Texture2D)tex; } var aTexes = f.AtlasCreator.textures; bool added = false; for (int i = index; i < aTexes.Count; i++) { if ((aTexes[i] == null) || (!aTexes[i].used) || (aTexes[i].texture == texture)) { index = i; passedFields.Add(f); passedTextures.Add(texture); passedColors.Add(f.col); added = true; break; } } if (!added) { Debug.Log("Could not find a place for " + original); return; } } } if (passedFields.Count > 0) { bool firstAtlasing = false; var atlPlug = painter.GetPlugin <TileableAtlasingPainterPlugin>(); if (atlPlug.preAtlasingMaterials == null) { atlPlug.preAtlasingMaterials = painter.GetMaterials(); atlPlug.preAtlasingMesh = painter.GetMesh(); firstAtlasing = true; } var MainField = passedFields[0]; atlPlug.atlasRows = MainField.AtlasCreator.Row; Vector2 tyling = mat.GetTextureScale(originalTextures[MainField.originField]); Vector2 offset = mat.GetTextureOffset(originalTextures[MainField.originField]); for (int i = 0; i < passedFields.Count; i++) {// var f in passedFields){ var f = passedFields[i]; var ac = f.AtlasCreator; ac.textures[index] = new AtlasTextureField(passedTextures[i], passedColors[i]); ac.AddTargets(f, originalTextures[f.originField]); ac.ReconstructAsset(); AtlasedMaterial.SetTexture(f.atlasedField, ac.a_texture); } MeshManager.Inst.EditMesh(painter, true); if (firstAtlasing) { atlPlug.preAtlasingSavedMesh = MeshManager.Inst.edMesh.Encode().ToString(); } painter.selectedMeshProfile = matAtlasProfile; if ((tyling != Vector2.one) || (offset != Vector2.zero)) { MeshManager.Inst.edMesh.TileAndOffsetUVs(offset, tyling, 0); Debug.Log("offsetting " + offset + " tyling " + tyling); } TriangleAtlasTool.Inst.SetAllTrianglesTextureTo(index, 0, painter.selectedSubmesh); MeshManager.Inst.Redraw(); MeshManager.Inst.DisconnectMesh(); AtlasedMaterial.SetFloat(PainterDataAndConfig.atlasedTexturesInARow, atlPlug.atlasRows); painter.Material = AtlasedMaterial; if (firstAtlasing) { var m = painter.GetMesh(); m.name = m.name + "_Atlased_" + index; } //painter.getMaterial(false).SetTextureOffset(1,Vector2.zero); AtlasedMaterial.EnableKeyword(PainterDataAndConfig.UV_ATLASED); } #endif }
public bool IsEnabledFor(PlaytimePainter painter, TextureMeta img, Brush cfg) => img.GetVolumeTextureData();
private bool CorrectField(ShaderProperty.TextureValue field, PlaytimePainter painter) => painter.terrain && field.Equals(PainterShaderVariables.TerrainHeight);
public bool IsA3DBrush(PlaytimePainter painter, Brush bc, ref bool overrideOther) => false;