FXVVolumetricFogLitURP.shader 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. Shader "FXV/FXVVolumeFogLitURP"
  2. {
  3. Properties
  4. {
  5. [HideInInspector]_QueueOffset("_QueueOffset", Float) = 0
  6. [HideInInspector]_QueueControl("_QueueControl", Float) = -1
  7. [HideInInspector][NoScaleOffset]unity_Lightmaps("unity_Lightmaps", 2DArray) = "" {}
  8. [HideInInspector][NoScaleOffset]unity_LightmapsInd("unity_LightmapsInd", 2DArray) = "" {}
  9. [HideInInspector][NoScaleOffset]unity_ShadowMasks("unity_ShadowMasks", 2DArray) = "" {}
  10. [HideInInspector] _FogType("__fogtype", Float) = 0.0
  11. [HideInInspector] _FogFalloffType("__fogfallofftype", Float) = 0.0
  12. [HideInInspector] _FogFalloff("__fogfalloff", Float) = 1.0
  13. [HideInInspector] _FogMeshType("__fogmeshtype", Float) = 0.0
  14. [HideInInspector] _FogClipping("__fogclipping", Float) = 0.0
  15. [HideInInspector][Toggle] _InAirEnabled("__inairenabled", Int) = 0
  16. [HideInInspector] _BlendMode("__mode", Float) = 0.0
  17. [HideInInspector] _SrcBlend("__src", Float) = 1.0
  18. [HideInInspector] _DstBlend("__dst", Float) = 0.0
  19. [HideInInspector] _ZWrite("__zw", Float) = 1.0
  20. [HideInInspector][Toggle] _AxisFadeEnabled("__axisfade", Float) = 0.0
  21. }
  22. SubShader
  23. {
  24. Tags
  25. {
  26. "RenderPipeline"="UniversalPipeline"
  27. "RenderType"="Transparent"
  28. "UniversalMaterialType" = "Lit"
  29. "Queue"="Transparent"
  30. "ShaderGraphShader"="true"
  31. "ShaderGraphTargetId"="UniversalLitSubTarget"
  32. }
  33. Pass
  34. {
  35. Name "Universal Forward"
  36. Tags
  37. {
  38. "LightMode" = "UniversalForward"
  39. }
  40. // Render State
  41. Cull Back
  42. Blend SrcAlpha OneMinusSrcAlpha, One OneMinusSrcAlpha
  43. ZTest LEqual
  44. ZWrite Off
  45. // Debug
  46. // <None>
  47. // --------------------------------------------------
  48. // Pass
  49. HLSLPROGRAM
  50. #define FXV_VOLUMEFOG_URP
  51. #if defined(FXV_VOLUMEFOG_URP)
  52. // Pragmas
  53. #pragma target 3.5
  54. #pragma multi_compile_instancing
  55. #pragma multi_compile_fog
  56. #pragma instancing_options renderinglayer
  57. #pragma multi_compile _ DOTS_INSTANCING_ON
  58. #pragma vertex vert
  59. #pragma fragment frag
  60. // DotsInstancingOptions: <None>
  61. // HybridV1InjectedBuiltinProperties: <None>
  62. // Keywords
  63. #pragma multi_compile_fragment _ _SCREEN_SPACE_OCCLUSION
  64. #pragma multi_compile _ LIGHTMAP_ON
  65. #pragma multi_compile _ DYNAMICLIGHTMAP_ON
  66. #pragma multi_compile _ DIRLIGHTMAP_COMBINED
  67. #pragma multi_compile _ _MAIN_LIGHT_SHADOWS _MAIN_LIGHT_SHADOWS_CASCADE _MAIN_LIGHT_SHADOWS_SCREEN
  68. #pragma multi_compile _ _ADDITIONAL_LIGHTS_VERTEX _ADDITIONAL_LIGHTS
  69. #pragma multi_compile_fragment _ _ADDITIONAL_LIGHT_SHADOWS
  70. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BLENDING
  71. #pragma multi_compile_fragment _ _REFLECTION_PROBE_BOX_PROJECTION
  72. #pragma multi_compile_fragment _ _SHADOWS_SOFT
  73. #pragma multi_compile _ LIGHTMAP_SHADOW_MIXING
  74. #pragma multi_compile _ SHADOWS_SHADOWMASK
  75. #pragma multi_compile_fragment _ _DBUFFER_MRT1 _DBUFFER_MRT2 _DBUFFER_MRT3
  76. #pragma multi_compile_fragment _ _LIGHT_LAYERS
  77. #pragma multi_compile_fragment _ DEBUG_DISPLAY
  78. #pragma multi_compile_fragment _ _LIGHT_COOKIES
  79. #pragma multi_compile _ _CLUSTERED_RENDERING
  80. #pragma multi_compile _ _FORWARD_PLUS
  81. #pragma shader_feature_local FXV_FOGTYPE_VIEWALIGNED FXV_FOGTYPE_SPHERICALPOS FXV_FOGTYPE_SPHERICALDIST FXV_FOGTYPE_BOXPOS FXV_FOGTYPE_BOXDIST FXV_FOGTYPE_BOXEXPERIMENTAL FXV_FOGTYPE_HEIGHT FXV_FOGTYPE_HEIGHTXBOX FXV_FOGTYPE_INVERTEDSPHERICAL FXV_FOGTYPE_INVERTEDSPHERICALXHEIGHT FXV_FOGTYPE_HEIGHTXVIEW FXV_FOGTYPE_BOXXVIEW
  82. #pragma shader_feature_local FXV_IN_AIR_FOG __
  83. #pragma shader_feature_local FXV_LINEAR_FALLOFF FXV_SMOOTHED_FALLOFF FXV_EXP_FALLOFF FXV_EXP2_FALLOFF
  84. #pragma shader_feature_local FXV_FOG_CUSTOM_MESH __
  85. #pragma shader_feature_local FXV_FOG_CLIP_SKYBOX FXV_FOG_CLIP_BOUNDS __
  86. // GraphKeywords: <None>
  87. // Defines
  88. #define _NORMALMAP 1
  89. #define _NORMAL_DROPOFF_TS 1
  90. #define ATTRIBUTES_NEED_NORMAL
  91. #define ATTRIBUTES_NEED_TANGENT
  92. #define ATTRIBUTES_NEED_TEXCOORD1
  93. #define ATTRIBUTES_NEED_TEXCOORD2
  94. #define VARYINGS_NEED_POSITION_WS
  95. #define VARYINGS_NEED_NORMAL_WS
  96. #define VARYINGS_NEED_TANGENT_WS
  97. #define VARYINGS_NEED_VIEWDIRECTION_WS
  98. #define VARYINGS_NEED_DEPTH
  99. #define VARYINGS_NEED_FOG_AND_VERTEX_LIGHT
  100. //#define VARYINGS_NEED_SHADOW_COORD
  101. #define VARYINGS_NEED_SCREENPOSITION
  102. #define FEATURES_GRAPH_VERTEX
  103. /* WARNING: $splice Could not find named fragment 'PassInstancing' */
  104. #define SHADERPASS SHADERPASS_FORWARD
  105. #define _FOG_FRAGMENT 1
  106. #define _SURFACE_TYPE_TRANSPARENT 1
  107. #define _RECEIVE_SHADOWS_OFF 1
  108. /* WARNING: $splice Could not find named fragment 'DotsInstancingVars' */
  109. // custom interpolator pre-include
  110. /* WARNING: $splice Could not find named fragment 'sgci_CustomInterpolatorPreInclude' */
  111. // Includes
  112. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Color.hlsl"
  113. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/Texture.hlsl"
  114. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"
  115. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Lighting.hlsl"
  116. #include "Packages/com.unity.render-pipelines.core/ShaderLibrary/TextureStack.hlsl"
  117. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Shadows.hlsl"
  118. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/ShaderGraphFunctions.hlsl"
  119. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DBuffer.hlsl"
  120. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/ShaderPass.hlsl"
  121. #define FXV_VOLUMEFOG_URP
  122. #include "../../Shaders/FXVVolumeFog.cginc"
  123. // --------------------------------------------------
  124. // Structs and Packing
  125. // custom interpolators pre packing
  126. /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPrePacking' */
  127. struct Attributes
  128. {
  129. FXV_VOLUMETRIC_FOG_APPDATA
  130. float3 normalOS : NORMAL;
  131. float4 tangentOS : TANGENT;
  132. float4 uv1 : TEXCOORD1;
  133. //float4 uv2 : TEXCOORD2;
  134. #if UNITY_ANY_INSTANCING_ENABLED
  135. // uint instanceID : INSTANCEID_SEMANTIC;
  136. #endif
  137. };
  138. struct Varyings
  139. {
  140. float4 positionCS : SV_POSITION;
  141. float3 positionWS;
  142. float3 normalWS;
  143. float4 tangentWS;
  144. float3 viewDirectionWS;
  145. float4 screenPosition;
  146. #if defined(VARYINGS_NEED_DEPTH)
  147. float depth;
  148. #endif
  149. #if defined(LIGHTMAP_ON)
  150. float2 staticLightmapUV;
  151. #endif
  152. #if defined(DYNAMICLIGHTMAP_ON)
  153. float2 dynamicLightmapUV;
  154. #endif
  155. #if !defined(LIGHTMAP_ON)
  156. float3 sh;
  157. #endif
  158. float4 fogFactorAndVertexLight;
  159. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  160. float4 shadowCoord;
  161. #endif
  162. #if UNITY_ANY_INSTANCING_ENABLED
  163. uint instanceID : CUSTOM_INSTANCE_ID;
  164. #endif
  165. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  166. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  167. #endif
  168. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  169. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  170. #endif
  171. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  172. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  173. #endif
  174. };
  175. struct SurfaceDescriptionInputs
  176. {
  177. float3 TangentSpaceNormal;
  178. };
  179. struct VertexDescriptionInputs
  180. {
  181. float3 ObjectSpaceNormal;
  182. float3 ObjectSpaceTangent;
  183. float3 ObjectSpacePosition;
  184. };
  185. struct PackedVaryings
  186. {
  187. float4 positionCS : SV_POSITION;
  188. #if defined(LIGHTMAP_ON)
  189. float2 staticLightmapUV : INTERP0;
  190. #endif
  191. #if defined(DYNAMICLIGHTMAP_ON)
  192. float2 dynamicLightmapUV : INTERP1;
  193. #endif
  194. #if !defined(LIGHTMAP_ON)
  195. float3 sh : INTERP2;
  196. #endif
  197. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  198. float4 shadowCoord : INTERP3;
  199. #endif
  200. float4 tangentWS : INTERP4;
  201. float4 fogFactorAndVertexLight : INTERP5;
  202. float3 positionWS : INTERP6;
  203. float3 normalWS : INTERP7;
  204. float3 viewDirectionWS : INTERP8;
  205. float4 screenPosition: INTERP9;
  206. #if defined(VARYINGS_NEED_DEPTH)
  207. float depth : INTERP10;
  208. #endif
  209. #if UNITY_ANY_INSTANCING_ENABLED
  210. uint instanceID : CUSTOM_INSTANCE_ID;
  211. #endif
  212. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  213. uint stereoTargetEyeIndexAsBlendIdx0 : BLENDINDICES0;
  214. #endif
  215. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  216. uint stereoTargetEyeIndexAsRTArrayIdx : SV_RenderTargetArrayIndex;
  217. #endif
  218. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  219. FRONT_FACE_TYPE cullFace : FRONT_FACE_SEMANTIC;
  220. #endif
  221. };
  222. PackedVaryings PackVaryings (Varyings input)
  223. {
  224. PackedVaryings output;
  225. ZERO_INITIALIZE(PackedVaryings, output);
  226. output.positionCS = input.positionCS;
  227. #if defined(LIGHTMAP_ON)
  228. output.staticLightmapUV = input.staticLightmapUV;
  229. #endif
  230. #if defined(DYNAMICLIGHTMAP_ON)
  231. output.dynamicLightmapUV = input.dynamicLightmapUV;
  232. #endif
  233. #if !defined(LIGHTMAP_ON)
  234. output.sh = input.sh;
  235. #endif
  236. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  237. output.shadowCoord = input.shadowCoord;
  238. #endif
  239. output.tangentWS.xyzw = input.tangentWS;
  240. output.fogFactorAndVertexLight.xyzw = input.fogFactorAndVertexLight;
  241. output.positionWS.xyz = input.positionWS;
  242. output.normalWS.xyz = input.normalWS;
  243. output.viewDirectionWS.xyz = input.viewDirectionWS;
  244. output.screenPosition = input.screenPosition;
  245. #if defined(VARYINGS_NEED_DEPTH)
  246. output.depth = input.depth;
  247. #endif
  248. #if UNITY_ANY_INSTANCING_ENABLED
  249. output.instanceID = input.instanceID;
  250. #endif
  251. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  252. output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  253. #endif
  254. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  255. output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
  256. #endif
  257. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  258. output.cullFace = input.cullFace;
  259. #endif
  260. return output;
  261. }
  262. Varyings UnpackVaryings (PackedVaryings input)
  263. {
  264. Varyings output;
  265. output.positionCS = input.positionCS;
  266. #if defined(LIGHTMAP_ON)
  267. output.staticLightmapUV = input.staticLightmapUV;
  268. #endif
  269. #if defined(DYNAMICLIGHTMAP_ON)
  270. output.dynamicLightmapUV = input.dynamicLightmapUV;
  271. #endif
  272. #if !defined(LIGHTMAP_ON)
  273. output.sh = input.sh;
  274. #endif
  275. #if defined(REQUIRES_VERTEX_SHADOW_COORD_INTERPOLATOR)
  276. output.shadowCoord = input.shadowCoord;
  277. #endif
  278. output.tangentWS = input.tangentWS.xyzw;
  279. output.fogFactorAndVertexLight = input.fogFactorAndVertexLight.xyzw;
  280. output.positionWS = input.positionWS.xyz;
  281. output.normalWS = input.normalWS.xyz;
  282. output.viewDirectionWS = input.viewDirectionWS.xyz;
  283. output.screenPosition = input.screenPosition;
  284. #if defined(VARYINGS_NEED_DEPTH)
  285. output.depth = input.depth;
  286. #endif
  287. #if UNITY_ANY_INSTANCING_ENABLED
  288. output.instanceID = input.instanceID;
  289. #endif
  290. #if (defined(UNITY_STEREO_MULTIVIEW_ENABLED)) || (defined(UNITY_STEREO_INSTANCING_ENABLED) && (defined(SHADER_API_GLES3) || defined(SHADER_API_GLCORE)))
  291. output.stereoTargetEyeIndexAsBlendIdx0 = input.stereoTargetEyeIndexAsBlendIdx0;
  292. #endif
  293. #if (defined(UNITY_STEREO_INSTANCING_ENABLED))
  294. output.stereoTargetEyeIndexAsRTArrayIdx = input.stereoTargetEyeIndexAsRTArrayIdx;
  295. #endif
  296. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  297. output.cullFace = input.cullFace;
  298. #endif
  299. return output;
  300. }
  301. // --------------------------------------------------
  302. // Graph
  303. // Graph Properties
  304. CBUFFER_START(UnityPerMaterial)
  305. CBUFFER_END
  306. // Object and Global properties
  307. // Graph Includes
  308. // GraphIncludes: <None>
  309. // -- Property used by ScenePickingPass
  310. #ifdef SCENEPICKINGPASS
  311. float4 _SelectionID;
  312. #endif
  313. // -- Properties used by SceneSelectionPass
  314. #ifdef SCENESELECTIONPASS
  315. int _ObjectId;
  316. int _PassValue;
  317. #endif
  318. // Graph Functions
  319. // GraphFunctions: <None>
  320. // Custom interpolators pre vertex
  321. /* WARNING: $splice Could not find named fragment 'CustomInterpolatorPreVertex' */
  322. // Graph Vertex
  323. struct VertexDescription
  324. {
  325. float3 Position;
  326. float3 Normal;
  327. float3 Tangent;
  328. };
  329. VertexDescription VertexDescriptionFunction(VertexDescriptionInputs IN)
  330. {
  331. VertexDescription description = (VertexDescription)0;
  332. description.Position = IN.ObjectSpacePosition;
  333. description.Normal = IN.ObjectSpaceNormal;
  334. description.Tangent = IN.ObjectSpaceTangent;
  335. return description;
  336. }
  337. // Custom interpolators, pre surface
  338. #ifdef FEATURES_GRAPH_VERTEX
  339. Varyings CustomInterpolatorPassThroughFunc(inout Varyings output, VertexDescription input)
  340. {
  341. return output;
  342. }
  343. #define CUSTOMINTERPOLATOR_VARYPASSTHROUGH_FUNC
  344. #endif
  345. // Graph Pixel
  346. struct SurfaceDescription
  347. {
  348. float3 BaseColor;
  349. float3 NormalTS;
  350. float3 Emission;
  351. float Metallic;
  352. float Smoothness;
  353. float Occlusion;
  354. float Alpha;
  355. };
  356. SurfaceDescription SurfaceDescriptionFunction(SurfaceDescriptionInputs IN)
  357. {
  358. SurfaceDescription surface = (SurfaceDescription)0;
  359. surface.BaseColor = IsGammaSpace() ? float3(0.5, 0.5, 0.5) : SRGBToLinear(float3(0.5, 0.5, 0.5));
  360. surface.NormalTS = IN.TangentSpaceNormal;
  361. surface.Emission = float3(0, 0, 0);
  362. surface.Metallic = 0;
  363. surface.Smoothness = 0.5;
  364. surface.Occlusion = 1;
  365. surface.Alpha = 1;
  366. return surface;
  367. }
  368. // --------------------------------------------------
  369. // Build Graph Inputs
  370. #ifdef HAVE_VFX_MODIFICATION
  371. #define VFX_SRP_ATTRIBUTES Attributes
  372. #define VFX_SRP_VARYINGS Varyings
  373. #define VFX_SRP_SURFACE_INPUTS SurfaceDescriptionInputs
  374. #endif
  375. VertexDescriptionInputs BuildVertexDescriptionInputs(Attributes input)
  376. {
  377. VertexDescriptionInputs output;
  378. ZERO_INITIALIZE(VertexDescriptionInputs, output);
  379. output.ObjectSpaceNormal = input.normalOS;
  380. output.ObjectSpaceTangent = input.tangentOS.xyz;
  381. output.ObjectSpacePosition = input.positionOS;
  382. return output;
  383. }
  384. SurfaceDescriptionInputs BuildSurfaceDescriptionInputs(Varyings input)
  385. {
  386. SurfaceDescriptionInputs output;
  387. ZERO_INITIALIZE(SurfaceDescriptionInputs, output);
  388. #ifdef HAVE_VFX_MODIFICATION
  389. // FragInputs from VFX come from two places: Interpolator or CBuffer.
  390. /* WARNING: $splice Could not find named fragment 'VFXSetFragInputs' */
  391. #endif
  392. output.TangentSpaceNormal = float3(0.0f, 0.0f, 1.0f);
  393. #if defined(SHADER_STAGE_FRAGMENT) && defined(VARYINGS_NEED_CULLFACE)
  394. #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN output.FaceSign = IS_FRONT_VFACE(input.cullFace, true, false);
  395. #else
  396. #define BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
  397. #endif
  398. #undef BUILD_SURFACE_DESCRIPTION_INPUTS_OUTPUT_FACESIGN
  399. return output;
  400. }
  401. // --------------------------------------------------
  402. // Main
  403. #include "Packages/com.unity.render-pipelines.universal/Editor/ShaderGraph/Includes/Varyings.hlsl"
  404. #include "PBRForwardPass.hlsl"
  405. // --------------------------------------------------
  406. // Visual Effect Vertex Invocations
  407. #ifdef HAVE_VFX_MODIFICATION
  408. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/VisualEffectVertex.hlsl"
  409. #endif
  410. #endif
  411. ENDHLSL
  412. }
  413. }
  414. //CustomEditorForRenderPipeline "UnityEditor.ShaderGraphLitGUI" "UnityEngine.Rendering.Universal.UniversalRenderPipelineAsset"
  415. //CustomEditor "UnityEditor.ShaderGraph.GenericShaderGraphMaterialGUI"
  416. CustomEditor "FXV.fxvVolumeFogShaderInspector"
  417. FallBack "Hidden/Shader Graph/FallbackError"
  418. }