Beispiel #1
0
        public void PaintRenderTexture(StrokeVector stroke, TextureMeta 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));
            }
        }
Beispiel #2
0
        public void ChangeBufferTarget(TextureMeta newTarget, MaterialMeta mat, ShaderProperty.TextureValue parameter, PlaytimePainter painter)
        {
            if (newTarget != imgMetaUsingRendTex)
            {
                if (materialsUsingRenderTexture.Count > 0)
                {
                    PlaytimePainter.CheckSetOriginalShader();
                }

                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);
        }
Beispiel #3
0
        public static VolumeTexture GetVolumeTextureData(this TextureMeta id)
        {
            if (VolumePaintingCameraModule._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)
                {
                    VolumeTexture.all.RemoveAt(i);
                    i--;
                }
                else if (vt.ImageMeta != null && id == vt.ImageMeta)
                {
                    _lastFetchedVt      = vt;
                    id.isAVolumeTexture = true;
                    return(vt);
                }
            }

            return(null);
        }
Beispiel #4
0
 public BrushStrokePainterImage(StrokeVector s, TextureMeta id, BrushConfig br, PlaytimePainter pp)
 {
     stroke  = s;
     image   = id;
     brush   = br;
     painter = pp;
 }
Beispiel #5
0
            public override void PaintRenderTextureUvSpace(PaintCommand.UV command)
            {
                Brush       br = command.Brush;
                Stroke      st = command.Stroke;
                TextureMeta id = command.TextureData;

                BeforeStroke(command);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                command.strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f);

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(command);// br, br.Speed * 0.05f, id, st, out alphaBuffer, painter);

                RtBrush.localScale = Vector3.one * br.StrokeWidth(id.width, false);

                BrushMesh             = PainterCamera.BrushMeshGenerator.GetQuad();
                RtBrush.localRotation = Quaternion.identity;

                RtBrush.localPosition = st.BrushWorldPosition;

                TexMGMT.Render();

                AfterStroke(command);//painter, br, st, alphaBuffer, id);
            }
        public static Texture CurrentTexture(this TextureMeta 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);
        }
Beispiel #7
0
            public virtual void PaintRenderTextureUvSpace(PaintCommand.UV command)
            {
                TextureMeta textureMeta = command.TextureData;
                Brush       br          = command.Brush;
                Stroke      st          = command.Stroke;

                BeforeStroke(command);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                command.strokeAlphaPortion = Mathf.Clamp01(br.Flow * 0.05f);

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(command);

                var rb = RtBrush;

                rb.localScale = Vector3.one;
                var direction = st.DeltaUv;
                var length    = direction.magnitude;

                BrushMesh        = PainterCamera.BrushMeshGenerator.GetLongMesh(length * 256, br.StrokeWidth(textureMeta.width, false));
                rb.localRotation = Quaternion.Euler(new Vector3(0, 0,
                                                                (direction.x > 0 ? -1 : 1) * Vector2.Angle(Vector2.up, direction)));

                rb.localPosition = Stroke.BrushWorldPositionFrom((st.uvFrom + st.uvTo) * 0.5f);

                TexMGMT.Render();

                AfterStroke(command);
            }
 public void TryApplyBufferChangesTo(TextureMeta id)
 {
     if ((id != null) && (id == alphaBufferDataTarget))
     {
         FinalizePreviousAlphaDataTarget();
     }
 }
Beispiel #9
0
            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);
                }
            }
Beispiel #10
0
 public void TryDiscardBufferChangesTo(TextureMeta id)
 {
     if (id != null && id == alphaBufferDataTarget)
     {
         DiscardAlphaBuffer();
     }
 }
        /*  #region Encode & Decode
         *
         * public override CfgEncoder Encode() => this.EncodeUnrecognized()
         *    .Add_Reference("mat", material)
         *    .Add_IfNotZero("texInd", selectedTexture)
         *    .Add_IfTrue("pv", usePreviewShader)
         *    .Add_IfTrue("colToV", colorToVertexColorOnMerge)
         *    .Add("tfs", materialsTextureFields);
         *
         * public override bool Decode(string tg, string data)
         * {
         *   switch (tg)
         *    {
         *        case "mat": data.Decode_Reference(ref material); break;
         *        case "texInd":  selectedTexture = data.ToInt(); break;
         *        case "pv": usePreviewShader = data.ToBool(); break;
         *        case "tfs": data.Decode_List(out materialsTextureFields); break;
         *        case "colToV": colorToVertexColorOnMerge = data.ToBool(); break;
         *        default: return false;
         *    }
         *    return true;
         * }
         #endregion*/

        public void SetTextureOnLastTarget(TextureMeta id)
        {
            if (painterTarget)
            {
                painterTarget.SetTextureOnMaterial(bufferParameterTarget, id.CurrentTexture(), material);
            }
        }
