public void AfterCameraRender(RenderTexture texture) { var size = RenderTextureBuffersManager.tinyTextureSize; int pixelsCount = size * size; var tiny = RenderTextureBuffersManager.GetDownscaleOf(texture, RenderTextureBuffersManager.tinyTextureSize, true); var pix = RenderTextureBuffersManager.GetMinSizeTexture().CopyFrom(tiny).GetPixels(); Color avg = Color.black; foreach (var p in pix) { avg += p; } var pcam = PainterCamera.GetOrCreateProjectorCamera(); GlobalBrush.Color = avg / pixelsCount; PainterShaderVariables.BrushColorProperty.GlobalValue = GlobalBrush.Color; PaintRenderTextureUvSpace(delayedPaintingConfiguration); delayedPaintingConfiguration = null; }
public bool PaintRenderTextureInternal(PaintCommand.UV cfg) { var stroke = cfg.Stroke; var image = cfg.TextureData; var bc = cfg.Brush; var vt = cfg.TextureData.GetVolumeTextureData(); //painter.GetVolumeTexture(); stroke.posFrom = stroke.posTo; BrushTypes.Sphere.Inst.BeforeStroke(cfg); //bc, stroke, painter); VOLUME_POSITION_N_SIZE_BRUSH.GlobalValue = vt.PosSize4Shader; VOLUME_H_SLICES_BRUSH.GlobalValue = vt.Slices4Shader; VOLUME_BRUSH_DIRECTION.GlobalValue = stroke.collisionNormal.ToVector4(smoothing); UseSmoothing.Enabled = smoothing > 0; image.useTexCoord2 = false; cfg.strokeAlphaPortion = Mathf.Clamp01(bc.Flow * 0.05f); TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(cfg); stroke.SetWorldPosInShader(); RenderTextureBuffersManager.Blit(null, image.CurrentRenderTexture(), TexMGMT.brushRenderer.GetMaterial().shader); BrushTypes.Sphere.Inst.AfterStroke(cfg); return(true); }
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 void PaintPixelsInRam(PaintCommand.UV command) { var painter= command.TryGetPainter(); if (!painter) return; painter.GetModule<TileableAtlasingComponentModule>()?.PaintTexture2D(command); }
public void PaintRenderTextureUvSpace(PaintCommand.UV command) { }
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 bool PaintTexture2D(PaintCommand.UV command) { Stroke stroke = command.Stroke; float brushAlpha = command.strokeAlphaPortion; TextureMeta image = command.TextureData; Brush bc = command.Brush; 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); }