public static void PrepareCpuBlit(this BrushConfig bc, ImageMeta id) { half = (bc.Size(false)) / 2; var smooth = bc.GetBrushType(true) != BrushTypePixel.Inst; if (smooth) { alphaMode = CircleAlpha; } else { alphaMode = NoAlpha; } blitMode = bc.GetBlitMode(true).BlitFunctionTex2D(id); alpha = 1; var m = bc.mask; r = m.HasFlag(BrushMask.R); g = m.HasFlag(BrushMask.G); b = m.HasFlag(BrushMask.B); a = m.HasFlag(BrushMask.A); cSrc = bc.Color; }
public virtual void AfterStroke_Painter(PlaytimePainter painter, BrushConfig br, StrokeVector st, bool alphaBuffer, TextureMeta id) { painter.AfterStroke(st); if (br.useMask && st.MouseUpEvent && br.randomMaskOffset) { br.maskOffset = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)); } if (alphaBuffer) { var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit; if (painter.NotUsingPreview) { TexMGMT.UpdateFromAlphaBuffer(id.CurrentRenderTexture(), sh); } else { TexMGMT.AlphaBufferSetDirtyBeforeRender(id, sh); } } else if (!br.IsSingleBufferBrush() && !br.IsA3DBrush(painter)) { TexMGMT.UpdateBufferSegment(); } foreach (var p in painter.Modules) { p.AfterGpuStroke(br, st, this); } }
public void SHADER_STROKE_SEGMENT_UPDATE(BrushConfig bc, float brushAlpha, TextureMeta id, StrokeVector stroke, out bool alphaBuffer, PlaytimePainter pntr = null) { CheckPaintingBuffers(); var isDoubleBuffer = !id.renderTexture; var useSingle = !isDoubleBuffer || bc.IsSingleBufferBrush(); var blitMode = bc.GetBlitMode(false); alphaBuffer = !useSingle && bc.useAlphaBuffer && bc.GetBrushType(false).SupportsAlphaBufferPainting&& blitMode.SupportsAlphaBufferPainting; Shader shd = null; if (pntr) { foreach (var pl in CameraModuleBase.BrushPlugins) { var bs = useSingle ? pl.GetBrushShaderSingleBuffer(pntr) : pl.GetBrushShaderDoubleBuffer(pntr); if (!bs) { continue; } shd = bs; break; } } if (!shd) { if (alphaBuffer) { shd = blitMode.ShaderForAlphaOutput; AlphaBufferSetDirtyBeforeRender(id, blitMode.ShaderForAlphaBufferBlit); } else { shd = useSingle ? blitMode.ShaderForSingleBuffer : blitMode.ShaderForDoubleBuffer; } } if (!useSingle && !RenderTextureBuffersManager.secondBufferUpdated) { RenderTextureBuffersManager.UpdateBufferTwo(); } //if (stroke.firstStroke) SHADER_BRUSH_UPDATE(bc, brushAlpha, id, pntr); TargetTexture = alphaBuffer ? AlphaBuffer : id.CurrentRenderTexture(); if (isDoubleBuffer) { PainterShaderVariables.DESTINATION_BUFFER.GlobalValue = BackBuffer; } CurrentShader = shd; }
public static void Paint(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> subMeshIndex) { br.GetBlitMode(false).PrePaint(null, br, st); bool alphaBuffer; PrepareSphereBrush(rt.GetImgData(), br, st, null, out alphaBuffer); TexMGMT.brushRenderer.UseMeshAsBrush(go, mesh, subMeshIndex); TexMGMT.Render(); AfterStroke_NoPainter(br, alphaBuffer, rt); }
public static void Paint(RenderTexture rt, GameObject go, SkinnedMeshRenderer skinner, BrushConfig br, StrokeVector st, int subMeshIndex) { br.GetBlitMode(false).PrePaint(null, br, st); bool alphaBuffer; PrepareSphereBrush(rt.GetTextureMeta(), br, st, out alphaBuffer); TexMGMT.brushRenderer.UseSkinMeshAsBrush(go, skinner, subMeshIndex); TexMGMT.Render(); AfterStroke_NoPainter(br, alphaBuffer, rt); }
protected static void AfterStroke_NoPainter(BrushConfig br, bool alphaBuffer, RenderTexture rt = null) { if (br.useMask && br.randomMaskOffset) { br.maskOffset = new Vector2(Random.Range(0f, 1f), Random.Range(0f, 1f)); } if (alphaBuffer) { var sh = br.GetBlitMode(false).ShaderForAlphaBufferBlit; TexMGMT.UpdateFromAlphaBuffer(rt, sh); } }
public static void PaintAtlased(RenderTexture rt, GameObject go, Mesh mesh, BrushConfig br, StrokeVector st, List <int> subMeshIndex, int aTexturesInRow) { br.GetBlitMode(false).PrePaint(null, br, st); PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, aTexturesInRow, 1); bool alphaBuffer; PrepareSphereBrush(rt.GetImgData(), br, st, null, out alphaBuffer); TexMGMT.brushRenderer.UseMeshAsBrush(go, mesh, subMeshIndex); TexMGMT.Render(); AfterStroke_NoPainter(br, alphaBuffer, rt); PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0); }
public static void PrepareCpuBlit(this BrushConfig bc, TextureMeta id) { half = (bc.Size(false)) / 2; var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst; if (smooth) { alphaMode = CircleAlpha; } else { alphaMode = NoAlpha; } blitMode = bc.GetBlitMode(true).BlitFunctionTex2D(id); alpha = 1; Set(bc.mask); cSrc = bc.Color; }
public static bool IsSingleBufferBrush(this BrushConfig b) => (PainterCamera.Inst.IsLinearColorSpace && b.GetBlitMode(false).SupportedBySingleBuffer&& b.GetBrushType(false).SupportedBySingleBuffer&& b.PaintingRGB);
public bool PaintTexture2D(StrokeVector stroke, float brushAlpha, TextureMeta image, BrushConfig bc, PlaytimePainter painter) { if (!painter.IsAtlased()) { return(false); } var uvCoords = stroke.uvFrom; var atlasedSection = GetAtlasedSection(); sectorSize = image.width / atlasRows; atlasSector.From(atlasedSection * sectorSize); BlitFunctions.brAlpha = brushAlpha; BlitFunctions.half = (bc.Size(false)) / 2; var iHalf = Mathf.FloorToInt(BlitFunctions.half - 0.5f); var smooth = bc.GetBrushType(true) != BrushTypes.Pixel.Inst; if (smooth) { BlitFunctions.alphaMode = BlitFunctions.CircleAlpha; } else { BlitFunctions.alphaMode = BlitFunctions.NoAlpha; } BlitFunctions.blitMode = bc.GetBlitMode(true).BlitFunctionTex2D(image); if (smooth) { iHalf += 1; } BlitFunctions.alpha = 1; BlitFunctions.Set(bc.mask); BlitFunctions.cSrc = bc.Color; var tmp = image.UvToPixelNumber(uvCoords); var fromX = tmp.x - iHalf; tmp.y -= iHalf; var pixels = image.Pixels; for (BlitFunctions.y = -iHalf; BlitFunctions.y < iHalf + 1; BlitFunctions.y++) { tmp.x = fromX; for (BlitFunctions.x = -iHalf; BlitFunctions.x < iHalf + 1; BlitFunctions.x++) { if (BlitFunctions.alphaMode()) { var sx = tmp.x - atlasSector.x; var sy = tmp.y - atlasSector.y; sx %= sectorSize; if (sx < 0) { sx += sectorSize; } sy %= sectorSize; if (sy < 0) { sy += sectorSize; } BlitFunctions.blitMode(ref pixels[((atlasSector.y + sy)) * image.width + (atlasSector.x + sx)]); } tmp.x += 1; } tmp.y += 1; } return(true); }
public void SHADER_BRUSH_UPDATE(BrushConfig brush = null, float brushAlpha = 1, TextureMeta id = null, PlaytimePainter painter = null) { if (brush == null) { brush = GlobalBrush; } if (id == null && painter) { id = painter.TexMeta; } brush.previewDirty = false; if (id == null) { return; } float textureWidth = id.width; var rendTex = id.TargetIsRenderTexture(); var brushType = brush.GetBrushType(!rendTex); var blitMode = brush.GetBlitMode(!rendTex); var is3DBrush = brush.IsA3DBrush(painter); var useAlphaBuffer = (brush.useAlphaBuffer && blitMode.SupportsAlphaBufferPainting && rendTex); PainterShaderVariables.BrushColorProperty.GlobalValue = brush.Color; PainterShaderVariables.BrushMaskProperty.GlobalValue = brush.mask.ToVector4(); float useTransparentLayerBackground = 0; PainterShaderVariables.OriginalTextureTexelSize.GlobalValue = new Vector4( 1f / id.width, 1f / id.height, id.width, id.height ); if (id.isATransparentLayer) { var md = painter.MatDta; var mat = md.material; if (md != null && md.usePreviewShader && mat) { var mt = mat.mainTexture; PainterShaderVariables.TransparentLayerUnderProperty.GlobalValue = mt; useTransparentLayerBackground = (mt && (id != mt.GetImgDataIfExists())) ? 1 : 0; } } brushType.OnShaderBrushUpdate(brush); if (rendTex) { PainterShaderVariables.SourceMaskProperty.GlobalValue = brush.useMask ? Data.masks.TryGet(brush.selectedSourceMask) : null; } PainterShaderVariables.MaskDynamicsProperty.GlobalValue = new Vector4( brush.maskTiling, rendTex ? brush.hardness * brush.hardness : 0, // y - Hardness is 0 to do correct preview for Texture2D brush ((brush.flipMaskAlpha && brush.useMask) ? 0 : 1), // z - flip mask if any (brush.maskFromGreyscale && brush.useMask) ? 1 : 0); PainterShaderVariables.MaskOffsetProperty.GlobalValue = brush.maskOffset.ToVector4(); PainterShaderVariables.BrushFormProperty.GlobalValue = new Vector4( brushAlpha, // x - transparency brush.Size(is3DBrush), // y - scale for sphere brush.Size(is3DBrush) / textureWidth, // z - scale for uv space brush.blurAmount); // w - blur amount PainterShaderVariables.AlphaBufferConfigProperty.GlobalValue = new Vector4( brush.alphaLimitForAlphaBuffer, brush.worldSpaceBrushPixelJitter ? 1 : 0, useAlphaBuffer ? 1 : 0, 0); PainterShaderVariables.AlphaPaintingBuffer.GlobalValue = AlphaBuffer; brushType.SetKeyword(id.useTexCoord2); QcUnity.SetShaderKeyword(PainterShaderVariables.BRUSH_TEXCOORD_2, id.useTexCoord2); //if (blitMode.SupportsTransparentLayer) QcUnity.SetShaderKeyword(PainterShaderVariables.TARGET_TRANSPARENT_LAYER, id.isATransparentLayer); blitMode.SetKeyword(id).SetGlobalShaderParameters(); if (rendTex && blitMode.UsingSourceTexture) { PainterShaderVariables.SourceTextureProperty.GlobalValue = Data.sourceTextures.TryGet(brush.selectedSourceTexture); PainterShaderVariables.TextureSourceParameters.GlobalValue = new Vector4( (float)brush.srcColorUsage, brush.clampSourceTexture ? 1f : 0f, useTransparentLayerBackground, brush.ignoreSrcTextureTransparency ? 1f : 0f ); } }
public void SHADER_BRUSH_UPDATE(BrushConfig brush = null, float brushAlpha = 1, ImageMeta id = null, PlaytimePainter painter = null) { if (brush == null) { brush = GlobalBrush; } if (!painter) { painter = PlaytimePainter.selectedInPlaytime; } if (id == null && painter) { id = painter.ImgMeta; } brush.previewDirty = false; if (id == null) { return; } float textureWidth = id.width; var rendTex = id.TargetIsRenderTexture(); var brushType = brush.GetBrushType(!rendTex); var blitMode = brush.GetBlitMode(!rendTex); var is3DBrush = brush.IsA3DBrush(painter); //var isDecal = rendTex && brushType.IsUsingDecals; var useAlphaBuffer = (brush.useAlphaBuffer && blitMode.SupportsAlphaBufferPainting && rendTex); BrushColorProperty.GlobalValue = brush.Color; BrushMaskProperty.GlobalValue = new Vector4( BrushExtensions.HasFlag(brush.mask, BrushMask.R) ? 1 : 0, BrushExtensions.HasFlag(brush.mask, BrushMask.G) ? 1 : 0, BrushExtensions.HasFlag(brush.mask, BrushMask.B) ? 1 : 0, BrushExtensions.HasFlag(brush.mask, BrushMask.A) ? 1 : 0); float useTransparentLayerBackground = 0; if (id.isATransparentLayer) { var md = painter.MatDta; if (md != null && md.usePreviewShader && md.material) { var mt = md.material.mainTexture; TransparentLayerUnderProperty.GlobalValue = mt; useTransparentLayerBackground = (mt && (id != mt.GetImgDataIfExists())) ? 1 : 0; } } brushType.OnShaderBrushUpdate(brush); //if (isDecal) // SHADER_DECAL_UPDATE(brush); if (rendTex) { SourceMaskProperty.GlobalValue = brush.useMask ? Data.masks.TryGet(brush.selectedSourceMask) : null; } MaskDynamicsProperty.GlobalValue = new Vector4( brush.maskTiling, rendTex ? brush.hardness * brush.hardness : 0, // y - Hardness is 0 to do correct preview for Texture2D brush ((brush.flipMaskAlpha || brush.useMask) ? 0 : 1), (brush.maskFromGreyscale && brush.useMask) ? 1 : 0); MaskOffsetProperty.GlobalValue = brush.maskOffset.ToVector4(); BrushFormProperty.GlobalValue = new Vector4( brushAlpha, // x - transparency brush.Size(is3DBrush), // y - scale for sphere brush.Size(is3DBrush) / textureWidth, // z - scale for uv space brush.blurAmount); // w - blur amount AlphaBufferConfigProperty.GlobalValue = new Vector4( brush.alphaLimitForAlphaBuffer, brush.worldSpaceBrushPixelJitter ? 1 : 0, useAlphaBuffer ? 1 : 0, 0); AlphaPaintingBuffer.GlobalValue = AlphaBuffer; brushType.SetKeyword(id.useTexCoord2); UnityUtils.SetShaderKeyword(PainterDataAndConfig.BRUSH_TEXCOORD_2, id.useTexCoord2); if (blitMode.SupportsTransparentLayer) { UnityUtils.SetShaderKeyword(PainterDataAndConfig.TARGET_TRANSPARENT_LAYER, id.isATransparentLayer); } blitMode.SetKeyword(id).SetGlobalShaderParameters(); if (rendTex && blitMode.UsingSourceTexture) { SourceTextureProperty.GlobalValue = Data.sourceTextures.TryGet(brush.selectedSourceTexture); TextureSourceParameters.GlobalValue = new Vector4( (float)brush.srcColorUsage, brush.clampSourceTexture ? 1f : 0f, useTransparentLayerBackground, brush.ignoreSrcTextureTransparency ? 1f : 0f ); } }