Beispiel #12
0
            public override void PaintRenderTexture(PlaytimePainter painter, BrushConfig br, StrokeVector st)
            {
                BeforeStroke(br, st, painter);

                if (st.CrossedASeam())
                {
                    st.uvFrom = st.uvTo;
                }

                TextureMeta id = painter.TexMeta;

                bool alphaBuffer;

                TexMGMT.SHADER_STROKE_SEGMENT_UPDATE(br, br.Speed * 0.05f, id, st, out alphaBuffer, painter);

                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);
            }
Beispiel #13
0
        public override bool SetTextureOnMaterial(ShaderProperty.TextureValue field, TextureMeta 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);
        }
Beispiel #14
0
        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;
        }
Beispiel #15
0
 public virtual BlitFunctions.BlitModeFunction BlitFunctionTex2D(TextureMeta id)
 {
     if (id.isATransparentLayer)
     {
         return(BlitFunctions.AlphaBlitTransparent);
     }
     return(BlitFunctions.AlphaBlitOpaque);
 }
Beispiel #16
0
            public void Set(TextureMeta from, int globalOrder)
            {
                RenderTextureBuffersManager.Blit(from.CurrentRenderTexture(), rt);

                SetB(from, globalOrder);

                exclusive = from.renderTexture != null;
            }
        private void OnPostSaveTexture(TextureMeta id)
        {
            SetTextureOnMaterial(id);
            UpdateOrSetTexTarget(id.target);
            UpdateModules();

            id.UnsetAlphaSavePixel();
        }
Beispiel #18
0
        public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta id)
        {
            if (pixels == null)
            {
                ExtractPixels(set.diffuse, id?.width ?? set.width, id?.height ?? set.height);
            }

            return(pixels);
        }
        public static VolumeTexture GetVolumeTextureController(this TextureMeta id)
        {
            if (id != null && id.isAVolumeTexture)
            {
                return(id.GetVolumeTextureData());
            }

            return(null);
        }
Beispiel #20
0
        public static void Paint(StrokeVector stroke, float brushAlpha, TextureMeta 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) != BrushTypes.Pixel.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;
            }
        }
Beispiel #21
0
        public static RenderTexture Blit(Texture tex, TextureMeta id)
        {
            if (!tex || id == null)
            {
                return(null);
            }

            return(Blit(tex, id.CurrentRenderTexture()));
        }
Beispiel #22
0
            protected void SetB(TextureMeta from, int globalOrder)
            {
                order = globalOrder;

                foreach (var module in from.Modules)
                {
                    module.OnTextureBackup(this);
                }
            }
Beispiel #23
0
        public static VolumeTexture IsVolumeTexture(this TextureMeta id)
        {
            if (id != null && id.texture2D)
            {
                return(id.GetVolumeTextureData());
            }

            return(null);
        }
Beispiel #24
0
        public void AlphaBufferSetDirtyBeforeRender(TextureMeta id, Shader shade)
        {
            if (alphaBufferDataTarget != null && (alphaBufferDataTarget != id || alphaBufferDataShader != shade))
            {
                UpdateFromAlphaBuffer(alphaBufferDataTarget.CurrentRenderTexture(), alphaBufferDataShader);
            }

            alphaBufferDataTarget = id;
            alphaBufferDataShader = shade;
        }
Beispiel #25
0
            public Base SetKeyword(TextureMeta id)
            {
                foreach (var bs in AllModes)
                {
                    QcUnity.SetShaderKeyword(bs.ShaderKeyword(id), false);
                }

                QcUnity.SetShaderKeyword(ShaderKeyword(id), true);

                return(this);
            }
Beispiel #26
0
            public RenderTextureBackup(TextureMeta 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);
            }
Beispiel #27
0
        public List <Color[]> GetMipPixels(TextureSetForCombinedMaps set, TextureMeta 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);
        }
Beispiel #28
0
        public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta 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);
        }
Beispiel #29
0
        public override Color[] GetPixels(TextureSetForCombinedMaps set, TextureMeta 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);
        }
Beispiel #30
0
            public override void AfterStroke_Painter(PlaytimePainter painter, BrushConfig br, StrokeVector st,
                                                     bool alphaBuffer, TextureMeta id)
            {
                base.AfterStroke_Painter(painter, br, st, alphaBuffer, id);

                if (br.rotationMethod != RotationMethod.Random)
                {
                    return;
                }

                br.decalAngle = Random.Range(-90f, 450f);
                OnShaderBrushUpdate(Cfg.brushConfig);
            }