Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
158
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
  2.  
  3. Shader "COMBsm/DX11/Transparent" {
  4.     Properties{
  5.         _BumpMap("Normal Map", 2D) = "bump" {}
  6.         //_Metallic("Metallic", Range(0,1)) = 0.0
  7.  
  8.     }
  9.  
  10.         SubShader
  11.     {
  12.         Tags
  13.     { "Queue" = "AlphaTest" "IgnoreProjector" = "False" "RenderType" = "Transparent" }
  14.  
  15.         /////////////////////////////////////////////////////////
  16.         /// First Pass
  17.         /////////////////////////////////////////////////////////
  18.  
  19.         Pass
  20.     {
  21.         // Only render alpha channel
  22.         ColorMask A
  23.         Blend SrcAlpha OneMinusSrcAlpha
  24.  
  25.         CGPROGRAM
  26. #pragma vertex vert
  27. #pragma fragment frag
  28.  
  29. #pragma target 3.0
  30.  
  31.  
  32.     uniform StructuredBuffer<uint> _Buff1;
  33.     uniform StructuredBuffer<uint> _Buff2;
  34.     float4x4 matr[25];
  35.     uint vprm = 24;
  36.  
  37.  
  38.     // note: no SV_POSITION in this struct
  39.     struct v2f
  40.     {
  41.         float2 uv : TEXCOORD0;
  42.     };
  43.  
  44.     v2f vert(
  45.         float4 vertex : POSITION, // vertex position input
  46.         uint id : SV_VertexID,
  47.         out float4 outpos : SV_POSITION // clip space position output
  48.     )
  49.     {
  50.         v2f o;
  51.  
  52.         uint cbid = (uint)id / (uint)vprm;
  53.         uint p = _Buff1[cbid];
  54.         float4x4 mt = matr[p >> 24];
  55.         vertex *= 1 - (bool)(_Buff2[cbid / 32] & (1 << (cbid % 32)));
  56.        
  57.         uint iX = p & 0xFF, iY = (p >> 8) & 0xFF, iZ = (p >> 16) & 0xFF;
  58.         float x = iX; if (iX >= 128) x -= 256;
  59.         float y = iY; if (iY >= 128) y -= 256;
  60.         float z = iZ; if (iZ >= 128) z -= 256;
  61.         float4 pos = float4(x, y, z, 0);
  62.         outpos = UnityObjectToClipPos(mul(mt,vertex) + pos.xyz);
  63.         return o;
  64.     }
  65.  
  66.     sampler2D _MainTex;
  67.  
  68.  
  69.     fixed4 frag(v2f i, UNITY_VPOS_TYPE screenPos : VPOS) : SV_Target
  70.     {
  71.         fixed4 c = fixed4(0,0,0,1);// tex2D(_MainTex, i.uv)*_Color;
  72.     return c;
  73.     }
  74.  
  75.         ENDCG
  76.     }
  77.  
  78.         /////////////////////////////////////////////////////////
  79.         /// Second Pass
  80.         /////////////////////////////////////////////////////////
  81.  
  82.         //Tags  { "Queue" = "Transparent" "IgnoreProjector" = "False" "RenderType" = "Transparent" }
  83.         Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
  84.         Blend SrcAlpha OneMinusSrcAlpha
  85.         LOD 200
  86.  
  87.         CGPROGRAM
  88. #pragma surface surf Lambert alpha:fade vertex:vert //noshadows
  89. #pragma target 5.0
  90.  
  91.  
  92.         sampler2D _MainTex;
  93.     sampler2D _BumpMap;
  94.     sampler2D _EmissionMap;
  95.  
  96.  
  97.     struct appdata {
  98.         float4 vertex : POSITION;
  99.         float4 texcoord : TEXCOORD0;
  100.         float4 texcoord1 : TEXCOORD1;
  101.         float4 texcoord2 : TEXCOORD2;
  102.  
  103.         float4 tangent : TANGENT;
  104.         float3 normal : NORMAL;
  105.         //float4 color : COLOR;
  106.         uint id : SV_VertexID;
  107.     };
  108.  
  109.     struct Input {
  110.         float2 uv_BumpMap;
  111.     };
  112.  
  113.  
  114.  
  115. #ifdef SHADER_API_D3D11
  116.     uniform StructuredBuffer<uint> _Buff1;
  117.     uniform StructuredBuffer<uint> _Buff2;
  118. #endif
  119.     float4x4 matr[25];
  120.     uint vprm = 24;
  121.  
  122.     void vert(inout appdata v) {
  123.  
  124.         uint id = v.id;
  125.         uint cbid = (uint)id / (uint)vprm;
  126.         v.vertex *= 1 - (bool)(_Buff2[cbid / 32] & (1 << (cbid % 32)));
  127.  
  128.         uint p = _Buff1[cbid];
  129.         float4x4 mt = matr[p >> 24];
  130.         float a = float(128);
  131.         uint iX = p & 0xFF, iY = (p >> 8) & 0xFF, iZ = (p >> 16) & 0xFF;
  132.         float x = iX; if (iX >= 128) x -= 256;
  133.         float y = iY; if (iY >= 128) y -= 256;
  134.         float z = iZ; if (iZ >= 128) z -= 256;
  135.         float4 pos = float4(x, y, z, 0);
  136.         v.vertex.xyz = mul(mt, v.vertex) + pos.xyz;
  137.         v.normal = mul(mt, v.normal);
  138.         v.tangent = mul(mt, v.tangent);
  139.     }
  140.  
  141.     void surf(Input IN, inout SurfaceOutput o) {
  142.         o.Normal = UnpackNormal(tex2D(_BumpMap, IN.uv_BumpMap));
  143.         o.Albedo = float3(0.8, 0.5, 1);
  144.         o.Alpha = 0.5;
  145.         o.Emission = float3(0.5,0.5,0.5);
  146.         }
  147.     ENDCG
  148.     }
  149. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement