private void Init(DynamicCanvas 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()); }
private void OnWillRenderObject() { //HeightMapを垂らす var heightPaint = canvas.GetPaintHeightTexture(materialName); if (heightPaint == null) { var newHeightPaint = new RenderTexture(CREATE_TEXTURE_SIZE, CREATE_TEXTURE_SIZE, 0); InitHeightMap(newHeightPaint); canvas.SetPaintHeightTexture(materialName, newHeightPaint); heightPaint = newHeightPaint; } var heightTmp = RenderTexture.GetTemporary(heightPaint.width, heightPaint.height); heightFluid.SetFloat("_ScaleFactor", flowingForce); heightFluid.SetFloat("_Viscosity", viscosity); heightFluid.SetVector("_FlowDirection", flowDirection.normalized); Graphics.Blit(heightPaint, heightTmp, heightFluid); Graphics.Blit(heightTmp, heightPaint); RenderTexture.ReleaseTemporary(heightTmp); //HeightMapからMainTexture生成 var mainPaint = canvas.GetPaintMainTexture(materialName); if (mainPaint == null) { var newMainPaint = new RenderTexture(CREATE_TEXTURE_SIZE, CREATE_TEXTURE_SIZE, 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); Graphics.Blit(heightPaint, mainTmp, height2Color); Graphics.Blit(mainTmp, mainPaint); RenderTexture.ReleaseTemporary(mainTmp); //HeightMapからNormalMap生成 var normalPaint = canvas.GetPaintNormalTexture(materialName); if (normalPaint == null) { var newNormalPaint = new RenderTexture(CREATE_TEXTURE_SIZE, CREATE_TEXTURE_SIZE, 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); Graphics.Blit(heightPaint, normalTmp, height2Normal); Graphics.Blit(normalTmp, normalPaint); RenderTexture.ReleaseTemporary(normalTmp); }