File tree 2 files changed +83
-0
lines changed
2 files changed +83
-0
lines changed Original file line number Diff line number Diff line change
1
+ using UnityEngine ;
2
+
3
+ public class mrt : MonoBehaviour
4
+ {
5
+ public RenderTexture [ ] RenderTextures ;
6
+ public Material material ;
7
+
8
+ void MRT ( RenderTexture [ ] rt , Material mat , int pass = 0 )
9
+ {
10
+ RenderBuffer [ ] rb = new RenderBuffer [ rt . Length ] ;
11
+ for ( int i = 0 ; i < rt . Length ; i ++ ) rb [ i ] = rt [ i ] . colorBuffer ;
12
+ Graphics . SetRenderTarget ( rb , rt [ 0 ] . depthBuffer ) ;
13
+ GL . Clear ( true , true , Color . clear ) ;
14
+ GL . PushMatrix ( ) ;
15
+ GL . LoadOrtho ( ) ;
16
+ mat . SetPass ( pass ) ;
17
+ GL . Begin ( GL . QUADS ) ;
18
+ GL . Vertex3 ( 0.0f , 0.0f , 0.1f ) ;
19
+ GL . TexCoord2 ( 0.0f , 0.0f ) ;
20
+ GL . Vertex3 ( 1.0f , 0.0f , 0.1f ) ;
21
+ GL . TexCoord2 ( 1.0f , 0.0f ) ;
22
+ GL . Vertex3 ( 1.0f , 1.0f , 0.1f ) ;
23
+ GL . TexCoord2 ( 1.0f , 1.0f ) ;
24
+ GL . Vertex3 ( 0.0f , 1.0f , 0.1f ) ;
25
+ GL . TexCoord2 ( 0.0f , 1.0f ) ;
26
+ GL . End ( ) ;
27
+ GL . PopMatrix ( ) ;
28
+ }
29
+
30
+ void Update ( )
31
+ {
32
+ MRT ( RenderTextures , material , 0 ) ;
33
+ }
34
+ }
Original file line number Diff line number Diff line change
1
+ Shader "MRT"
2
+ {
3
+ SubShader
4
+ {
5
+ Pass
6
+ {
7
+ ZTest Always Cull Off ZWrite Off
8
+ CGPROGRAM
9
+ #pragma vertex vertex_shader
10
+ #pragma fragment pixel_shader
11
+ #pragma exclude_renderers nomrt
12
+ #pragma target 3.0
13
+
14
+ struct structureVS
15
+ {
16
+ float4 vertex : SV_POSITION ;
17
+ float2 uv : TEXCOORD0 ;
18
+ };
19
+
20
+ struct structurePS
21
+ {
22
+ float4 target00 : SV_Target0 ;
23
+ float4 target01 : SV_Target1 ;
24
+ float4 target02 : SV_Target2 ;
25
+ float4 target03 : SV_Target3 ;
26
+ };
27
+
28
+ structureVS vertex_shader (float4 vertex:POSITION , float2 uv:TEXCOORD0 )
29
+ {
30
+ structureVS vs;
31
+ vs.vertex = UnityObjectToClipPos ( vertex );
32
+ vs.uv = uv;
33
+ return vs;
34
+ }
35
+
36
+ structurePS pixel_shader (structureVS vs)
37
+ {
38
+ structurePS ps;
39
+ ps.target00 = float4 (1 ,0 ,0 ,1 );
40
+ ps.target01 = float4 (0 ,1 ,0 ,1 );
41
+ ps.target02 = float4 (0 ,0 ,1 ,1 );
42
+ ps.target03 = float4 (1 ,1 ,1 ,1 );
43
+ return ps;
44
+ }
45
+ ENDCG
46
+ }
47
+ }
48
+ FallBack "Diffuse"
49
+ }
You can’t perform that action at this time.
0 commit comments