Compare commits

...

7 Commits

Author SHA1 Message Date
mob-sakai ea7d98dc5e release v2.8.2 2018-09-26 22:40:48 +09:00
mob-sakai 77ebcf2b7a update change log 2018-09-26 22:40:48 +09:00
mob-sakai 773f8cf4ae High Serria 2018-09-26 22:09:40 +09:00
mob-sakai c792be9626 Update readme 2018-09-26 22:02:43 +09:00
mob-sakai 1110bf3dad Update gitignore 2018-09-26 16:51:12 +09:00
mob-sakai 4dfdcd76ab fix #125; UICapturedEffectImage does not work with Lightweight Render Pipeline LWRP 2018-09-26 16:51:12 +09:00
mob-sakai 385c082fb4 fix #126; When "UI-Effect.mat" is created automatically, Unity hangs up 2018-09-25 10:49:10 +09:00
8 changed files with 135 additions and 166 deletions
+6
View File
@@ -36,3 +36,9 @@ sysinfo.txt
*.unitypackage
build.app
unity.log
.vs/
_Android/
_iOS/
_WebGL/
_Standalone/
@@ -1,5 +1,6 @@
#if UNITY_EDITOR
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEditor;
@@ -11,6 +12,8 @@ namespace Coffee.UIExtensions
{
static readonly StringBuilder s_StringBuilder = new StringBuilder ();
static readonly Dictionary<string, Material> s_MaterialMap = new Dictionary<string, Material> ();
public static Material GetOrGenerateMaterialVariant (Shader shader, params object[] append)
{
if (!shader) {
@@ -34,35 +37,46 @@ namespace Coffee.UIExtensions
return mat;
}
var variantName = GetVariantName (shader, append);
string variantName = GetVariantName (shader, append);
if(s_MaterialMap.TryGetValue(variantName, out mat) && mat)
{
return mat;
}
Debug.Log ("Generate material : " + variantName);
mat = new Material (shader);
mat.shaderKeywords = keywords;
mat.name = variantName;
mat.hideFlags |= HideFlags.NotEditable;
s_MaterialMap [variantName] = mat;
bool isMainAsset = append.Cast<int> ().All (x => x == 0);
EditorApplication.delayCall += () => SaveMaterial (mat, shader, isMainAsset);
return mat;
}
static void SaveMaterial (Material mat, Shader shader, bool isMainAsset)
{
string materialPath = GetDefaultMaterialPath (shader);
#if UIEFFECT_SEPARATE
string dir = Path.GetDirectoryName(GetDefaultMaterialPath (shader));
string materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
string dir = Path.GetDirectoryName(materialPath);
materialPath = Path.Combine(Path.Combine(dir, "Separated"), mat.name + ".mat");
isMainAsset = true;
#endif
if (isMainAsset)
{
Directory.CreateDirectory (Path.GetDirectoryName (materialPath));
AssetDatabase.CreateAsset (mat, materialPath);
AssetDatabase.SaveAssets ();
#else
if (append.Cast<int> ().All (x => x == 0)) {
string materialPath = GetDefaultMaterialPath (shader);
Directory.CreateDirectory (Path.GetDirectoryName (materialPath));
AssetDatabase.CreateAsset (mat, materialPath);
AssetDatabase.SaveAssets ();
} else {
}
else
{
GetOrGenerateMaterialVariant (shader);
string materialPath = GetDefaultMaterialPath (shader);
mat.hideFlags |= HideFlags.HideInHierarchy;
AssetDatabase.AddObjectToAsset (mat, materialPath);
}
#endif
return mat;
AssetDatabase.SaveAssets ();
}
public static Material GetMaterial (Shader shader, params object[] append)
@@ -188,9 +188,20 @@ namespace Coffee.UIExtensions
/// </summary>
public void GetDesamplingSize(DesamplingRate rate, out int w, out int h)
{
var cam = canvas.worldCamera ?? Camera.main;
h = cam.pixelHeight;
w = cam.pixelWidth;
#if UNITY_EDITOR
if (!Application.isPlaying)
{
var res = UnityEditor.UnityStats.screenRes.Split('x');
w = int.Parse(res[0]);
h = int.Parse(res[1]);
}
else
#endif
{
w = Screen.width;
h = Screen.height;
}
if (rate == DesamplingRate.None)
return;
@@ -212,6 +223,7 @@ namespace Coffee.UIExtensions
/// </summary>
public void Capture()
{
// Fit to screen.
var rootCanvas = canvas.rootCanvas;
if (m_FitToScreen)
{
@@ -222,10 +234,7 @@ namespace Coffee.UIExtensions
rectTransform.position = rootTransform.position;
}
// Camera for command buffer.
_camera = canvas.worldCamera ?? Camera.main;
// Cache id for RT.
// Cache some ids.
if (s_CopyId == 0)
{
s_CopyId = Shader.PropertyToID("_UIEffectCapturedImage_ScreenCopyId");
@@ -234,24 +243,25 @@ namespace Coffee.UIExtensions
s_EffectFactorId = Shader.PropertyToID("_EffectFactor");
s_ColorFactorId = Shader.PropertyToID("_ColorFactor");
s_CommandBuffer = new CommandBuffer();
}
// If size of generated result RT has changed, relese it.
int w, h;
GetDesamplingSize(m_DesamplingRate, out w, out h);
// If target texture exists, release result RT.
if (m_TargetTexture)
{
_rtToRelease = _rt;
_Release(ref _rt);
}
else
{
// If size of result RT has changed, release it.
int w, h;
GetDesamplingSize (m_DesamplingRate, out w, out h);
if (_rt && (_rt.width != w || _rt.height != h))
{
_rtToRelease = _rt;
_rt = null;
_Release (ref _rt);
}
// Generate result RT.
// Generate RT for result.
if (_rt == null)
{
_rt = new RenderTexture(w, h, 0, RenderTextureFormat.ARGB32, RenderTextureReadWrite.Default);
@@ -266,124 +276,73 @@ namespace Coffee.UIExtensions
void SetupCommandBuffer()
{
if (_buffer != null)
{
return;
}
bool isOverlay = canvas.rootCanvas.renderMode == RenderMode.ScreenSpaceOverlay;
int w, h;
GetDesamplingSize(m_DesamplingRate, out w, out h);
var rtId = new RenderTargetIdentifier(m_TargetTexture ? m_TargetTexture : _rt);
// Material for effect.
Material mat = effectMaterial;
_buffer = new CommandBuffer();
_buffer.name = mat ? mat.name : "noeffect";
if(s_CommandBuffer == null)
{
s_CommandBuffer = new CommandBuffer ();
}
s_CommandBuffer.name = mat ? mat.name : "noeffect";
if (_rt)
{
_rt.name = _buffer.name;
_rt.name = s_CommandBuffer.name;
}
// Copy to temporary RT.
_buffer.GetTemporaryRT(s_CopyId, -1, -1, 0, m_FilterMode);
if (isOverlay)
{
if (!s_renderedResult)
{
s_renderedResult = new Texture2D(Screen.width, Screen.height, TextureFormat.ARGB32, false, false);
s_renderedResult.filterMode = FilterMode.Point;
}
else if (s_renderedResult.width != Screen.width || s_renderedResult.height != Screen.height)
{
s_renderedResult.Resize(Screen.width, Screen.height, TextureFormat.ARGB32, false);
}
// [1] Capture from back buffer (back buffer -> copied screen).
int w, h;
GetDesamplingSize(DesamplingRate.None, out w, out h);
s_CommandBuffer.GetTemporaryRT(s_CopyId, w, h, 0, m_FilterMode);
#if UNITY_EDITOR
if (!Application.isPlaying)
{
RenderTexture.active = Resources.FindObjectsOfTypeAll<RenderTexture>().FirstOrDefault(x=>x.name == "GameView RT");
s_renderedResult.ReadPixels(new Rect(0, 0, s_renderedResult.width, s_renderedResult.height), 0, 0);
s_renderedResult.Apply(false, false);
RenderTexture.active = null;
}
s_CommandBuffer.Blit(Resources.FindObjectsOfTypeAll<RenderTexture>().FirstOrDefault(x => x.name == "GameView RT"), s_CopyId);
#else
s_CommandBuffer.Blit(BuiltinRenderTextureType.BindableTexture, s_CopyId);
#endif
_buffer.Blit(new RenderTargetIdentifier(s_renderedResult), s_CopyId);
}
else
// Set properties for effect.
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(toneLevel, 0));
s_CommandBuffer.SetGlobalVector(s_ColorFactorId, new Vector4(effectColor.r, effectColor.g, effectColor.b, effectColor.a));
// [2] Apply base effect with reduction buffer (copied screen -> effect1).
GetDesamplingSize (m_ReductionRate, out w, out h);
s_CommandBuffer.GetTemporaryRT (s_EffectId1, w, h, 0, m_FilterMode);
s_CommandBuffer.Blit(s_CopyId, s_EffectId1, mat, 0);
s_CommandBuffer.ReleaseTemporaryRT(s_CopyId);
// Iterate blurring operation.
if (m_BlurMode != BlurMode.None)
{
_buffer.Blit(BuiltinRenderTextureType.CurrentActive, s_CopyId);
}
// Set properties.
_buffer.SetGlobalVector(s_EffectFactorId, new Vector4(toneLevel, 0));
_buffer.SetGlobalVector(s_ColorFactorId, new Vector4(effectColor.r, effectColor.g, effectColor.b, effectColor.a));
// Blit without effect.
if (!mat)
{
_buffer.Blit(s_CopyId, rtId);
_buffer.ReleaseTemporaryRT(s_CopyId);
}
// Blit with effect.
else
{
GetDesamplingSize(m_ReductionRate, out w, out h);
_buffer.GetTemporaryRT(s_EffectId1, w, h, 0, m_FilterMode);
// Apply base effect (copied screen -> effect1).
_buffer.Blit(s_CopyId, s_EffectId1, mat, 0);
_buffer.ReleaseTemporaryRT(s_CopyId);
// Iterate the operation.
if (m_BlurMode != BlurMode.None)
s_CommandBuffer.GetTemporaryRT(s_EffectId2, w, h, 0, m_FilterMode);
for (int i = 0; i < m_BlurIterations; i++)
{
_buffer.GetTemporaryRT(s_EffectId2, w, h, 0, m_FilterMode);
for (int i = 0; i < m_BlurIterations; i++)
{
// Apply effect (effect1 -> effect2, or effect2 -> effect1).
_buffer.SetGlobalVector(s_EffectFactorId, new Vector4(blur, 0));
_buffer.Blit(s_EffectId1, s_EffectId2, mat, 1);
_buffer.SetGlobalVector(s_EffectFactorId, new Vector4(0, blur));
_buffer.Blit(s_EffectId2, s_EffectId1, mat, 1);
}
_buffer.ReleaseTemporaryRT(s_EffectId2);
// [3] Apply blurring with reduction buffer (effect1 -> effect2, or effect2 -> effect1).
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(blur, 0));
s_CommandBuffer.Blit(s_EffectId1, s_EffectId2, mat, 1);
s_CommandBuffer.SetGlobalVector(s_EffectFactorId, new Vector4(0, blur));
s_CommandBuffer.Blit(s_EffectId2, s_EffectId1, mat, 1);
}
_buffer.Blit(s_EffectId1, rtId);
_buffer.ReleaseTemporaryRT(s_EffectId1);
s_CommandBuffer.ReleaseTemporaryRT(s_EffectId2);
}
// [4] Copy to result RT.
s_CommandBuffer.Blit(s_EffectId1, new RenderTargetIdentifier (capturedTexture));
s_CommandBuffer.ReleaseTemporaryRT(s_EffectId1);
#if UNITY_EDITOR
// Start rendering for editor mode.
if (!Application.isPlaying)
if(!Application.isPlaying)
{
_cameraEvent = CameraEvent.AfterEverything;
_camera.AddCommandBuffer(_cameraEvent, _buffer);
texture = null;
_SetDirty();
_SetDirty ();
Graphics.ExecuteCommandBuffer (s_CommandBuffer);
UnityEditor.EditorApplication.delayCall += () =>
{
_Release(false);
texture = capturedTexture;
_SetDirty();
};
_Release(false);
texture = capturedTexture;
_SetDirty ();
return;
}
#endif
// Start rendering coroutine by CanvasScaler.
var scaler = canvas.rootCanvas.GetComponent<CanvasScaler>();
scaler.StartCoroutine(
isOverlay
? _CoUpdateTextureOnNextFrameOverlay()
: _CoUpdateTextureOnNextFrame()
);
// Execute command buffer.
canvas.rootCanvas.GetComponent<CanvasScaler> ().StartCoroutine(_CoUpdateTextureOnNextFrame ());
}
/// <summary>
@@ -457,18 +416,14 @@ namespace Coffee.UIExtensions
//################################
// Private Members.
//################################
CameraEvent _cameraEvent = CameraEvent.AfterEverything;
Camera _camera;
RenderTexture _rt;
RenderTexture _rtToRelease;
CommandBuffer _buffer;
public Texture2D s_renderedResult;
static int s_CopyId;
static int s_EffectId1;
static int s_EffectId2;
static int s_EffectFactorId;
static int s_ColorFactorId;
static CommandBuffer s_CommandBuffer;
/// <summary>
/// Release genarated objects.
@@ -482,22 +437,23 @@ namespace Coffee.UIExtensions
_Release(ref _rt);
}
if (_buffer != null)
if (s_CommandBuffer != null)
{
if (_camera != null)
_camera.RemoveCommandBuffer(_cameraEvent, _buffer);
_buffer.Release();
_buffer = null;
}
s_CommandBuffer.Clear();
_Release(ref _rtToRelease);
if(releaseRT)
{
s_CommandBuffer.Release ();
s_CommandBuffer = null;
}
}
}
[System.Diagnostics.Conditional("UNITY_EDITOR")]
void _SetDirty()
{
#if UNITY_EDITOR
if(Application.isPlaying)
if(!Application.isPlaying)
{
UnityEditor.EditorUtility.SetDirty(this);
}
@@ -522,33 +478,16 @@ namespace Coffee.UIExtensions
/// <summary>
/// Set texture on next frame.
/// </summary>
IEnumerator _CoUpdateTextureOnNextFrame()
IEnumerator _CoUpdateTextureOnNextFrame ()
{
// Add command buffer to camera.
_cameraEvent = CameraEvent.AfterEverything;
_camera.AddCommandBuffer(_cameraEvent, _buffer);
yield return new WaitForEndOfFrame();
yield return new WaitForEndOfFrame ();
_Release(false);
texture = m_TargetTexture ? m_TargetTexture : _rt;
// Execute command buffer.
Graphics.ExecuteCommandBuffer (s_CommandBuffer);
_Release (false);
texture = capturedTexture;
}
/// <summary>
/// Set texture on next frame (for overlay).
/// </summary>
IEnumerator _CoUpdateTextureOnNextFrameOverlay()
{
// Add command buffer to camera.
yield return new WaitForEndOfFrame();
s_renderedResult.ReadPixels(new Rect(0, 0, s_renderedResult.width, s_renderedResult.height), 0, 0);
s_renderedResult.Apply(false, false);
_cameraEvent = CameraEvent.BeforeForwardOpaque;
_camera.AddCommandBuffer(_cameraEvent, _buffer);
texture = m_TargetTexture ? m_TargetTexture : _rt;
yield return new WaitForEndOfFrame();
_Release(false);
}
}
}
@@ -46,7 +46,6 @@ Shader "UI/Hidden/UI-EffectCapture"
fixed4 frag(v2f_img IN) : SV_Target
{
half effectFactor = _EffectFactor.x;
half blurFactor = _EffectFactor.z;
fixed4 colorFactor = _ColorFactor;
#if PIXEL
+11
View File
@@ -1,5 +1,16 @@
# Changelog
## [v2.8.2](https://github.com/mob-sakai/UIEffect/tree/v2.8.2) (2018-09-26)
[Full Changelog](https://github.com/mob-sakai/UIEffect/compare/v2.8.1...v2.8.2)
**Fixed bugs:**
- UICapturedEffectImage does not work with 'ScreenSpace - Overlay' in edit mode [\#128](https://github.com/mob-sakai/UIEffect/issues/128)
- The UIEffectCapturedImage is upside down with 'ScreenSpace - Overlay' mode [\#127](https://github.com/mob-sakai/UIEffect/issues/127)
- When "UI-Effect.mat" is created automatically, Unity hangs up. [\#126](https://github.com/mob-sakai/UIEffect/issues/126)
- UICapturedEffectImage does not work with Lightweight Render Pipeline LWRP [\#125](https://github.com/mob-sakai/UIEffect/issues/125)
## [v2.8.1](https://github.com/mob-sakai/UIEffect/tree/v2.8.1) (2018-08-17)
[Full Changelog](https://github.com/mob-sakai/UIEffect/compare/v2.8.0...v2.8.1)
+1 -1
View File
@@ -1 +1 @@
m_EditorVersion: 5.5.0p4
m_EditorVersion: 5.5.4p5
+1 -1
View File
@@ -5,7 +5,7 @@ UIEffect contains visual effect components for uGUI element in Unity.
[![](https://img.shields.io/github/release/mob-sakai/UIEffect.svg?label=latest%20version)](https://github.com/mob-sakai/UIEffect/releases)
[![](https://img.shields.io/github/release-date/mob-sakai/UIEffect.svg)](https://github.com/mob-sakai/UIEffect/releases)
![](https://img.shields.io/badge/unity-5.5%2B%2C+2017.1%2B%2C+2018.1%2B-green.svg)
![](https://img.shields.io/badge/unity-5.5%2B-green.svg)
[![](https://img.shields.io/github/license/mob-sakai/UIEffect.svg)](https://github.com/mob-sakai/UIEffect/blob/master/LICENSE.txt)
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "UIEffect",
"version": "2.8.1",
"version": "2.8.2",
"repository": {
"type": "git",
"url": "git+https://github.com/mob-sakai/UIEffect.git"