├── .gitignore ├── Assets ├── MRT.meta └── MRT │ ├── Materials.meta │ ├── Materials │ ├── ParticleDisplay.mat │ ├── ParticleDisplay.mat.meta │ ├── ParticleUpdate.mat │ └── ParticleUpdate.mat.meta │ ├── Scenes.meta │ ├── Scenes │ ├── GPUParticle.unity │ ├── GPUParticle.unity.meta │ ├── Test.unity │ └── Test.unity.meta │ ├── Scripts.meta │ ├── Scripts │ ├── GPUParticle.meta │ ├── GPUParticle │ │ ├── GPUParticleSystem.cs │ │ └── GPUParticleSystem.cs.meta │ ├── MRT.cs │ ├── MRT.cs.meta │ ├── Test.meta │ └── Test │ │ ├── MRTTest.cs │ │ └── MRTTest.cs.meta │ ├── Shaders.meta │ └── Shaders │ ├── MRTTest.shader │ ├── MRTTest.shader.meta │ ├── ParticleDisplay.shader │ ├── ParticleDisplay.shader.meta │ ├── ParticleUpdate.shader │ ├── ParticleUpdate.shader.meta │ ├── Random.cginc │ └── Random.cginc.meta ├── Captures └── gpu-particle-example.png └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | [Ll]ibrary/ 2 | [Tt]emp/ 3 | [Oo]bj/ 4 | [Bb]uild/ 5 | [Pp]rojectSettings/ 6 | 7 | # Autogenerated VS/MD solution and project files 8 | *.csproj 9 | *.unityproj 10 | *.sln 11 | *.suo 12 | *.user 13 | *.userprefs 14 | *.pidb 15 | *.booproj 16 | 17 | # Unity3D Generated File On Crash Reports 18 | sysinfo.txt -------------------------------------------------------------------------------- /Assets/MRT.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 9ac263a383812c546855979a81b0a9a9 3 | folderAsset: yes 4 | timeCreated: 1444898531 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Materials.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a5401aeb146b5744595fa6f525666f0d 3 | folderAsset: yes 4 | timeCreated: 1444963225 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Materials/ParticleDisplay.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/unity-mrt-example/0a0b5d919b53df3b62e2f84fc82a2056deb35689/Assets/MRT/Materials/ParticleDisplay.mat -------------------------------------------------------------------------------- /Assets/MRT/Materials/ParticleDisplay.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: a785418957152de408a175e531ea29e8 3 | timeCreated: 1444963232 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MRT/Materials/ParticleUpdate.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/unity-mrt-example/0a0b5d919b53df3b62e2f84fc82a2056deb35689/Assets/MRT/Materials/ParticleUpdate.mat -------------------------------------------------------------------------------- /Assets/MRT/Materials/ParticleUpdate.mat.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: c6ced720ce8184f4fa132c8770cbb291 3 | timeCreated: 1444963399 4 | licenseType: Pro 5 | NativeFormatImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MRT/Scenes.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b0c6f249324a4be4ebdcad4823ba5c20 3 | folderAsset: yes 4 | timeCreated: 1444898802 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Scenes/GPUParticle.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/unity-mrt-example/0a0b5d919b53df3b62e2f84fc82a2056deb35689/Assets/MRT/Scenes/GPUParticle.unity -------------------------------------------------------------------------------- /Assets/MRT/Scenes/GPUParticle.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 931bd7a3ea32d4e44a4f92fa9c338ca4 3 | timeCreated: 1444962340 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MRT/Scenes/Test.unity: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/unity-mrt-example/0a0b5d919b53df3b62e2f84fc82a2056deb35689/Assets/MRT/Scenes/Test.unity -------------------------------------------------------------------------------- /Assets/MRT/Scenes/Test.unity.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 500bf9aa544462f4481de8578c80a35d 3 | timeCreated: 1444898809 4 | licenseType: Pro 5 | DefaultImporter: 6 | userData: 7 | assetBundleName: 8 | assetBundleVariant: 9 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: e270836e61e49584cb9d0bda9c13379f 3 | folderAsset: yes 4 | timeCreated: 1444898578 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/GPUParticle.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 26f9bdfd24d02b345b40c9ee00d4edd0 3 | folderAsset: yes 4 | timeCreated: 1444962348 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/GPUParticle/GPUParticleSystem.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | using System.Collections; 4 | 5 | public class GPUParticleSystem : MonoBehaviour { 6 | 7 | public GameObject System { get { return system; } } 8 | public MRT ReadMRT { get { return mrts[readIndex]; } } 9 | public MRT WriteMRT { get { return mrts[writeIndex]; } } 10 | 11 | [SerializeField] int vertexCount = 65000; 12 | [SerializeField] Material particleDisplayMat; 13 | [SerializeField] Material particleUpdateMat; 14 | 15 | [SerializeField] MRT[] mrts; 16 | int readIndex = 0; 17 | int writeIndex = 1; 18 | 19 | GameObject system; 20 | 21 | const int VERTEXLIMIT = 65000; 22 | 23 | GameObject Build(int vertCount, out int bufSize) { 24 | System.Type[] objectType = new System.Type[2]; 25 | objectType[0] = typeof(MeshFilter); 26 | objectType[1] = typeof(MeshRenderer); 27 | 28 | GameObject go = new GameObject("ParticleMesh", objectType); 29 | 30 | Mesh particleMesh = new Mesh(); 31 | particleMesh.name = vertCount.ToString(); 32 | 33 | int vc = Mathf.Min(VERTEXLIMIT, vertCount); 34 | bufSize = Mathf.CeilToInt(Mathf.Sqrt(vertCount * 1.0f)); 35 | 36 | Vector3[] verts = new Vector3[vc]; 37 | Vector2[] texcoords = new Vector2[vc]; 38 | 39 | int[] indices = new int[vc]; 40 | 41 | for (int i = 0; i < vc; i++) { 42 | int k = i; 43 | 44 | float tx = 1f * (k % bufSize) / bufSize; 45 | float ty = 1f * (k / bufSize) / bufSize; 46 | 47 | verts[i] = Random.insideUnitSphere; 48 | texcoords[i] = new Vector2(tx, ty); 49 | indices[i] = i; 50 | } 51 | 52 | particleMesh.vertices = verts; 53 | particleMesh.uv = texcoords; 54 | particleMesh.uv2 = texcoords; 55 | 56 | particleMesh.SetIndices(indices, MeshTopology.Points, 0); 57 | particleMesh.RecalculateBounds(); 58 | 59 | go.GetComponent().material = particleDisplayMat; 60 | go.GetComponent().sharedMesh = particleMesh; 61 | 62 | return go; 63 | } 64 | 65 | void Start() { 66 | int bufSize; 67 | system = Build(vertexCount, out bufSize); 68 | system.transform.parent = transform; 69 | 70 | mrts = new MRT[2]; 71 | for(int i = 0, n = mrts.Length; i < n; i++) { 72 | mrts[i] = new MRT(bufSize, bufSize); 73 | } 74 | 75 | ReadMRT.Render(particleUpdateMat, 0); // init 76 | 77 | } 78 | 79 | void Update() { 80 | var buffers = ReadMRT.RenderTextures; 81 | 82 | particleUpdateMat.SetTexture("_PosTex", buffers[0]); 83 | particleUpdateMat.SetTexture("_VelTex", buffers[1]); 84 | particleUpdateMat.SetTexture("_AccTex", buffers[2]); 85 | particleUpdateMat.SetVector("_TrackingTo", 2f * new Vector3(Mathf.Cos(Time.timeSinceLevelLoad), Mathf.Sin(Time.timeSinceLevelLoad), Mathf.Cos(Time.timeSinceLevelLoad))); 86 | 87 | WriteMRT.Render(particleUpdateMat, 1); // update 88 | 89 | Swap(); 90 | 91 | particleDisplayMat.SetTexture("_PosTex", ReadMRT.RenderTextures[0]); 92 | } 93 | 94 | void Swap() { 95 | var tmp = readIndex; 96 | readIndex = writeIndex; 97 | writeIndex = tmp; 98 | } 99 | 100 | void OnDestroy() { 101 | for(int i = 0, n = mrts.Length; i < n; i++) { 102 | mrts[i].Release(); 103 | } 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/GPUParticle/GPUParticleSystem.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: bd9cdb5318abe1b47a8a4a62d093cc00 3 | timeCreated: 1444962357 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/MRT.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | 3 | using System; 4 | using System.Linq; 5 | using System.Collections; 6 | using System.Collections.Generic; 7 | 8 | [System.Serializable] 9 | public class MRT { 10 | 11 | public RenderTexture[] RenderTextures { get { return RTs; } } 12 | public RenderBuffer[] ColorBuffers { get { return RTs.Select(rt => rt.colorBuffer).ToArray(); } } 13 | public RenderBuffer DepthBuffer { get { return RTs[0].depthBuffer; } } 14 | 15 | [SerializeField] RenderTexture[] RTs; 16 | 17 | public MRT(int width, int height, RenderTextureFormat format = RenderTextureFormat.ARGBFloat, FilterMode filterMode = FilterMode.Point, TextureWrapMode wrapMode = TextureWrapMode.Repeat) { 18 | RTs = new RenderTexture[3]; 19 | for(int i = 0, n = RTs.Length; i < n; i++) { 20 | int depth = (i == 0) ? 24 : 0; 21 | RTs[i] = new RenderTexture(width, height, depth); 22 | RTs[i].hideFlags = HideFlags.DontSave; 23 | RTs[i].format = format; 24 | RTs[i].filterMode = filterMode; 25 | RTs[i].wrapMode = wrapMode; 26 | RTs[i].Create(); 27 | } 28 | } 29 | 30 | public void Render (Material mat, int pass = 0) { 31 | Graphics.SetRenderTarget(ColorBuffers, DepthBuffer); 32 | 33 | GL.PushMatrix(); 34 | 35 | mat.SetPass(pass); 36 | 37 | GL.LoadOrtho(); 38 | 39 | GL.Begin(GL.QUADS); 40 | 41 | GL.TexCoord(new Vector3(0, 0, 0)); 42 | GL.Vertex3(0, 0, 0); 43 | 44 | GL.TexCoord(new Vector3(1, 0, 0)); 45 | GL.Vertex3(1, 0, 0); 46 | 47 | GL.TexCoord(new Vector3(1, 1, 0)); 48 | GL.Vertex3(1, 1, 0); 49 | 50 | GL.TexCoord(new Vector3(0, 1, 0)); 51 | GL.Vertex3(0, 1, 0); 52 | 53 | GL.End(); 54 | 55 | GL.PopMatrix(); 56 | } 57 | 58 | public void Release () { 59 | for(int i = 0, n = RTs.Length; i < n; i++) { 60 | RTs[i].Release(); 61 | } 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/MRT.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 120d3893a1f469948b8ddb798f442454 3 | timeCreated: 1444898537 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/Test.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: db5dad506f54f094cbb066fcea033b87 3 | folderAsset: yes 4 | timeCreated: 1444962008 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/Test/MRTTest.cs: -------------------------------------------------------------------------------- 1 | using UnityEngine; 2 | using System.Collections; 3 | 4 | public class MRTTest : MonoBehaviour { 5 | 6 | MRT mrt; 7 | 8 | [SerializeField] Shader testShader; 9 | Material mat; 10 | 11 | void Start() { 12 | mrt = new MRT(Screen.width, Screen.height); 13 | mat = new Material(testShader); 14 | } 15 | 16 | void Update() { 17 | mrt.Render(mat); 18 | } 19 | 20 | void OnGUI() { 21 | var w = Screen.width * 0.5f; 22 | var h = Screen.width * 0.5f; 23 | var r00 = new Rect(0f, 0f, w, h); 24 | var r01 = new Rect(w, 0f, w, h); 25 | var r10 = new Rect(0f, h, w, h); 26 | 27 | var buffers = mrt.RenderTextures; 28 | GUI.DrawTexture(r00, buffers[0]); 29 | GUI.DrawTexture(r01, buffers[1]); 30 | GUI.DrawTexture(r10, buffers[2]); 31 | } 32 | 33 | } 34 | -------------------------------------------------------------------------------- /Assets/MRT/Scripts/Test/MRTTest.cs.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: daeeb5327dbff1240abbb0fb085cc7fa 3 | timeCreated: 1444962017 4 | licenseType: Pro 5 | MonoImporter: 6 | serializedVersion: 2 7 | defaultReferences: [] 8 | executionOrder: 0 9 | icon: {instanceID: 0} 10 | userData: 11 | assetBundleName: 12 | assetBundleVariant: 13 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 75141ba545deb824b95ee9d7f7923056 3 | folderAsset: yes 4 | timeCreated: 1444898587 5 | licenseType: Pro 6 | DefaultImporter: 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/MRTTest.shader: -------------------------------------------------------------------------------- 1 | Shader "MRT/MRTTest" 2 | { 3 | 4 | Properties { 5 | } 6 | 7 | SubShader { 8 | Cull Off ZWrite Off ZTest Always 9 | 10 | Pass 11 | { 12 | CGPROGRAM 13 | #pragma vertex vert 14 | #pragma fragment frag 15 | 16 | #include "UnityCG.cginc" 17 | 18 | struct appdata 19 | { 20 | float4 vertex : POSITION; 21 | float2 uv : TEXCOORD0; 22 | }; 23 | 24 | struct v2f 25 | { 26 | float2 uv : TEXCOORD0; 27 | float4 vertex : SV_POSITION; 28 | }; 29 | 30 | struct f2o 31 | { 32 | float4 col0 : COLOR0; 33 | float4 col1 : COLOR1; 34 | float4 col2 : COLOR2; 35 | }; 36 | 37 | v2f vert (appdata IN) 38 | { 39 | v2f OUT; 40 | OUT.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); 41 | OUT.uv = IN.uv; 42 | return OUT; 43 | } 44 | 45 | sampler2D _MainTex; 46 | 47 | f2o frag (v2f IN) { 48 | f2o OUT; 49 | OUT.col0 = float4(1, 0, 0, 1); 50 | OUT.col1 = float4(0, 1, 0, 1); 51 | OUT.col2 = float4(0, 0, 1, 1); 52 | return OUT; 53 | } 54 | ENDCG 55 | } 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/MRTTest.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: fbced0babed4e054a9b8b37321317939 3 | timeCreated: 1444898594 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/ParticleDisplay.shader: -------------------------------------------------------------------------------- 1 | Shader "GPUParticleSystem/Display" { 2 | 3 | Properties { 4 | _MainTex ("Texture", 2D) = "white" {} 5 | _PosTex ("Position Texture", 2D) = "white" {} 6 | } 7 | 8 | SubShader { 9 | Cull Off ZWrite Off ZTest Always 10 | 11 | CGINCLUDE 12 | 13 | #include "UnityCG.cginc" 14 | 15 | struct appdata { 16 | float4 vertex : POSITION; 17 | float2 uv : TEXCOORD0; 18 | }; 19 | 20 | struct v2f { 21 | float2 uv : TEXCOORD0; 22 | float4 vertex : SV_POSITION; 23 | }; 24 | 25 | sampler2D _MainTex; 26 | sampler2D _PosTex; 27 | 28 | v2f vert (appdata IN) { 29 | v2f o; 30 | 31 | float4 vertex = tex2Dlod(_PosTex, float4(IN.uv, 0, 0)); 32 | o.vertex = mul(UNITY_MATRIX_MVP, float4(vertex.xyz, 1)); 33 | 34 | o.uv = IN.uv; 35 | 36 | return o; 37 | } 38 | 39 | fixed4 frag (v2f i) : SV_Target { 40 | fixed4 col = tex2D(_MainTex, i.uv); 41 | return col; 42 | } 43 | 44 | ENDCG 45 | 46 | Pass { 47 | CGPROGRAM 48 | #pragma vertex vert 49 | #pragma fragment frag 50 | ENDCG 51 | } 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/ParticleDisplay.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 22f8035ab11b6bd42971ac93bf2c90c6 3 | timeCreated: 1444963251 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/ParticleUpdate.shader: -------------------------------------------------------------------------------- 1 | Shader "GPUParticleSystem/Update" { 2 | 3 | Properties { 4 | _PosTex ("Position Texture", 2D) = "white" {} 5 | _VelTex ("Velocity Texture", 2D) = "white" {} 6 | _AccTex ("Acceleration Texture", 2D) = "white" {} 7 | 8 | _TrackingTo ("Tracking Target", Vector) = (0, 0, 0, 0) 9 | } 10 | 11 | SubShader { 12 | 13 | Cull Off ZWrite Off ZTest Always 14 | 15 | CGINCLUDE 16 | 17 | #include "UnityCG.cginc" 18 | #include "./Random.cginc" 19 | 20 | struct appdata { 21 | float4 vertex : POSITION; 22 | float2 uv : TEXCOORD0; 23 | }; 24 | 25 | struct v2f { 26 | float4 vertex : SV_POSITION; 27 | float2 uv : TEXCOORD0; 28 | }; 29 | 30 | struct f2o { 31 | float4 color0 : COLOR0; 32 | float4 color1 : COLOR1; 33 | float4 color2 : COLOR2; 34 | }; 35 | 36 | v2f vert (appdata IN) { 37 | v2f o; 38 | o.vertex = mul(UNITY_MATRIX_MVP, IN.vertex); 39 | o.uv = IN.uv; 40 | return o; 41 | } 42 | 43 | sampler2D _PosTex; 44 | sampler2D _VelTex; 45 | sampler2D _AccTex; 46 | float3 _TrackingTo; 47 | 48 | f2o init (v2f IN) { 49 | f2o OUT; 50 | 51 | OUT.color0 = float4((rand3(IN.uv) - 0.5) * 2.0, rand(IN.uv)); 52 | OUT.color1 = float4(0, 0, 0, 1); 53 | OUT.color2 = float4(0, 0, 0, 1); 54 | 55 | return OUT; 56 | } 57 | 58 | float3 track (float3 p) { 59 | float3 v = _TrackingTo - p; 60 | return normalize(v); 61 | } 62 | 63 | f2o update (v2f IN) { 64 | f2o OUT; 65 | 66 | float4 pos = tex2D(_PosTex, IN.uv); 67 | float4 vel = tex2D(_VelTex, IN.uv); 68 | float4 acc = tex2D(_AccTex, IN.uv); 69 | 70 | acc.xyz += track(pos.xyz); 71 | vel.xyz *= 0.9; 72 | vel.xyz += (acc.xyz * unity_DeltaTime.x) / pos.w; 73 | pos.xyz += vel.xyz * unity_DeltaTime.x; 74 | 75 | OUT.color0 = pos; 76 | OUT.color1 = vel; 77 | OUT.color2 = acc; 78 | 79 | return OUT; 80 | } 81 | 82 | ENDCG 83 | 84 | Pass { 85 | CGPROGRAM 86 | #pragma vertex vert 87 | #pragma fragment init 88 | ENDCG 89 | } 90 | 91 | Pass { 92 | CGPROGRAM 93 | #pragma vertex vert 94 | #pragma fragment update 95 | ENDCG 96 | } 97 | 98 | } 99 | } 100 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/ParticleUpdate.shader.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: b781b8a6548fa1541941349f8bea389e 3 | timeCreated: 1444963413 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/Random.cginc: -------------------------------------------------------------------------------- 1 | #ifndef RANDOM_INCLUDED 2 | #define RANDOM_INCLUDED 3 | 4 | float rand( float2 co ){ 5 | return frac(sin(dot(co.xy, float2(12.9898, 78.233))) * 43758.5453); 6 | } 7 | 8 | float3 rand3( float2 seed ){ 9 | float t = sin(seed.x + seed.y * 1e3); 10 | return float3(frac(t*1e4), frac(t*1e6), frac(t*1e5)); 11 | } 12 | 13 | #endif // RANDOM_INCLUDED 14 | -------------------------------------------------------------------------------- /Assets/MRT/Shaders/Random.cginc.meta: -------------------------------------------------------------------------------- 1 | fileFormatVersion: 2 2 | guid: 44ff9ee44bfaf3641851b319d53b75d7 3 | timeCreated: 1444965145 4 | licenseType: Pro 5 | ShaderImporter: 6 | defaultTextures: [] 7 | userData: 8 | assetBundleName: 9 | assetBundleVariant: 10 | -------------------------------------------------------------------------------- /Captures/gpu-particle-example.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mattatz/unity-mrt-example/0a0b5d919b53df3b62e2f84fc82a2056deb35689/Captures/gpu-particle-example.png -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | unity-mrt-example 2 | ================= 3 | 4 | Unity example of multiple render targets. 5 | 6 | This example MRT script doesn't use camera object. 7 | 8 | ![gpu-particle-example](https://raw.githubusercontent.com/mattatz/unity-mrt-example/master/Captures/gpu-particle-example.png) 9 | 10 | --------------------------------------------------------------------------------