Advertisement
Guest User

Untitled

a guest
Jun 13th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  Shader "Instanced/InstancedShader" {
  2.     Properties {
  3.         _MainTex ("Albedo (RGB)", 2D) = "white" {}
  4.     }
  5.     SubShader {
  6.  
  7.         Pass {
  8.             ZWrite Off
  9.             Blend SrcAlpha OneMinusSrcAlpha
  10.             Tags {"Queue"="Transparent"}
  11.             CGPROGRAM
  12. // Upgrade NOTE: excluded shader from OpenGL ES 2.0 because it uses non-square matrices
  13. #pragma exclude_renderers gles
  14.  
  15.             #pragma vertex vert
  16.             #pragma fragment frag
  17.             #pragma target 4.5
  18.  
  19.             #include "UnityCG.cginc"
  20.  
  21.             sampler2D _MainTex;
  22.  
  23.             StructuredBuffer<float4x2> matrixBuffer;
  24.  
  25.             struct v2f
  26.             {
  27.                 float4 pos : SV_POSITION;
  28.                 float2 uv: TEXCOORD0;
  29.             };
  30.  
  31.             v2f vert (appdata_full v, uint instanceID : SV_InstanceID)
  32.             {
  33.                 //IMPLEMENTARE ROTAZIONE SI TROVA SULLA W
  34.                 float4 position = float4(matrixBuffer[instanceID][0].x,matrixBuffer[instanceID][1].x,matrixBuffer[instanceID][2].x,matrixBuffer[instanceID][3].x);
  35.                 float4 uv = float4(matrixBuffer[instanceID][0].y,matrixBuffer[instanceID][1].y,matrixBuffer[instanceID][2].y,matrixBuffer[instanceID][3].y);
  36.                
  37.                 float3 worldPosition = position.xyz + (v.vertex.xyz * position.w);
  38.                 float3 color = v.color;
  39.  
  40.                 v2f o;
  41.                 o.pos = mul(UNITY_MATRIX_VP, float4(worldPosition, 1.0f));
  42.                 o.uv =  v.texcoord * uv.xy + uv.zw;
  43.                 return o;
  44.             }
  45.  
  46.             fixed4 frag (v2f i) : SV_Target
  47.             {
  48.                 fixed4 albedo = tex2D(_MainTex, i.uv);
  49.                 fixed4 output = fixed4(albedo.rgb, albedo.w);
  50.                 return output;
  51.             }
  52.  
  53.             ENDCG
  54.         }
  55.     }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement