public void penUpdate() { if (!penDown) { return; } uvcam.enabled = false; uvcam.gameObject.SetActive(true); Plane[] planes = GeometryUtility.CalculateFrustumPlanes(uvcam); bool detected = DokoDemoPainterPaintable.setGlobalUVMode(true, planes); if (detected) { RenderTexture prev = RenderTexture.active; RenderTexture renderTexture = RenderTexture.GetTemporary(1, 1, 16, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear, 1); uvcam.targetTexture = renderTexture; RenderTexture.active = renderTexture; Shader.SetGlobalTexture("_DDPPenLast", lastPenTex); Shader.SetGlobalFloat("_DDPDontSwitch", keepTarget ? 1.0f : 0.0f); Shader.SetGlobalFloat("_DDPInvisibleAlpha", paintInvisible ? 1.0f : 0.0f); uvcam.RenderWithShader(ddpdShader, ""); uvcam.targetTexture = null; RenderTexture.active = prev; DokoDemoPainterPaintable.setGlobalUVMode(false, planes); DokoDemoPainterPaintable.globalPaintAt(id, renderTexture, color, smoothTip, smoothTipExponent, radius, opacity, eraser); if (lastPenTex != null) { RenderTexture.ReleaseTemporary(lastPenTex); } lastPenTex = renderTexture; } uvcam.gameObject.SetActive(false); }
public void stampUpdate() { if (!stampActive) { return; } uvcam.enabled = false; uvcam.gameObject.SetActive(true); Plane[] planes = GeometryUtility.CalculateFrustumPlanes(uvcam); bool detected = DokoDemoPainterPaintable.setGlobalUVMode(true, planes); if (detected) { RenderTexture prev = RenderTexture.active; RenderTexture renderTexture = RenderTexture.GetTemporary(1, 1, 16, RenderTextureFormat.ARGBFloat, RenderTextureReadWrite.Linear, 1); uvcam.targetTexture = renderTexture; RenderTexture.active = renderTexture; Shader.SetGlobalTexture("_DDPPenLast", null); Shader.SetGlobalFloat("_DDPDontSwitch", 0.0f); Shader.SetGlobalFloat("_DDPInvisibleAlpha", paintInvisible ? 1.0f : 0.0f); uvcam.RenderWithShader(ddpdShader, ""); uvcam.targetTexture = null; if (deactiveStampAfterAttempt) { RenderTexture.active = renderTexture; Texture2D readTex = new Texture2D(1, 1, TextureFormat.RGBA32, false); readTex.ReadPixels(new Rect(0, 0, 1, 1), 0, 0); readTex.Apply(); if (readTex.GetPixel(0, 0).b > 0.0) { stampActive = false; } } RenderTexture.active = prev; DokoDemoPainterPaintable.setGlobalUVMode(false, planes); DokoDemoPainterPaintable.globalStampAt(renderTexture, stampTexture, stampPixelSize, stampAngle * Mathf.Deg2Rad, stampOpacity, enableTint, tintColor, tintStrength); RenderTexture.ReleaseTemporary(renderTexture); } uvcam.gameObject.SetActive(false); }