Exemplo n.º 1
0
 private void Init(InkCanvas canvas)
 {
     material           = GetComponent <MeshRenderer>().sharedMaterial;
     defaultMainTexture = canvas.GetMainTexture(material.name);
     paintMainTexture   = canvas.GetPaintMainTexture(material.name);
     defaultNormalMap   = canvas.GetNormalTexture(material.name);
     paintNormalMap     = canvas.GetPaintNormalTexture(material.name);
     defaultHeightMap   = canvas.GetHeightTexture(material.name);
     paintHeightMap     = canvas.GetPaintHeightTexture(material.name);
     StartCoroutine(TextureLerp());
 }
Exemplo n.º 2
0
        private void OnWillRenderObject()
        {
            if (performanceOptimize && enabledFluid && Time.time - lastPaintedTime > fluidProcessStopTime)
            {
                enabledFluid = false;
            }

            if (!enabledFluid)
            {
                return;
            }

            foreach (var set in canvas.PaintDatas)
            {
                var materialName = set.material.name;
                var heightPaint  = canvas.GetPaintHeightTexture(materialName);
                if (heightPaint == null)
                {
                    var newHeightPaint = new RenderTexture(createTextureSize, createTextureSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                    SingleColorFill(newHeightPaint, Vector4.zero);
                    canvas.SetPaintHeightTexture(materialName, newHeightPaint);
                    heightPaint = newHeightPaint;
                    set.material.SetFloat("_Parallax", 0);
                }
                var heightTmp = RenderTexture.GetTemporary(heightPaint.width, heightPaint.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                heightFluid.SetFloat("_ScaleFactor", flowingForce);
                heightFluid.SetFloat("_Viscosity", easeOfDripping);
                heightFluid.SetFloat("_HorizontalSpread", horizontalSpread);
                heightFluid.SetFloat("_InfluenceOfNormal", influenceOfNormal);
                heightFluid.SetVector("_FlowDirection", flowDirection.normalized);
                if (canvas.GetNormalTexture(materialName) != null)
                {
                    heightFluid.SetTexture("_NormalMap", canvas.GetNormalTexture(materialName));
                }
                Graphics.Blit(heightPaint, heightTmp, heightFluid);
                Graphics.Blit(heightTmp, heightPaint);
                RenderTexture.ReleaseTemporary(heightTmp);

                if (useMainTextureFluid)
                {
                    var mainPaint = canvas.GetPaintMainTexture(materialName);
                    if (mainPaint == null)
                    {
                        var newMainPaint = new RenderTexture(createTextureSize, createTextureSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                        if (canvas.GetMainTexture(materialName) != null)
                        {
                            Graphics.Blit(canvas.GetMainTexture(materialName), newMainPaint);
                        }
                        canvas.SetPaintMainTexture(materialName, newMainPaint);
                        mainPaint = newMainPaint;
                    }
                    var mainTmp = RenderTexture.GetTemporary(mainPaint.width, mainPaint.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                    height2Color.SetTexture("_ColorMap", mainPaint);
                    height2Color.SetTexture("_BaseColor", canvas.GetMainTexture(materialName));
                    height2Color.SetFloat("_Alpha", alpha);
                    height2Color.SetFloat("_Border", AdhesionBorder);
                    Graphics.Blit(heightPaint, mainTmp, height2Color);
                    Graphics.Blit(mainTmp, mainPaint);
                    RenderTexture.ReleaseTemporary(mainTmp);
                }

                if (useNormalMapFluid)
                {
                    var normalPaint = canvas.GetPaintNormalTexture(materialName);
                    if (normalPaint == null)
                    {
                        var newNormalPaint = new RenderTexture(createTextureSize, createTextureSize, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                        //DXT5nm color initialization.
                        SingleColorFill(newNormalPaint, Vector4.one * 0.5f);
                        set.material.EnableKeyword("_NORMALMAP");
                        if (canvas.GetNormalTexture(materialName) != null)
                        {
                            Graphics.Blit(canvas.GetNormalTexture(materialName), newNormalPaint);
                        }
                        canvas.SetPaintNormalTexture(materialName, newNormalPaint);
                        normalPaint = newNormalPaint;
                    }
                    var normalTmp = RenderTexture.GetTemporary(normalPaint.width, normalPaint.height, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Linear);
                    height2Normal.SetTexture("_BumpMap", normalPaint);
                    height2Normal.SetFloat("_NormalScaleFactor", normalScaleFactor);
                    height2Normal.SetFloat("_Border", AdhesionBorder);
                    Graphics.Blit(heightPaint, normalTmp, height2Normal);
                    Graphics.Blit(normalTmp, normalPaint);
                    RenderTexture.ReleaseTemporary(normalTmp);
                }
            }
        }
Exemplo n.º 3
0
        private void OnWillRenderObject()
        {
            var heightPaint = canvas.GetPaintHeightTexture(materialName);

            if (heightPaint == null)
            {
                var newHeightPaint = new RenderTexture(createTextureSize, createTextureSize, 0);
                InitHeightMap(newHeightPaint);
                canvas.SetPaintHeightTexture(materialName, newHeightPaint);
                heightPaint = newHeightPaint;
            }
            var heightTmp = RenderTexture.GetTemporary(heightPaint.width, heightPaint.height);

            heightFluid.SetFloat("_ScaleFactor", flowingForce);
            heightFluid.SetFloat("_Viscosity", easeOfDripping);
            heightFluid.SetFloat("_HorizontalSpread", horizontalSpread);
            heightFluid.SetFloat("_InfluenceOfNormal", influenceOfNormal);
            heightFluid.SetVector("_FlowDirection", flowDirection.normalized);
            if (canvas.GetNormalTexture(materialName) != null)
            {
                heightFluid.SetTexture("_NormalMap", canvas.GetNormalTexture(materialName));
            }
            Graphics.Blit(heightPaint, heightTmp, heightFluid);
            Graphics.Blit(heightTmp, heightPaint);
            RenderTexture.ReleaseTemporary(heightTmp);

            if (useMainTextureFluid)
            {
                var mainPaint = canvas.GetPaintMainTexture(materialName);
                if (mainPaint == null)
                {
                    var newMainPaint = new RenderTexture(createTextureSize, createTextureSize, 0);
                    if (canvas.GetMainTexture(materialName) != null)
                    {
                        var tmp = RenderTexture.GetTemporary(newMainPaint.width, newMainPaint.height, 0);
                        Graphics.Blit(canvas.GetMainTexture(materialName), tmp);
                        Graphics.Blit(tmp, newMainPaint);
                        RenderTexture.ReleaseTemporary(tmp);
                    }
                    canvas.SetPaintMainTexture(materialName, newMainPaint);
                    mainPaint = newMainPaint;
                }
                var mainTmp = RenderTexture.GetTemporary(mainPaint.width, mainPaint.height);
                height2Color.SetTexture("_ColorMap", mainPaint);
                height2Color.SetFloat("_Alpha", alpha);
                height2Color.SetFloat("_Border", AdhesionBorder);
                Graphics.Blit(heightPaint, mainTmp, height2Color);
                Graphics.Blit(mainTmp, mainPaint);
                RenderTexture.ReleaseTemporary(mainTmp);
            }

            if (useNormalMapFluid)
            {
                var normalPaint = canvas.GetPaintNormalTexture(materialName);
                if (normalPaint == null)
                {
                    var newNormalPaint = new RenderTexture(createTextureSize, createTextureSize, 0);
                    if (canvas.GetNormalTexture(materialName) != null)
                    {
                        var tmp = RenderTexture.GetTemporary(newNormalPaint.width, newNormalPaint.height, 0);
                        Graphics.Blit(canvas.GetNormalTexture(materialName), tmp);
                        Graphics.Blit(tmp, newNormalPaint);
                        RenderTexture.ReleaseTemporary(tmp);
                    }
                    canvas.SetPaintNormalTexture(materialName, newNormalPaint);
                    normalPaint = newNormalPaint;
                }
                var normalTmp = RenderTexture.GetTemporary(normalPaint.width, normalPaint.height);
                height2Normal.SetTexture("_BumpMap", normalPaint);
                height2Normal.SetFloat("_NormalScaleFactor", normalScaleFactor);
                height2Normal.SetFloat("_Border", AdhesionBorder);
                Graphics.Blit(heightPaint, normalTmp, height2Normal);
                Graphics.Blit(normalTmp, normalPaint);
                RenderTexture.ReleaseTemporary(normalTmp);
            }
        }