public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { BeforeStroke(pntr, br, st); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } ImageData id = pntr.ImgData; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, st, pntr); Rtbrush.localScale = Vector3.one * br.StrokeWidth(id.width, false); BrushMesh = brushMeshGenerator.inst().GetQuad(); Rtbrush.localRotation = Quaternion.identity; Rtbrush.localPosition = st.BrushWorldPosition; TexMGMT.Render(); AfterStroke(pntr, br, st); }
public static void Paint(Vector2 uv, BrushConfig br, RenderTexture rt) { if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } var id = rt.GetImgData(); var stroke = new StrokeVector(uv) { useTexcoord2 = false, firstStroke = false }; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, stroke, null); float width = br.StrokeWidth(id.width, false); Rtbrush.localScale = Vector3.one; BrushMesh = brushMeshGenerator.inst().GetLongMesh(0, width); Rtbrush.localRotation = Quaternion.Euler(new Vector3(0, 0, Vector2.Angle(Vector2.up, Vector2.zero))); Rtbrush.localPosition = StrokeVector.BrushWorldPositionFrom(uv); TexMGMT.Render(); AfterStroke(br); }
public virtual void BeforeStroke(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { foreach (var p in pntr.plugins) { p.BeforeGPUStroke(pntr, br, st, this); } }
public override bool MouseEventPointedTriangle() { if (EditorInputManager.GetMouseButton(0)) { if (PointedTris.SameAsLastFrame) { return(true); } BrushConfig bcf = Cfg.brushConfig; Color c = bcf.colorLinear.ToGamma(); foreach (var u in PointedTris.vertexes) { foreach (var vuv in u.meshPoint.uvpoints) { bcf.mask.Transfer(ref vuv._color, c); } } // a.vert.SetColorOnLine(c, bcf.mask, b.vert);//setColor(glob.colorSampler.color, glob.colorSampler.mask); // b.vert.SetColorOnLine(c, bcf.mask, a.vert); MeshMGMT.edMesh.dirty_Color = true; return(true); } return(false); }
public virtual void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { BeforeStroke(pntr, br, st); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } ImageData id = pntr.ImgData; TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, st, pntr); var rb = Rtbrush; rb.localScale = Vector3.one; Vector2 direction = st.Delta_uv; float length = direction.magnitude; BrushMesh = brushMeshGenerator.inst().GetLongMesh(length * 256, br.StrokeWidth(id.width, false)); rb.localRotation = Quaternion.Euler(new Vector3(0, 0, (direction.x > 0 ? -1 : 1) * Vector2.Angle(Vector2.up, direction))); rb.localPosition = StrokeVector.BrushWorldPositionFrom((st.uvFrom + st.uvTo) / 2); TexMGMT.Render(); AfterStroke(pntr, br, st); }
protected static void AfterStroke(BrushConfig br) { if ((br.useMask) && (br.randomMaskOffset)) { br.maskOffset = new Vector2(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); } }
public override void AfterGPUStroke(PlaytimePainter p, BrushConfig br, StrokeVector st, BrushType type) { if (br.IsA3Dbrush(p) && p.IsAtlased()) { Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, 1, 0)); } }
public static void PrepareCPUBlit(this BrushConfig bc) { half = (bc.Size(false)) / 2; bool smooth = bc.Type(true) != BrushTypePixel.Inst; if (smooth) { _alphaMode = circleAlpha; } else { _alphaMode = noAlpha; } _blitMode = bc.BlitMode.BlitFunctionTex2D;//bliTMode_Texture2D.blitFunction(); alpha = 1; r = bc.mask.GetFlag(BrushMask.R); g = bc.mask.GetFlag(BrushMask.G); b = bc.mask.GetFlag(BrushMask.B); a = bc.mask.GetFlag(BrushMask.A); csrc = bc.colorLinear.ToGamma(); }
public override void PrePaint(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { var v4 = new Vector4(st.unRepeatedUV.x, st.unRepeatedUV.y, Mathf.Floor(st.unRepeatedUV.x), Mathf.Floor(st.unRepeatedUV.y)); Shader.SetGlobalVector("_brushPointedUV_Untiled", v4); if (st.firstStroke) { if (method == (ColorSetMethod.MDownColor)) { if (pntr) { pntr.SampleTexture(st.uvTo); FromColor(br, st.unRepeatedUV); } } else if (method == (ColorSetMethod.MDownPosition)) { FromUV(st.uvTo); } Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_SAMPLING_DISPLACEMENT, new Vector4( ((float)currentPixel.x + 0.5f) / ((float)Cfg.samplingMaskSize.x), ((float)currentPixel.y + 0.5f) / ((float)Cfg.samplingMaskSize.y), Cfg.samplingMaskSize.x, Cfg.samplingMaskSize.y)); } }
public void FromColor(BrushConfig brush, Vector2 uv) { var c = brush.colorLinear.ToGamma(); currentPixel.x = (int)Mathf.Floor((uv.x + (c.r - 0.5f) * 2) * Cfg.samplingMaskSize.x); currentPixel.y = (int)Mathf.Floor((uv.y + (c.g - 0.5f) * 2) * Cfg.samplingMaskSize.y); }
public override bool MouseEventPointedVertex() { MeshManager m = MeshMGMT; BrushConfig bcf = GlobalBrush; //if (EditorInputManager.GetMouseButtonDown(1)) // m.pointedUV.vert.clearColor(cfg.brushConfig.mask); if ((EditorInputManager.GetMouseButtonDown(0))) { if (EditorInputManager.getControlKey()) { bcf.mask.Transfer(ref m.PointedUV._color, bcf.colorLinear.ToGamma()); } else { foreach (Vertex uvi in m.PointedUV.meshPoint.uvpoints) { bcf.mask.Transfer(ref uvi._color, Cfg.brushConfig.colorLinear.ToGamma()); } } m.edMesh.dirty_Color = true; } return(false); }
public override void BeforeGPUStroke(PlaytimePainter pntr, BrushConfig br, StrokeVector st, BrushType type) { if (br.IsA3Dbrush(pntr) && pntr.IsAtlased()) { var ats = GetAtlasedSection(); Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(ats.x, ats.y, atlasRows, 1)); } }
public void PrepareVolumeBlit(BrushConfig bc, ImageData id, float alpha, StrokeVector stroke, VolumeTexture volume) { PrepareBlit(bc, id, alpha, stroke); pos = (stroke.posFrom - volume.transform.position) / volume.size + 0.5f * Vector3.one; isVolumeBlit = true; slices = volume.h_slices; volHeight = volume.Height; texWidth = id.width; }
public override bool IsA3Dbrush(PlaytimePainter pntr, BrushConfig bc, ref bool overrideOther) { if (pntr.GetVolumeTexture() != null) { overrideOther = true; return(true); } return(false); }
public static void Paint(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> submeshIndex) { br.BlitMode.PrePaint(null, br, st); PrepareSphereBrush(rt.GetImgData(), br, st, null); TexMGMT.brushRendy.UseMeshAsBrush(go, mesh, submeshIndex); TexMGMT.Render(); AfterStroke(br); }
public override void AfterStroke(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { base.AfterStroke(pntr, br, st); if (br.decalRotationMethod == DecalRotationMethod.Random) { br.decalAngle = UnityEngine.Random.Range(-90f, 450f); TexMGMT.Shader_UpdateDecal(Cfg.brushConfig); //pntr.Dec//Update_Brush_Parameters_For_Preview_Shader(); } }
public void Shader_UpdateDecal(BrushConfig brush) { VolumetricDecal vd = Data.decals.TryGet(brush.selectedDecal); if (vd != null) { Shader.SetGlobalTexture("_VolDecalHeight", vd.heightMap); Shader.SetGlobalTexture("_VolDecalOverlay", vd.overlay); Shader.SetGlobalVector("_DecalParameters", new Vector4(brush.decalAngle * Mathf.Deg2Rad, (vd.type == VolumetricDecalType.Add) ? 1 : -1, Mathf.Clamp01(brush.speed / 10f), 0)); } }
public static void PaintAtlased(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> submeshIndex, int A_Textures_in_row) { br.BlitMode.PrePaint(null, br, st); Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, A_Textures_in_row, 1)); PrepareSphereBrush(rt.GetImgData(), br, st, null); TexMGMT.brushRendy.UseMeshAsBrush(go, mesh, submeshIndex); TexMGMT.Render(); AfterStroke(br); Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, 1, 0)); }
public void ShaderPrepareStroke(BrushConfig bc, float brushAlpha, ImageData id, StrokeVector stroke, PlaytimePainter pntr) { if (BigRT_pair == null) { UpdateBuffersState(); } bool isDoubleBuffer = (id.renderTexture == null); bool useSingle = (!isDoubleBuffer) || bc.IsSingleBufferBrush(); if ((!useSingle) && (!secondBufferUpdated)) { UpdateBufferTwo(); } if (stroke.firstStroke) { Shader_BrushCFG_Update(bc, brushAlpha, id.width, id.TargetIsRenderTexture(), stroke.useTexcoord2, pntr); } rtcam.targetTexture = id.CurrentRenderTexture(); if (isDoubleBuffer) { Shader.SetGlobalTexture(PainterDataAndConfig.DESTINATION_BUFFER, BigRT_pair[1]); } Shader shd = null; if (pntr != null) { foreach (var pl in Plugins) { Shader bs = useSingle ? pl.GetBrushShaderSingleBuffer(pntr) : pl.GetBrushShaderDoubleBuffer(pntr); if (bs != null) { shd = bs; break; } } } if (shd == null) { shd = useSingle ? bc.BlitMode.ShaderForSingleBuffer : bc.BlitMode.ShaderForDoubleBuffer; } brushRendy.Set(shd); }
public override bool MouseEventPointedVertex() { if ((EditorInputManager.GetMouseButton(0))) { if (PointedUV.SameAsLastFrame) { return(true); } BrushConfig bcf = Cfg.brushConfig; bcf.colorLinear.ToV4(ref PointedVertex.shadowBake, bcf.mask); MeshMGMT.edMesh.Dirty = true; return(true); } return(false); }
public override void PaintRenderTexture(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { ImageData id = pntr.ImgData; BeforeStroke(pntr, br, st); PrepareSphereBrush(id, br, st, pntr); if (!st.mouseDwn) { TexMGMT.brushRendy.UseMeshAsBrush(pntr); TexMGMT.Render(); } AfterStroke(pntr, br, st); }
public override bool MouseEventPointedTriangle() { if ((EditorInputManager.GetMouseButton(0))) { if (PointedTris.SameAsLastFrame) { return(true); } BrushConfig bcf = Cfg.brushConfig; foreach (var uv in PointedTris.vertexes) { bcf.colorLinear.ToV4(ref uv.meshPoint.shadowBake, bcf.mask); } MeshMGMT.edMesh.Dirty = true; return(true); } return(false); }
public virtual void AfterStroke(PlaytimePainter pntr, BrushConfig br, StrokeVector st) { pntr.AfterStroke(st); if (!br.IsSingleBufferBrush() && !br.IsA3Dbrush(pntr)) { TexMGMT.UpdateBufferSegment(); } if ((br.useMask) && (st.mouseUp) && (br.randomMaskOffset)) { br.maskOffset = new Vector2(UnityEngine.Random.Range(0f, 1f), UnityEngine.Random.Range(0f, 1f)); } foreach (var p in pntr.plugins) { p.AfterGPUStroke(pntr, br, st, this); } }
public bool PaintTexture2D_NEW(StrokeVector stroke, float brushAlpha, ImageData image, BrushConfig bc, PlaytimePainter pntr) { var volume = image.texture2D.GetVolumeTextureData(); if (image.CanUsePixelsForJob()) { var blitJob = new BlitJobs(); blitJob.PrepareVolumeBlit(bc, image, brushAlpha, stroke, volume); image.jobHandle = blitJob.Schedule(); JobHandle.ScheduleBatchedJobs(); return(true); } return(false); }
static void PrepareSphereBrush(ImageData id, BrushConfig br, StrokeVector stroke, PlaytimePainter pntr) { if (TexMGMT.BigRT_pair == null) { TexMGMT.UpdateBuffersState(); } if (stroke.mouseDwn) { stroke.posFrom = stroke.posTo; } TexMGMT.ShaderPrepareStroke(br, br.speed * 0.05f, id, stroke, null); Vector2 offset = id.offset - stroke.unRepeatedUV.Floor(); stroke.SetWorldPosInShader(); Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_EDITED_UV_OFFSET, new Vector4(id.tiling.x, id.tiling.y, offset.x, offset.y)); Shader.SetGlobalVector(PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS, new Vector4(0, 0, 1, 0)); }
public void PrepareBlit(BrushConfig bc, ImageData id, float brushAlpha, StrokeVector stroke) { values = id.pixelsForJob; pixelNumber = id.UvToPixelNumber(stroke.uvFrom); width = id.width; height = id.height; brAlpha = brushAlpha; half = (bc.Size(false)) / 2; smooth = bc.Type(true) != BrushTypePixel.Inst; blitJobBlitMode = bc.BlitMode.BlitJobFunction(); alpha = 1; r = bc.mask.GetFlag(BrushMask.R); g = bc.mask.GetFlag(BrushMask.G); b = bc.mask.GetFlag(BrushMask.B); a = bc.mask.GetFlag(BrushMask.A); csrc = bc.colorLinear.ToGamma(); }
public override bool MouseEventPointedLine() { if (EditorInputManager.GetMouseButton(0)) { if (PointedLine.SameAsLastFrame) { return(true); } BrushConfig bcf = Cfg.brushConfig; Vertex a = PointedLine.pnts[0]; Vertex b = PointedLine.pnts[1]; Color c = bcf.colorLinear.ToGamma(); a.meshPoint.SetColorOnLine(c, bcf.mask, b.meshPoint);//setColor(glob.colorSampler.color, glob.colorSampler.mask); b.meshPoint.SetColorOnLine(c, bcf.mask, a.meshPoint); MeshMGMT.edMesh.dirty_Color = true; return(true); } return(false); }
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 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 virtual bool PaintRenderTexture(StrokeVector stroke, ImageData image, BrushConfig bc, PlaytimePainter pntr) { return(false); }