public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st) { BeforeStroke(painter, br, st); if (st.CrossedASeam()) { st.uvFrom = st.uvTo; } ImageMeta id = painter.ImgMeta; bool alphaBuffer; TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st, painter, out alphaBuffer); RtBrush.localScale = Vector3.one * br.StrokeWidth(id.width, false); BrushMesh = PainterCamera.BrushMeshGenerator.GetQuad(); RtBrush.localRotation = Quaternion.identity; RtBrush.localPosition = st.BrushWorldPosition; TexMGMT.Render(); AfterStroke_Painter(painter, br, st, alphaBuffer, id); }
public void DiscardChanges(ImageMeta id) { if (id != null && id == alphaBufferDataTarget) { DiscardAlphaBuffer(); } }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter) { var tex = id.CurrentTexture(); if (!painter.terrain) { return(false); } if (!field.HasUsageTag(PainterDataAndConfig.TERRAIN_CONTROL_TEXTURE)) { return(false); } var no = field.NameForDisplayPEGI[0].CharToInt(); if (no == 0) { PainterDataAndConfig.TerrainControlMain.GlobalValue = tex; } painter.terrain.terrainData.alphamapTextures[no] = id.texture2D; return(true); }
public static VolumeTexture GetVolumeTextureData(this ImageMeta id) { if (VolumePaintingModule._inst == null || id == null) { return(null); } if (_lastFetchedVt != null && _lastFetchedVt.ImageMeta != null && _lastFetchedVt.ImageMeta == id) { return(_lastFetchedVt); } for (var i = 0; i < VolumeTexture.all.Count; i++) { var vt = VolumeTexture.all[i]; if (vt == null) { VolumeTexture.all.RemoveAt(i); i--; } else if (vt.ImageMeta != null && id == vt.ImageMeta) { _lastFetchedVt = vt; id.isAVolumeTexture = true; return(vt); } } return(null); }
public void PaintRenderTexture(StrokeVector stroke, ImageMeta 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); //Debug.Log("Setting position: "+stroke.posTo); PainterCamera.GetProjectorCamera().RenderRightNow(this); } else { PaintRenderTexture(new BrushStrokePainterImage(stroke, image, bc, painter)); } }
public void ChangeBufferTarget(ImageMeta newTarget, MaterialMeta mat, ShaderProperty.TextureValue parameter, PlaytimePainter painter) { if (newTarget != imgMetaUsingRendTex) { if (materialsUsingRenderTexture.Count > 0) { PlaytimePainter.SetOriginalShader(); } if (imgMetaUsingRendTex != null) { if (imgMetaUsingRendTex.texture2D) { imgMetaUsingRendTex.RenderTexture_To_Texture2D(); } imgMetaUsingRendTex.destination = TexTarget.Texture2D; foreach (var m in materialsUsingRenderTexture) { m.SetTextureOnLastTarget(imgMetaUsingRendTex); } } materialsUsingRenderTexture.Clear(); autodisabledBufferTarget = null; imgMetaUsingRendTex = newTarget; } mat.bufferParameterTarget = parameter; mat.painterTarget = painter; materialsUsingRenderTexture.Add(mat); }
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 BrushStrokePainterImage(StrokeVector s, ImageMeta id, BrushConfig br, PlaytimePainter pp) { stroke = s; image = id; brush = br; painter = pp; }
public void SetTextureOnLastTarget(ImageMeta id) { if (painterTarget) { painterTarget.SetTextureOnMaterial(bufferParameterTarget, id.CurrentTexture(), material); } }
public static Texture CurrentTexture(this ImageMeta id) { if (id == null) { return(null); } if (id.other) { return(id.other); } switch (id.destination) { case TexTarget.RenderTexture: if (id.renderTexture != null) { return(id.renderTexture); } if (PainterCamera.Inst.imgMetaUsingRendTex == id) { return(PainterCamera.FrontBuffer); } id.destination = TexTarget.Texture2D; return(id.texture2D); case TexTarget.Texture2D: return(id.texture2D); } return(null); }
public virtual BlitFunctions.BlitModeFunction BlitFunctionTex2D(ImageMeta id) { if (id.isATransparentLayer) { return(BlitFunctions.AlphaBlitTransparent); } return(BlitFunctions.AlphaBlitOpaque); }
public void Set(ImageMeta from, int globalOrder) { RenderTextureBuffersManager.Blit(from.CurrentRenderTexture(), rt); SetB(from, globalOrder); exclusive = from.renderTexture != null; }
public static void Paint(StrokeVector stroke, float brushAlpha, ImageMeta image, BrushConfig bc, PlaytimePainter painter) { if (image?.Pixels == null) { return; } var uvCoords = stroke.uvFrom; brAlpha = brushAlpha; bc.PrepareCpuBlit(image); var iHalf = (int)(half); Vector2 offset; var tmp = image.UvToPixelNumber(uvCoords, out offset); var smooth = bc.GetBrushType(true) != BrushTypePixel.Inst; if (smooth) { iHalf += 1; offset = Vector2.zero; } var hf = half - 0.5f; var halfFromX = Mathf.RoundToInt(-hf + offset.x); var halfFromY = Mathf.RoundToInt(-hf + offset.y); var halfToX = Mathf.RoundToInt(hf + offset.x); var halfToY = Mathf.RoundToInt(hf + offset.y); var fromX = tmp.x + halfFromX; tmp.y += halfFromY; var pixels = image.Pixels; for (y = halfFromY; y <= halfToY; y++) { tmp.x = fromX; for (x = halfFromX; x <= halfToX; x++) { if (alphaMode()) { blitMode(ref pixels[image.PixelNo(tmp)]); } tmp.x += 1; } tmp.y += 1; } }
public static VolumeTexture IsVolumeTexture(this ImageMeta id) { if (id != null && id.texture2D) { return(id.GetVolumeTextureData()); } return(null); }
private void UpdateImageMeta() { if (ImageMeta == null) { return; } ImageMeta.isAVolumeTexture = true; ImageMeta.Rename(name + hSlices); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, ImageMeta id) { if (pixels == null) { ExtractPixels(set.diffuse, id?.width ?? set.width, id?.height ?? set.height); } return(pixels); }
public void AlphaBufferSetDirtyBeforeRender(ImageMeta id, Shader shade) { if (alphaBufferDataTarget != null && (alphaBufferDataTarget != id || alphaBufferDataShader != shade)) { UpdateFromAlphaBuffer(alphaBufferDataTarget.CurrentRenderTexture(), alphaBufferDataShader); } alphaBufferDataTarget = id; alphaBufferDataShader = shade; }
public void ApplyAllChangesTo(ImageMeta id) { if (id != null) { if (id == alphaBufferDataTarget) { FinalizePreviousAlphaDataTarget(); } } }
public RenderTextureBackup(ImageMeta from, int globalOrder) { RenderTexture frt = from.CurrentRenderTexture(); rt = new RenderTexture(from.width, from.height, 0, RenderTextureFormat.ARGB32, frt.sRGB ? RenderTextureReadWrite.sRGB : RenderTextureReadWrite.Linear) { filterMode = frt.filterMode }; Set(from, globalOrder); }
public BlitMode SetKeyword(ImageMeta id) { foreach (var bs in AllModes) { UnityUtils.SetShaderKeyword(bs.ShaderKeyword(id), false); } UnityUtils.SetShaderKeyword(ShaderKeyword(id), true); return(this); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, ImageMeta 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); }
public List <Color[]> GetMipPixels(TextureSetForCombinedMaps set, ImageMeta 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 virtual void UpdateMaterials() { materials.SetVolumeTexture(this); if (!setForGlobal) { return; } PositionAndScaleProperty.SetGlobal(PosSize4Shader); SlicesShadeProperty.SetGlobal(Slices4Shader); TextureInShaderProperty.SetGlobal(ImageMeta.CurrentTexture()); }
public override Color[] GetPixels(TextureSetForCombinedMaps set, ImageMeta 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, ImageMeta 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, ImageMeta 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); }
public static RenderTexture Blit(Texture tex, ImageMeta id) { if (!tex || id == null) { return(null); } var mat = TempMaterial(Data.pixPerfectCopy); var dst = id.CurrentRenderTexture(); Graphics.Blit(tex, dst, mat); AfterBlit(dst); return(dst); }
private static void PrepareSphereBrush(ImageMeta id, BrushConfig br, StrokeVector stroke, PlaytimePainter painter, out bool alphaBuffer) { if (stroke.mouseDwn) { stroke.posFrom = stroke.posTo; } TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, stroke, painter, out alphaBuffer); var offset = id.offset - stroke.unRepeatedUv.Floor(); stroke.SetWorldPosInShader(); PainterDataAndConfig.BRUSH_EDITED_UV_OFFSET.GlobalValue = new Vector4(id.tiling.x, id.tiling.y, offset.x, offset.y); PainterDataAndConfig.BRUSH_ATLAS_SECTION_AND_ROWS.GlobalValue = new Vector4(0, 0, 1, 0); }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter) { if (!CorrectField(field, painter)) { return(false); } if (id != null && id.texture2D) { painter.terrainHeightTexture = id.texture2D; } var tex = id.CurrentTexture(); PainterDataAndConfig.TerrainHeight.GlobalValue = tex; return(true); }
public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, ImageMeta id, PlaytimePainter painter) { if (!field.IsGlobalVolume()) { return(false); } var gl = VolumeTexture.GetGlobal(field); if (gl != null) { gl.ImageMeta = id; gl.UpdateMaterials(); } return(true); }