14 [AddComponentMenu(
"")]
19 int index = (int)mode;
21 if (m_BlitMaterials[index] != null)
22 return m_BlitMaterials[index];
25 m_BlitMaterials[0] =
new Material (
26 "Shader \"BlitCopy\" {\n" +
27 " SubShader { Pass {\n" +
28 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
29 " SetTexture [__RenderTex] { combine texture}" +
34 m_BlitMaterials[1] =
new Material (
35 "Shader \"BlitMultiply\" {\n" +
36 " SubShader { Pass {\n" +
37 " Blend DstColor Zero\n" +
38 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
39 " SetTexture [__RenderTex] { combine texture }" +
44 m_BlitMaterials[2] =
new Material (
45 "Shader \"BlitMultiplyDouble\" {\n" +
46 " SubShader { Pass {\n" +
47 " Blend DstColor SrcColor\n" +
48 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
49 " SetTexture [__RenderTex] { combine texture }" +
54 m_BlitMaterials[3] =
new Material (
55 "Shader \"BlitAdd\" {\n" +
56 " SubShader { Pass {\n" +
58 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
59 " SetTexture [__RenderTex] { combine texture }" +
64 m_BlitMaterials[4] =
new Material (
65 "Shader \"BlitAddSmooth\" {\n" +
66 " SubShader { Pass {\n" +
67 " Blend OneMinusDstColor One\n" +
68 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
69 " SetTexture [__RenderTex] { combine texture }" +
74 m_BlitMaterials[5] =
new Material (
75 "Shader \"BlitBlend\" {\n" +
76 " SubShader { Pass {\n" +
77 " Blend SrcAlpha OneMinusSrcAlpha\n" +
78 " ZTest Always Cull Off ZWrite Off Fog { Mode Off }\n" +
79 " SetTexture [__RenderTex] { combine texture }" +
83 for(
int i = 0; i < m_BlitMaterials.Length; ++i ) {
84 m_BlitMaterials[i].hideFlags = HideFlags.HideAndDontSave;
85 m_BlitMaterials[i].shader.hideFlags = HideFlags.HideAndDontSave;
87 return m_BlitMaterials[index];
97 public static void Blit (RenderTexture source, RenderTexture dest,
BlendMode blendMode) {
98 Blit (source,
new Rect (0,0,1,1), dest,
new Rect (0,0,1,1), blendMode);
100 public static void Blit (RenderTexture source, RenderTexture dest) {
105 public static void Blit (RenderTexture source, Rect sourceRect, RenderTexture dest, Rect destRect,
BlendMode blendMode) {
107 RenderTexture.active = dest;
109 source.SetGlobalShaderProperty (
"__RenderTex");
110 bool invertY = source.texelSize.y < 0.0f;
115 for (
int i = 0; i < blitMaterial.passCount; i++) {
116 blitMaterial.SetPass (i);
122 public static void BlitWithMaterial (Material material, RenderTexture source, RenderTexture destination)
124 Graphics.Blit (source, destination, material);
128 public static void RenderDistortion (Material material, RenderTexture source, RenderTexture destination,
float angle, Vector2 center, Vector2 radius)
130 bool invertY = source.texelSize.y < 0.0f;
132 center.y = 1.0f-center.y;
136 Matrix4x4 rotationMatrix = Matrix4x4.TRS(Vector3.zero, Quaternion.Euler(0, 0, angle), Vector3.one);
138 material.SetMatrix(
"_RotationMatrix", rotationMatrix);
139 material.SetVector(
"_CenterRadius",
new Vector4(center.x,center.y,radius.x,radius.y) );
140 material.SetFloat(
"_Angle", angle * Mathf.Deg2Rad);
142 Graphics.Blit (source, destination, material);
151 y1 = 1.0f; y2 = 0.0f;
153 y1 = 0.0f; y2 = 1.0f;
155 GL.TexCoord2( 0.0f, y1 ); GL.Vertex3( 0.0f, 0.0f, 0.1f );
156 GL.TexCoord2( 1.0f, y1 ); GL.Vertex3( 1.0f, 0.0f, 0.1f );
157 GL.TexCoord2( 1.0f, y2 ); GL.Vertex3( 1.0f, 1.0f, 0.1f );
158 GL.TexCoord2( 0.0f, y2 ); GL.Vertex3( 0.0f, 1.0f, 0.1f );
166 float xDelta = 1.0F / xSize;
167 float yDelta = 1.0F / ySize;
169 for (
int y=0;y<xSize;y++)
171 for (
int x=0;x<ySize;x++)
173 GL.TexCoord2 ((x+0) * xDelta, (y+0) * yDelta); GL.Vertex3 ((x+0) * xDelta, (y+0) * yDelta, 0.1f);
174 GL.TexCoord2 ((x+1) * xDelta, (y+0) * yDelta); GL.Vertex3 ((x+1) * xDelta, (y+0) * yDelta, 0.1f);
175 GL.TexCoord2 ((x+1) * xDelta, (y+1) * yDelta); GL.Vertex3 ((x+1) * xDelta, (y+1) * yDelta, 0.1f);
176 GL.TexCoord2 ((x+0) * xDelta, (y+1) * yDelta); GL.Vertex3 ((x+0) * xDelta, (y+1) * yDelta, 0.1f);
static void DrawGrid(int xSize, int ySize)
static void RenderDistortion(Material material, RenderTexture source, RenderTexture destination, float angle, Vector2 center, Vector2 radius)
static void DrawQuad(bool invertY)
static Material[] m_BlitMaterials
BlendMode
Blending modes use by the ImageEffects2.Blit functions.
static void BlitWithMaterial(Material material, RenderTexture source, RenderTexture destination)
static Material GetBlitMaterial(BlendMode mode)
A Utility class for performing various image based rendering tasks.
static void Blit(RenderTexture source, Rect sourceRect, RenderTexture dest, Rect destRect, BlendMode blendMode)
Copies one render texture onto another.
static void Blit(RenderTexture source, RenderTexture dest, BlendMode blendMode)
Copies one render texture onto another.
static void Blit(RenderTexture source, RenderTexture dest)