Advertisement
Guest User

Untitled

a guest
Dec 25th, 2012
639
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. Shader "HP/RenderParticles" {
  2. Properties {
  3. _Sprite ("", 2D) = "white" {}
  4. }
  5.  
  6. SubShader {
  7. Pass{
  8. ZWrite Off ZTest Always Cull Off Fog { Mode Off }
  9. Blend SrcAlpha One
  10.  
  11. CGPROGRAM
  12. #pragma target 5.0
  13.  
  14. #pragma vertex vert
  15. #pragma geometry geom
  16. #pragma fragment frag
  17.  
  18. #include "UnityCG.cginc"
  19.  
  20. StructuredBuffer<float3> particleBuffer;
  21. StructuredBuffer<float3> particleColor;
  22.  
  23. struct vs_out {
  24. float4 pos : SV_POSITION;
  25. float4 col : COLOR;
  26. };
  27.  
  28. vs_out vert (uint id : SV_VertexID)
  29. {
  30. // This runs through for each instance of the shader, id corrisponds to the particle in the list
  31. vs_out o;
  32. // Pull the location data and send it off to the geometry shader so it can be built into a particle
  33. o.pos = float4(particleBuffer[id], 1.0f);
  34. o.col = float4(particleColor[id], 1.0f);
  35. return o;
  36. }
  37.  
  38. struct gs_out {
  39. float4 pos : SV_POSITION;
  40. float2 uv : TEXCOORD0;
  41. float4 col : COLOR;
  42. };
  43.  
  44. [maxvertexcount(4)]
  45. void geom (point vs_out input[1], inout TriangleStream<gs_out> outStream)
  46. {
  47. float Size = 0.1f;
  48.  
  49. float dx = Size;
  50. float dy = Size * _ScreenParams.x / _ScreenParams.y;
  51. gs_out output;
  52.  
  53. // Run the given position through the View Proj matrix
  54.  
  55. float4 corLoc = mul(UNITY_MATRIX_MVP, input[0].pos);
  56. // Build the 4 points of the sprite and it's uv
  57. output.pos = corLoc + float4(-dx, dy,0,0); output.uv=float2(0,0); output.col = input[0].col; outStream.Append (output);
  58. output.pos = corLoc + float4( dx, dy,0,0); output.uv=float2(1,0); output.col = input[0].col; outStream.Append (output);
  59. output.pos = corLoc + float4(-dx,-dy,0,0); output.uv=float2(0,1); output.col = input[0].col; outStream.Append (output);
  60. output.pos = corLoc + float4( dx,-dy,0,0); output.uv=float2(1,1); output.col = input[0].col; outStream.Append (output);
  61. // Send it off as a particle to the pixel shader
  62. outStream.RestartStrip();
  63. }
  64.  
  65. // Pixel shader, straight forward just sample the sprite
  66. sampler2D _Sprite;
  67.  
  68. fixed4 frag (gs_out i ) : COLOR0
  69. {
  70. //fixed4 col = tex2D(_Sprite, i.uv);
  71. //col.w = 0.1f;
  72. return i.col;
  73. }
  74.  
  75. ENDCG
  76.  
  77. }
  78. }
  79.  
  80. Fallback Off
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement