Here are the examples of the csharp api UnityEngine.Graphics.DrawTexture(UnityEngine.Rect, UnityEngine.Texture) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
10 Examples
19
View Source File : AddNewLife.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
private void RunAddnewLife()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, renderTexture.width, renderTexture.height, 0);
RenderTexture.active = renderTexture;
int positionx, positiony;
positionx = Random.Range(0, renderTexture.width + newLife.width + newLife.width) - newLife.width;
positiony = Random.Range(0, renderTexture.height + newLife.height + newLife.height) - newLife.height;
Graphics.DrawTexture(new Rect(positionx, positiony, newLife.width, newLife.height), newLife);
RenderTexture.active = null;
GL.PopMatrix();
}
19
View Source File : PaintEditor.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
void BrushPaint()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, renderTexture.width, renderTexture.height, 0);
RenderTexture.active = renderTexture;
int positionx = x - ((int)slider.value);
int positiony = y - ((int)slider.value);
Graphics.DrawTexture(new Rect(positionx, positiony, (int)slider.value * 2, (int)slider.value * 2), Brush);
RenderTexture.active = null;
GL.PopMatrix();
}
19
View Source File : PaintEditor.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
void ClearPaint()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, renderTexture.width, renderTexture.height, 0);
RenderTexture.active = renderTexture;
int positionx = x - ((int)slider.value);
int positiony = y - ((int)slider.value);
Graphics.DrawTexture(new Rect(positionx, positiony, (int)slider.value * 2, (int)slider.value * 2), Clear);
RenderTexture.active = null;
GL.PopMatrix();
}
19
View Source File : PaintEditor.cs
License : MIT License
Project Creator : BelkinAndrey
License : MIT License
Project Creator : BelkinAndrey
void PencilPaint()
{
GL.PushMatrix();
GL.LoadPixelMatrix(0, renderTexture.width, renderTexture.height, 0);
RenderTexture.active = renderTexture;
Texture2D tex = new Texture2D(1, 1);
tex.ReadPixels(new Rect(x, y, 1, 1), 0, 0);
tex.Apply();
float r = tex.GetPixel(0, 0).r;
r += 1 / sliderMax.value;
tex.SetPixel(0, 0, new Color(r, 1, 1, 1));
tex.Apply();
Graphics.DrawTexture(new Rect(x, y, 1, 1), tex);
RenderTexture.active = null;
GL.PopMatrix();
}
19
View Source File : TextureScaler.cs
License : GNU General Public License v3.0
Project Creator : Cytoid
License : GNU General Public License v3.0
Project Creator : Cytoid
static void _gpu_scale(Texture2D src, int width, int height, FilterMode fmode)
{
//We need the source texture in VRAM because we render with it
src.filterMode = fmode;
src.Apply(true);
//Using RTT for best quality and performance. Thanks, Unity 5
RenderTexture rtt = new RenderTexture(width, height, 32);
//Set the RTT in order to render to it
Graphics.SetRenderTarget(rtt);
//Setup 2D matrix in range 0..1, so nobody needs to care about sized
GL.LoadPixelMatrix(0, 1, 1, 0);
//Then clear & draw the texture to fill the entire RTT.
GL.Clear(true, true, new Color(0, 0, 0, 0));
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
}
19
View Source File : HistogramMonitor.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public override void OnMonitorGUI(Rect r)
{
if (Event.current.type == EventType.Repaint)
{
// If m_MonitorAreaRect isn't set the preview was just opened so refresh the render to get the histogram data
if (Mathf.Approximately(m_MonitorAreaRect.width, 0) && Mathf.Approximately(m_MonitorAreaRect.height, 0))
InternalEditorUtility.RepaintAllViews();
// Sizing
float width = m_HistogramTexture != null
? Mathf.Min(m_HistogramTexture.width, r.width - 65f)
: r.width;
float height = m_HistogramTexture != null
? Mathf.Min(m_HistogramTexture.height, r.height - 45f)
: r.height;
m_MonitorAreaRect = new Rect(
Mathf.Floor(r.x + r.width / 2f - width / 2f),
Mathf.Floor(r.y + r.height / 2f - height / 2f - 5f),
width, height
);
if (m_HistogramTexture != null)
{
Graphics.DrawTexture(m_MonitorAreaRect, m_HistogramTexture);
var color = Color.white;
const float kTickSize = 5f;
// Rect, lines & ticks points
if (m_MonitorSettings.histogramMode == HistogramMode.RGBSplit)
{
// A B C D E
// N F
// M G
// L K J I H
var A = new Vector3(m_MonitorAreaRect.x - 1f, m_MonitorAreaRect.y - 1f);
var E = new Vector3(A.x + m_MonitorAreaRect.width + 2f, m_MonitorAreaRect.y - 1f);
var H = new Vector3(E.x, E.y + m_MonitorAreaRect.height + 2f);
var L = new Vector3(A.x, H.y);
var N = new Vector3(A.x, A.y + (L.y - A.y) / 3f);
var M = new Vector3(A.x, A.y + (L.y - A.y) * 2f / 3f);
var F = new Vector3(E.x, E.y + (H.y - E.y) / 3f);
var G = new Vector3(E.x, E.y + (H.y - E.y) * 2f / 3f);
var C = new Vector3(A.x + (E.x - A.x) / 2f, A.y);
var J = new Vector3(L.x + (H.x - L.x) / 2f, L.y);
var B = new Vector3(A.x + (C.x - A.x) / 2f, A.y);
var D = new Vector3(C.x + (E.x - C.x) / 2f, C.y);
var I = new Vector3(J.x + (H.x - J.x) / 2f, J.y);
var K = new Vector3(L.x + (J.x - L.x) / 2f, L.y);
// Borders
Handles.color = color;
Handles.DrawLine(A, E);
Handles.DrawLine(E, H);
Handles.DrawLine(H, L);
Handles.DrawLine(L, new Vector3(A.x, A.y - 1f));
// Vertical ticks
Handles.DrawLine(A, new Vector3(A.x - kTickSize, A.y));
Handles.DrawLine(N, new Vector3(N.x - kTickSize, N.y));
Handles.DrawLine(M, new Vector3(M.x - kTickSize, M.y));
Handles.DrawLine(L, new Vector3(L.x - kTickSize, L.y));
Handles.DrawLine(E, new Vector3(E.x + kTickSize, E.y));
Handles.DrawLine(F, new Vector3(F.x + kTickSize, F.y));
Handles.DrawLine(G, new Vector3(G.x + kTickSize, G.y));
Handles.DrawLine(H, new Vector3(H.x + kTickSize, H.y));
// Horizontal ticks
Handles.DrawLine(A, new Vector3(A.x, A.y - kTickSize));
Handles.DrawLine(B, new Vector3(B.x, B.y - kTickSize));
Handles.DrawLine(C, new Vector3(C.x, C.y - kTickSize));
Handles.DrawLine(D, new Vector3(D.x, D.y - kTickSize));
Handles.DrawLine(E, new Vector3(E.x, E.y - kTickSize));
Handles.DrawLine(L, new Vector3(L.x, L.y + kTickSize));
Handles.DrawLine(K, new Vector3(K.x, K.y + kTickSize));
Handles.DrawLine(J, new Vector3(J.x, J.y + kTickSize));
Handles.DrawLine(I, new Vector3(I.x, I.y + kTickSize));
Handles.DrawLine(H, new Vector3(H.x, H.y + kTickSize));
// Separators
Handles.DrawLine(N, F);
Handles.DrawLine(M, G);
// Labels
GUI.color = color;
GUI.Label(new Rect(L.x - 15f, L.y + kTickSize - 4f, 30f, 30f), "0.0", FxStyles.tickStyleCenter);
GUI.Label(new Rect(J.x - 15f, J.y + kTickSize - 4f, 30f, 30f), "0.5", FxStyles.tickStyleCenter);
GUI.Label(new Rect(H.x - 15f, H.y + kTickSize - 4f, 30f, 30f), "1.0", FxStyles.tickStyleCenter);
}
else
{
// A B C D E
// P F
// O G
// N H
// M L K J I
var A = new Vector3(m_MonitorAreaRect.x, m_MonitorAreaRect.y);
var E = new Vector3(A.x + m_MonitorAreaRect.width + 1f, m_MonitorAreaRect.y);
var I = new Vector3(E.x, E.y + m_MonitorAreaRect.height + 1f);
var M = new Vector3(A.x, I.y);
var C = new Vector3(A.x + (E.x - A.x) / 2f, A.y);
var G = new Vector3(E.x, E.y + (I.y - E.y) / 2f);
var K = new Vector3(M.x + (I.x - M.x) / 2f, M.y);
var O = new Vector3(A.x, A.y + (M.y - A.y) / 2f);
var P = new Vector3(A.x, A.y + (O.y - A.y) / 2f);
var F = new Vector3(E.x, E.y + (G.y - E.y) / 2f);
var N = new Vector3(A.x, O.y + (M.y - O.y) / 2f);
var H = new Vector3(E.x, G.y + (I.y - G.y) / 2f);
var B = new Vector3(A.x + (C.x - A.x) / 2f, A.y);
var L = new Vector3(M.x + (K.x - M.x) / 2f, M.y);
var D = new Vector3(C.x + (E.x - C.x) / 2f, A.y);
var J = new Vector3(K.x + (I.x - K.x) / 2f, M.y);
// Borders
Handles.color = color;
Handles.DrawLine(A, E);
Handles.DrawLine(E, I);
Handles.DrawLine(I, M);
Handles.DrawLine(M, new Vector3(A.x, A.y - 1f));
// Vertical ticks
Handles.DrawLine(A, new Vector3(A.x - kTickSize, A.y));
Handles.DrawLine(P, new Vector3(P.x - kTickSize, P.y));
Handles.DrawLine(O, new Vector3(O.x - kTickSize, O.y));
Handles.DrawLine(N, new Vector3(N.x - kTickSize, N.y));
Handles.DrawLine(M, new Vector3(M.x - kTickSize, M.y));
Handles.DrawLine(E, new Vector3(E.x + kTickSize, E.y));
Handles.DrawLine(F, new Vector3(F.x + kTickSize, F.y));
Handles.DrawLine(G, new Vector3(G.x + kTickSize, G.y));
Handles.DrawLine(H, new Vector3(H.x + kTickSize, H.y));
Handles.DrawLine(I, new Vector3(I.x + kTickSize, I.y));
// Horizontal ticks
Handles.DrawLine(A, new Vector3(A.x, A.y - kTickSize));
Handles.DrawLine(B, new Vector3(B.x, B.y - kTickSize));
Handles.DrawLine(C, new Vector3(C.x, C.y - kTickSize));
Handles.DrawLine(D, new Vector3(D.x, D.y - kTickSize));
Handles.DrawLine(E, new Vector3(E.x, E.y - kTickSize));
Handles.DrawLine(M, new Vector3(M.x, M.y + kTickSize));
Handles.DrawLine(L, new Vector3(L.x, L.y + kTickSize));
Handles.DrawLine(K, new Vector3(K.x, K.y + kTickSize));
Handles.DrawLine(J, new Vector3(J.x, J.y + kTickSize));
Handles.DrawLine(I, new Vector3(I.x, I.y + kTickSize));
// Labels
GUI.color = color;
GUI.Label(new Rect(A.x - kTickSize - 34f, A.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(O.x - kTickSize - 34f, O.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleRight);
GUI.Label(new Rect(M.x - kTickSize - 34f, M.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(E.x + kTickSize + 4f, E.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleLeft);
GUI.Label(new Rect(G.x + kTickSize + 4f, G.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleLeft);
GUI.Label(new Rect(I.x + kTickSize + 4f, I.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleLeft);
GUI.Label(new Rect(M.x - 15f, M.y + kTickSize - 4f, 30f, 30f), "0.0", FxStyles.tickStyleCenter);
GUI.Label(new Rect(K.x - 15f, K.y + kTickSize - 4f, 30f, 30f), "0.5", FxStyles.tickStyleCenter);
GUI.Label(new Rect(I.x - 15f, I.y + kTickSize - 4f, 30f, 30f), "1.0", FxStyles.tickStyleCenter);
}
}
}
}
19
View Source File : ParadeMonitor.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public override void OnMonitorGUI(Rect r)
{
if (Event.current.type == EventType.Repaint)
{
// If m_MonitorAreaRect isn't set the preview was just opened so refresh the render to get the waveform data
if (Mathf.Approximately(m_MonitorAreaRect.width, 0) && Mathf.Approximately(m_MonitorAreaRect.height, 0))
InternalEditorUtility.RepaintAllViews();
// Sizing
float width = m_WaveformTexture != null
? Mathf.Min(m_WaveformTexture.width, r.width - 65f)
: r.width;
float height = m_WaveformTexture != null
? Mathf.Min(m_WaveformTexture.height, r.height - 45f)
: r.height;
m_MonitorAreaRect = new Rect(
Mathf.Floor(r.x + r.width / 2f - width / 2f),
Mathf.Floor(r.y + r.height / 2f - height / 2f - 5f),
width, height
);
if (m_WaveformTexture != null)
{
m_Material.SetFloat("_Exposure", m_MonitorSettings.paradeExposure);
var oldActive = RenderTexture.active;
Graphics.Blit(null, m_WaveformTexture, m_Material, 0);
RenderTexture.active = oldActive;
Graphics.DrawTexture(m_MonitorAreaRect, m_WaveformTexture);
var color = Color.white;
const float kTickSize = 5f;
// Rect, lines & ticks points
// A O B P C Q D
// N E
// M F
// L G
// K T J S I R H
var A = new Vector3(m_MonitorAreaRect.x, m_MonitorAreaRect.y);
var D = new Vector3(A.x + m_MonitorAreaRect.width + 1f, m_MonitorAreaRect.y);
var H = new Vector3(D.x, D.y + m_MonitorAreaRect.height + 1f);
var K = new Vector3(A.x, H.y);
var F = new Vector3(D.x, D.y + (H.y - D.y) / 2f);
var M = new Vector3(A.x, A.y + (K.y - A.y) / 2f);
var B = new Vector3(A.x + (D.x - A.x) / 3f, A.y);
var C = new Vector3(A.x + (D.x - A.x) * 2f / 3f, A.y);
var I = new Vector3(K.x + (H.x - K.x) * 2f / 3f, K.y);
var J = new Vector3(K.x + (H.x - K.x) / 3f, K.y);
var N = new Vector3(A.x, A.y + (M.y - A.y) / 2f);
var L = new Vector3(A.x, M.y + (K.y - M.y) / 2f);
var E = new Vector3(D.x, D.y + (F.y - D.y) / 2f);
var G = new Vector3(D.x, F.y + (H.y - F.y) / 2f);
var O = new Vector3(A.x + (B.x - A.x) / 2f, A.y);
var P = new Vector3(B.x + (C.x - B.x) / 2f, B.y);
var Q = new Vector3(C.x + (D.x - C.x) / 2f, C.y);
var R = new Vector3(I.x + (H.x - I.x) / 2f, I.y);
var S = new Vector3(J.x + (I.x - J.x) / 2f, J.y);
var T = new Vector3(K.x + (J.x - K.x) / 2f, K.y);
// Borders
Handles.color = color;
Handles.DrawLine(A, D);
Handles.DrawLine(D, H);
Handles.DrawLine(H, K);
Handles.DrawLine(K, new Vector3(A.x, A.y - 1f));
Handles.DrawLine(B, J);
Handles.DrawLine(C, I);
// Vertical ticks
Handles.DrawLine(A, new Vector3(A.x - kTickSize, A.y));
Handles.DrawLine(N, new Vector3(N.x - kTickSize, N.y));
Handles.DrawLine(M, new Vector3(M.x - kTickSize, M.y));
Handles.DrawLine(L, new Vector3(L.x - kTickSize, L.y));
Handles.DrawLine(K, new Vector3(K.x - kTickSize, K.y));
Handles.DrawLine(D, new Vector3(D.x + kTickSize, D.y));
Handles.DrawLine(E, new Vector3(E.x + kTickSize, E.y));
Handles.DrawLine(F, new Vector3(F.x + kTickSize, F.y));
Handles.DrawLine(G, new Vector3(G.x + kTickSize, G.y));
Handles.DrawLine(H, new Vector3(H.x + kTickSize, H.y));
// Horizontal ticks
Handles.DrawLine(A, new Vector3(A.x, A.y - kTickSize));
Handles.DrawLine(B, new Vector3(B.x, B.y - kTickSize));
Handles.DrawLine(C, new Vector3(C.x, C.y - kTickSize));
Handles.DrawLine(D, new Vector3(D.x, D.y - kTickSize));
Handles.DrawLine(O, new Vector3(O.x, O.y - kTickSize));
Handles.DrawLine(P, new Vector3(P.x, P.y - kTickSize));
Handles.DrawLine(Q, new Vector3(Q.x, Q.y - kTickSize));
Handles.DrawLine(H, new Vector3(H.x, H.y + kTickSize));
Handles.DrawLine(I, new Vector3(I.x, I.y + kTickSize));
Handles.DrawLine(J, new Vector3(J.x, J.y + kTickSize));
Handles.DrawLine(K, new Vector3(K.x, K.y + kTickSize));
Handles.DrawLine(R, new Vector3(R.x, R.y + kTickSize));
Handles.DrawLine(S, new Vector3(S.x, S.y + kTickSize));
Handles.DrawLine(T, new Vector3(T.x, T.y + kTickSize));
// Labels
GUI.color = color;
GUI.Label(new Rect(A.x - kTickSize - 34f, A.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(M.x - kTickSize - 34f, M.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleRight);
GUI.Label(new Rect(K.x - kTickSize - 34f, K.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(D.x + kTickSize + 4f, D.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleLeft);
GUI.Label(new Rect(F.x + kTickSize + 4f, F.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleLeft);
GUI.Label(new Rect(H.x + kTickSize + 4f, H.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleLeft);
}
}
}
19
View Source File : VectorscopeMonitor.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public override void OnMonitorGUI(Rect r)
{
if (Event.current.type == EventType.Repaint)
{
// If m_MonitorAreaRect isn't set the preview was just opened so refresh the render to get the vectoscope data
if (Mathf.Approximately(m_MonitorAreaRect.width, 0) && Mathf.Approximately(m_MonitorAreaRect.height, 0))
InternalEditorUtility.RepaintAllViews();
// Sizing
float size = 0f;
if (r.width < r.height)
{
size = m_VectorscopeTexture != null
? Mathf.Min(m_VectorscopeTexture.width, r.width - 35f)
: r.width;
}
else
{
size = m_VectorscopeTexture != null
? Mathf.Min(m_VectorscopeTexture.height, r.height - 25f)
: r.height;
}
m_MonitorAreaRect = new Rect(
Mathf.Floor(r.x + r.width / 2f - size / 2f),
Mathf.Floor(r.y + r.height / 2f - size / 2f - 5f),
size, size
);
if (m_VectorscopeTexture != null)
{
m_Material.SetFloat("_Exposure", m_MonitorSettings.vectorscopeExposure);
var oldActive = RenderTexture.active;
Graphics.Blit(null, m_VectorscopeTexture, m_Material, m_MonitorSettings.vectorscopeShowBackground ? 0 : 1);
RenderTexture.active = oldActive;
Graphics.DrawTexture(m_MonitorAreaRect, m_VectorscopeTexture);
var color = Color.white;
const float kTickSize = 10f;
const int kTickCount = 24;
float radius = m_MonitorAreaRect.width / 2f;
float midX = m_MonitorAreaRect.x + radius;
float midY = m_MonitorAreaRect.y + radius;
var center = new Vector2(midX, midY);
// Cross
color.a *= 0.5f;
Handles.color = color;
Handles.DrawLine(new Vector2(midX, m_MonitorAreaRect.y), new Vector2(midX, m_MonitorAreaRect.y + m_MonitorAreaRect.height));
Handles.DrawLine(new Vector2(m_MonitorAreaRect.x, midY), new Vector2(m_MonitorAreaRect.x + m_MonitorAreaRect.width, midY));
if (m_MonitorAreaRect.width > 100f)
{
color.a = 1f;
// Ticks
Handles.color = color;
for (int i = 0; i < kTickCount; i++)
{
float a = (float)i / (float)kTickCount;
float theta = a * (Mathf.PI * 2f);
float tx = Mathf.Cos(theta + (Mathf.PI / 2f));
float ty = Mathf.Sin(theta - (Mathf.PI / 2f));
var innerVec = center + new Vector2(tx, ty) * (radius - kTickSize);
var outerVec = center + new Vector2(tx, ty) * radius;
Handles.DrawAAPolyLine(3f, innerVec, outerVec);
}
// Labels (where saturation reaches 75%)
color.a = 1f;
var oldColor = GUI.color;
GUI.color = color * 2f;
var point = new Vector2(-0.254f, -0.750f) * radius + center;
var rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[R]", FxStyles.tickStyleCenter);
point = new Vector2(-0.497f, 0.629f) * radius + center;
rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[G]", FxStyles.tickStyleCenter);
point = new Vector2(0.750f, 0.122f) * radius + center;
rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[B]", FxStyles.tickStyleCenter);
point = new Vector2(-0.750f, -0.122f) * radius + center;
rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[Y]", FxStyles.tickStyleCenter);
point = new Vector2(0.254f, 0.750f) * radius + center;
rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[C]", FxStyles.tickStyleCenter);
point = new Vector2(0.497f, -0.629f) * radius + center;
rect = new Rect(point.x - 10f, point.y - 10f, 20f, 20f);
GUI.Label(rect, "[M]", FxStyles.tickStyleCenter);
GUI.color = oldColor;
}
}
}
}
19
View Source File : WaveformMonitor.cs
License : MIT License
Project Creator : liangxiegame
License : MIT License
Project Creator : liangxiegame
public override void OnMonitorGUI(Rect r)
{
if (Event.current.type == EventType.Repaint)
{
// If m_MonitorAreaRect isn't set the preview was just opened so refresh the render to get the waveform data
if (Mathf.Approximately(m_MonitorAreaRect.width, 0) && Mathf.Approximately(m_MonitorAreaRect.height, 0))
InternalEditorUtility.RepaintAllViews();
// Sizing
float width = m_WaveformTexture != null
? Mathf.Min(m_WaveformTexture.width, r.width - 65f)
: r.width;
float height = m_WaveformTexture != null
? Mathf.Min(m_WaveformTexture.height, r.height - 45f)
: r.height;
m_MonitorAreaRect = new Rect(
Mathf.Floor(r.x + r.width / 2f - width / 2f),
Mathf.Floor(r.y + r.height / 2f - height / 2f - 5f),
width, height
);
if (m_WaveformTexture != null)
{
m_Material.SetFloat("_Exposure", m_MonitorSettings.waveformExposure);
var oldActive = RenderTexture.active;
Graphics.Blit(null, m_WaveformTexture, m_Material, 0);
RenderTexture.active = oldActive;
Graphics.DrawTexture(m_MonitorAreaRect, m_WaveformTexture);
var color = Color.white;
const float kTickSize = 5f;
// Rect, lines & ticks points
// A B C D E
// P F
// O G
// N H
// M L K J I
var A = new Vector3(m_MonitorAreaRect.x, m_MonitorAreaRect.y);
var E = new Vector3(A.x + m_MonitorAreaRect.width + 1f, m_MonitorAreaRect.y);
var I = new Vector3(E.x, E.y + m_MonitorAreaRect.height + 1f);
var M = new Vector3(A.x, I.y);
var C = new Vector3(A.x + (E.x - A.x) / 2f, A.y);
var G = new Vector3(E.x, E.y + (I.y - E.y) / 2f);
var K = new Vector3(M.x + (I.x - M.x) / 2f, M.y);
var O = new Vector3(A.x, A.y + (M.y - A.y) / 2f);
var P = new Vector3(A.x, A.y + (O.y - A.y) / 2f);
var F = new Vector3(E.x, E.y + (G.y - E.y) / 2f);
var N = new Vector3(A.x, O.y + (M.y - O.y) / 2f);
var H = new Vector3(E.x, G.y + (I.y - G.y) / 2f);
var B = new Vector3(A.x + (C.x - A.x) / 2f, A.y);
var L = new Vector3(M.x + (K.x - M.x) / 2f, M.y);
var D = new Vector3(C.x + (E.x - C.x) / 2f, A.y);
var J = new Vector3(K.x + (I.x - K.x) / 2f, M.y);
// Borders
Handles.color = color;
Handles.DrawLine(A, E);
Handles.DrawLine(E, I);
Handles.DrawLine(I, M);
Handles.DrawLine(M, new Vector3(A.x, A.y - 1f));
// Vertical ticks
Handles.DrawLine(A, new Vector3(A.x - kTickSize, A.y));
Handles.DrawLine(P, new Vector3(P.x - kTickSize, P.y));
Handles.DrawLine(O, new Vector3(O.x - kTickSize, O.y));
Handles.DrawLine(N, new Vector3(N.x - kTickSize, N.y));
Handles.DrawLine(M, new Vector3(M.x - kTickSize, M.y));
Handles.DrawLine(E, new Vector3(E.x + kTickSize, E.y));
Handles.DrawLine(F, new Vector3(F.x + kTickSize, F.y));
Handles.DrawLine(G, new Vector3(G.x + kTickSize, G.y));
Handles.DrawLine(H, new Vector3(H.x + kTickSize, H.y));
Handles.DrawLine(I, new Vector3(I.x + kTickSize, I.y));
// Horizontal ticks
Handles.DrawLine(A, new Vector3(A.x, A.y - kTickSize));
Handles.DrawLine(B, new Vector3(B.x, B.y - kTickSize));
Handles.DrawLine(C, new Vector3(C.x, C.y - kTickSize));
Handles.DrawLine(D, new Vector3(D.x, D.y - kTickSize));
Handles.DrawLine(E, new Vector3(E.x, E.y - kTickSize));
Handles.DrawLine(M, new Vector3(M.x, M.y + kTickSize));
Handles.DrawLine(L, new Vector3(L.x, L.y + kTickSize));
Handles.DrawLine(K, new Vector3(K.x, K.y + kTickSize));
Handles.DrawLine(J, new Vector3(J.x, J.y + kTickSize));
Handles.DrawLine(I, new Vector3(I.x, I.y + kTickSize));
// Labels
GUI.color = color;
GUI.Label(new Rect(A.x - kTickSize - 34f, A.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(O.x - kTickSize - 34f, O.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleRight);
GUI.Label(new Rect(M.x - kTickSize - 34f, M.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleRight);
GUI.Label(new Rect(E.x + kTickSize + 4f, E.y - 15f, 30f, 30f), "1.0", FxStyles.tickStyleLeft);
GUI.Label(new Rect(G.x + kTickSize + 4f, G.y - 15f, 30f, 30f), "0.5", FxStyles.tickStyleLeft);
GUI.Label(new Rect(I.x + kTickSize + 4f, I.y - 15f, 30f, 30f), "0.0", FxStyles.tickStyleLeft);
GUI.Label(new Rect(M.x - 15f, M.y + kTickSize - 4f, 30f, 30f), "0.0", FxStyles.tickStyleCenter);
GUI.Label(new Rect(K.x - 15f, K.y + kTickSize - 4f, 30f, 30f), "0.5", FxStyles.tickStyleCenter);
GUI.Label(new Rect(I.x - 15f, I.y + kTickSize - 4f, 30f, 30f), "1.0", FxStyles.tickStyleCenter);
}
}
}
19
View Source File : TextureExtensions.cs
License : MIT License
Project Creator : peteschmitz
License : MIT License
Project Creator : peteschmitz
static void _gpu_scale(Texture2D src, Rect? srcRect, int width, int height, FilterMode fmode)
{
//We need the source texture in VRAM because we render with it
src.filterMode = fmode;
src.Apply(true);
//Using RTT for best quality and performance. Thanks, Unity 5
RenderTexture rtt = new RenderTexture(width, height, 32);
//Set the RTT in order to render to it
Graphics.SetRenderTarget(rtt);
//Setup 2D matrix in range 0..1, so nobody needs to care about sized
GL.LoadPixelMatrix(0, 1, 1, 0);
//Then clear & draw the texture to fill the entire RTT.
GL.Clear(true, true, new Color(0, 0, 0, 0));
if (srcRect.HasValue)
{
//srcRect.Value.AsNormalizedUv(src.width, src.height)
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src, srcRect.Value.AsNormalizedUv(src.width, src.height), 0, 0, 0, 0);
}
else
{
Graphics.DrawTexture(new Rect(0, 0, 1, 1), src);
}
}