Advertisement
Guest User

Untitled

a guest
Mar 18th, 2019
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. Shader "Unlit/shadow"
  2. {
  3. Properties
  4. {
  5. _MainTex ("Texture", 2D) = "white" {}
  6. }
  7. SubShader
  8. {
  9. Tags { "RenderType"="Opaque" }
  10. LOD 100
  11.  
  12. Pass
  13. {
  14. CGPROGRAM
  15.  
  16. #pragma vertex vert
  17. #pragma fragment frag
  18. // make fog work
  19. #pragma multi_compile_fog
  20.  
  21. #include "UnityCG.cginc"
  22. #include "AutoLight.cginc"
  23.  
  24. //UNITY_DECLARE_SHADOWMAP(_ShadowMapTexture);
  25. //uniform sampler2D _ShadowMapTexture;
  26. uniform sampler2D m_ShadowmapCopy;
  27.  
  28. struct appdata
  29. {
  30. float4 vertex : POSITION;
  31. float2 uv : TEXCOORD0;
  32. };
  33.  
  34. struct v2f
  35. {
  36. float2 uv : TEXCOORD0;
  37. UNITY_FOG_COORDS(1)
  38. float4 vertex : SV_POSITION;
  39. float4 _ShadowCoord: TEXCOORD2;
  40. float3 _worldpos : TEXCOORD3;
  41. };
  42.  
  43. sampler2D _MainTex;
  44. float4 _MainTex_ST;
  45.  
  46. v2f vert (appdata v)
  47. {
  48. v2f o;
  49. o.vertex = UnityObjectToClipPos(v.vertex);
  50. o.uv = TRANSFORM_TEX(v.uv, _MainTex);
  51. UNITY_TRANSFER_FOG(o,o.vertex);
  52. o._worldpos = mul(unity_ObjectToWorld, v.vertex);
  53. //o._ShadowCoord = ComputeScreenPos(o.vertex); //mul(unity_WorldToShadow[0], o._worldpos);
  54. o._ShadowCoord = mul(unity_WorldToShadow[1], o._worldpos);
  55. return o;
  56. }
  57.  
  58. fixed4 frag (v2f i) : SV_Target
  59. {
  60. // sample the texture
  61. fixed4 col = tex2D(_MainTex, i.uv);
  62. //float depth = tex2Dproj(_ShadowMapTexture, UNITY_PROJ_COORD(i._ShadowCoord)).x;
  63. //float depth = tex2Dproj(_ShadowMapTexture, i._ShadowCoord).x;
  64. //depth = Linear01Depth(depth);
  65. //col = max(depth > (i._ShadowCoord.z / i._ShadowCoord.w), _LightShadowData.x);
  66. //col = depth;
  67. //float shadowAttenuation = UnitySampleShadowmap(
  68. // mul(unity_WorldToShadow[0], float4(i._worldpos, 1))
  69. //);
  70. float depth = tex2D(m_ShadowmapCopy, i.uv).r;
  71. //float depth = tex2D(m_ShadowmapCopy, i._ShadowCoord.xy).r;
  72. //float depth = tex2Dproj(m_ShadowmapCopy, UNITY_PROJ_COORD(i._ShadowCoord)).x;
  73. //depth = Linear01Depth(depth);
  74. col = depth;
  75. col.w = 1;
  76. return col;
  77. // apply fog
  78. UNITY_APPLY_FOG(i.fogCoord, col);
  79. return col;
  80. }
  81. ENDCG
  82. }
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement