설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ShaderGraphFunctions.hlsl 5.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. #ifndef UNITY_GRAPHFUNCTIONS_LW_INCLUDED
  2. #define UNITY_GRAPHFUNCTIONS_LW_INCLUDED
  3. #define SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv) shadergraph_LWSampleSceneDepth(uv)
  4. #define SHADERGRAPH_SAMPLE_SCENE_COLOR(uv) shadergraph_LWSampleSceneColor(uv)
  5. #define SHADERGRAPH_SAMPLE_SCENE_NORMAL(uv) shadergraph_LWSampleSceneNormals(uv)
  6. #define SHADERGRAPH_BAKED_GI(positionWS, normalWS, positionSS, uvStaticLightmap, uvDynamicLightmap, applyScaling) shadergraph_LWBakedGI(positionWS, normalWS, positionSS, uvStaticLightmap, uvDynamicLightmap, applyScaling)
  7. #define SHADERGRAPH_REFLECTION_PROBE(viewDir, normalOS, lod) shadergraph_LWReflectionProbe(viewDir, normalOS, lod)
  8. #define SHADERGRAPH_FOG(position, color, density) shadergraph_LWFog(position, color, density)
  9. #define SHADERGRAPH_AMBIENT_SKY unity_AmbientSky
  10. #define SHADERGRAPH_AMBIENT_EQUATOR unity_AmbientEquator
  11. #define SHADERGRAPH_AMBIENT_GROUND unity_AmbientGround
  12. #define SHADERGRAPH_MAIN_LIGHT_DIRECTION shadergraph_URPMainLightDirection
  13. #define SHADERGRAPH_RENDERER_BOUNDS_MIN shadergraph_RendererBoundsWS_Min()
  14. #define SHADERGRAPH_RENDERER_BOUNDS_MAX shadergraph_RendererBoundsWS_Max()
  15. #if defined(REQUIRE_DEPTH_TEXTURE)
  16. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareDepthTexture.hlsl"
  17. #endif
  18. #if defined(REQUIRE_OPAQUE_TEXTURE)
  19. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareOpaqueTexture.hlsl"
  20. #endif
  21. #if defined(REQUIRE_NORMAL_TEXTURE)
  22. #include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/DeclareNormalsTexture.hlsl"
  23. #endif
  24. float shadergraph_LWSampleSceneDepth(float2 uv)
  25. {
  26. #if defined(REQUIRE_DEPTH_TEXTURE)
  27. return SampleSceneDepth(uv);
  28. #else
  29. return 0;
  30. #endif
  31. }
  32. float3 shadergraph_LWSampleSceneColor(float2 uv)
  33. {
  34. #if defined(REQUIRE_OPAQUE_TEXTURE)
  35. return SampleSceneColor(uv);
  36. #else
  37. return 0;
  38. #endif
  39. }
  40. float3 shadergraph_LWSampleSceneNormals(float2 uv)
  41. {
  42. #if defined(REQUIRE_NORMAL_TEXTURE)
  43. return SampleSceneNormals(uv);
  44. #else
  45. return 0;
  46. #endif
  47. }
  48. float3 shadergraph_LWBakedGI(float3 positionWS, float3 normalWS, uint2 positionSS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool applyScaling)
  49. {
  50. #ifdef LIGHTMAP_ON
  51. if (applyScaling)
  52. {
  53. uvStaticLightmap = uvStaticLightmap * unity_LightmapST.xy + unity_LightmapST.zw;
  54. uvDynamicLightmap = uvDynamicLightmap * unity_DynamicLightmapST.xy + unity_DynamicLightmapST.zw;
  55. }
  56. #if defined(DYNAMICLIGHTMAP_ON)
  57. return SampleLightmap(uvStaticLightmap, uvDynamicLightmap, normalWS);
  58. #else
  59. return SampleLightmap(uvStaticLightmap, normalWS);
  60. #endif
  61. #else
  62. #if (defined(PROBE_VOLUMES_L1) || defined(PROBE_VOLUMES_L2))
  63. if (_EnableProbeVolumes)
  64. {
  65. float3 bakeDiffuseLighting;
  66. EvaluateAdaptiveProbeVolume(positionWS, normalWS, GetWorldSpaceNormalizeViewDir(positionWS), positionSS, bakeDiffuseLighting);
  67. return bakeDiffuseLighting;
  68. }
  69. else
  70. return SampleSH(normalWS);
  71. #else
  72. return SampleSH(normalWS);
  73. #endif
  74. #endif
  75. }
  76. float3 shadergraph_LWReflectionProbe(float3 viewDir, float3 normalOS, float lod)
  77. {
  78. float3 reflectVec = reflect(-viewDir, normalOS);
  79. #if USE_FORWARD_PLUS
  80. return SAMPLE_TEXTURECUBE_LOD(_GlossyEnvironmentCubeMap, sampler_GlossyEnvironmentCubeMap, reflectVec, lod).rgb;
  81. #else
  82. return DecodeHDREnvironment(SAMPLE_TEXTURECUBE_LOD(unity_SpecCube0, samplerunity_SpecCube0, reflectVec, lod), unity_SpecCube0_HDR);
  83. #endif
  84. }
  85. void shadergraph_LWFog(float3 positionOS, out float4 color, out float density)
  86. {
  87. color = unity_FogColor;
  88. #if defined(FOG_LINEAR) || defined(FOG_EXP) || defined(FOG_EXP2)
  89. float viewZ = -TransformWorldToView(TransformObjectToWorld(positionOS)).z;
  90. float nearZ0ToFarZ = max(viewZ - _ProjectionParams.y, 0);
  91. // ComputeFogFactorZ0ToFar returns the fog "occlusion" (0 for full fog and 1 for no fog) so this has to be inverted for density.
  92. density = 1.0f - ComputeFogIntensity(ComputeFogFactorZ0ToFar(nearZ0ToFarZ));
  93. #else
  94. density = 0.0f;
  95. #endif
  96. }
  97. // This function assumes the bitangent flip is encoded in tangentWS.w
  98. float3x3 BuildTangentToWorld(float4 tangentWS, float3 normalWS)
  99. {
  100. // tangentWS must not be normalized (mikkts requirement)
  101. // Normalize normalWS vector but keep the renormFactor to apply it to bitangent and tangent
  102. float3 unnormalizedNormalWS = normalWS;
  103. float renormFactor = 1.0 / length(unnormalizedNormalWS);
  104. // bitangent on the fly option in xnormal to reduce vertex shader outputs.
  105. // this is the mikktspace transformation (must use unnormalized attributes)
  106. float3x3 tangentToWorld = CreateTangentToWorld(unnormalizedNormalWS, tangentWS.xyz, tangentWS.w > 0.0 ? 1.0 : -1.0);
  107. // surface gradient based formulation requires a unit length initial normal. We can maintain compliance with mikkts
  108. // by uniformly scaling all 3 vectors since normalization of the perturbed normal will cancel it.
  109. tangentToWorld[0] = tangentToWorld[0] * renormFactor;
  110. tangentToWorld[1] = tangentToWorld[1] * renormFactor;
  111. tangentToWorld[2] = tangentToWorld[2] * renormFactor; // normalizes the interpolated vertex normal
  112. return tangentToWorld;
  113. }
  114. float3 shadergraph_URPMainLightDirection()
  115. {
  116. return -GetMainLight().direction;
  117. }
  118. float3 shadergraph_RendererBoundsWS_Min()
  119. {
  120. return GetCameraRelativePositionWS(unity_RendererBounds_Min.xyz);
  121. }
  122. float3 shadergraph_RendererBoundsWS_Max()
  123. {
  124. return GetCameraRelativePositionWS(unity_RendererBounds_Max.xyz);
  125. }
  126. // Always include Shader Graph version
  127. // Always include last to avoid double macros
  128. #include "Packages/com.unity.shadergraph/ShaderGraphLibrary/Functions.hlsl"
  129. #endif // UNITY_GRAPHFUNCTIONS_LW_INCLUDED