暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

Functions.hlsl 4.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. // UNITY_SHADER_NO_UPGRADE
  2. #ifndef UNITY_GRAPHFUNCTIONS_INCLUDED
  3. #define UNITY_GRAPHFUNCTIONS_INCLUDED
  4. // ----------------------------------------------------------------------------
  5. // Included in generated graph shaders
  6. // ----------------------------------------------------------------------------
  7. #ifndef BUILTIN_TARGET_API
  8. bool IsGammaSpace()
  9. {
  10. #ifdef UNITY_COLORSPACE_GAMMA
  11. return true;
  12. #else
  13. return false;
  14. #endif
  15. }
  16. #endif
  17. float4 ComputeScreenPos (float4 pos, float projectionSign)
  18. {
  19. float4 o = pos * 0.5f;
  20. o.xy = float2(o.x, o.y * projectionSign) + o.w;
  21. o.zw = pos.zw;
  22. return o;
  23. }
  24. struct Gradient
  25. {
  26. int type;
  27. int colorsLength;
  28. int alphasLength;
  29. float4 colors[8];
  30. float2 alphas[8];
  31. };
  32. Gradient NewGradient(int type, int colorsLength, int alphasLength,
  33. float4 colors0, float4 colors1, float4 colors2, float4 colors3, float4 colors4, float4 colors5, float4 colors6, float4 colors7,
  34. float2 alphas0, float2 alphas1, float2 alphas2, float2 alphas3, float2 alphas4, float2 alphas5, float2 alphas6, float2 alphas7)
  35. {
  36. Gradient output =
  37. {
  38. type, colorsLength, alphasLength,
  39. {colors0, colors1, colors2, colors3, colors4, colors5, colors6, colors7},
  40. {alphas0, alphas1, alphas2, alphas3, alphas4, alphas5, alphas6, alphas7}
  41. };
  42. return output;
  43. }
  44. // https://bottosson.github.io/posts/oklab/ for perceptual blend mode in gradients
  45. float3 LinearToOklab(float3 rgb)
  46. {
  47. float l = 0.4122214708f * rgb.r + 0.5363325363f * rgb.g + 0.0514459929f * rgb.b;
  48. float m = 0.2119034982f * rgb.r + 0.6806995451f * rgb.g + 0.1073969566f * rgb.b;
  49. float s = 0.0883024619f * rgb.r + 0.2817188376f * rgb.g + 0.6299787005f * rgb.b;
  50. float l_ = pow(l, 0.333333f);
  51. float m_ = pow(m, 0.333333f);
  52. float s_ = pow(s, 0.333333f);
  53. return float3(
  54. 0.2104542553f * l_ + 0.7936177850f * m_ - 0.0040720468f * s_,
  55. 1.9779984951f * l_ - 2.4285922050f * m_ + 0.4505937099f * s_,
  56. 0.0259040371f * l_ + 0.7827717662f * m_ - 0.8086757660f * s_);
  57. }
  58. float3 OklabToLinear(float3 lab)
  59. {
  60. float l_ = lab.r + 0.3963377774f * lab.g + 0.2158037573f * lab.b;
  61. float m_ = lab.r - 0.1055613458f * lab.g - 0.0638541728f * lab.b;
  62. float s_ = lab.r - 0.0894841775f * lab.g - 1.2914855480f * lab.b;
  63. float l = l_ * l_ * l_;
  64. float m = m_ * m_ * m_;
  65. float s = s_ * s_ * s_;
  66. return float3(
  67. 4.0767416621f * l - 3.3077115913f * m + 0.2309699292f * s,
  68. -1.2684380046f * l + 2.6097574011f * m - 0.3413193965f * s,
  69. -0.0041960863f * l - 0.7034186147f * m + 1.7076147010f * s);
  70. }
  71. #ifndef SHADERGRAPH_SAMPLE_SCENE_DEPTH
  72. #define SHADERGRAPH_SAMPLE_SCENE_DEPTH(uv) shadergraph_SampleSceneDepth(uv)
  73. #endif
  74. #ifndef SHADERGRAPH_SAMPLE_SCENE_COLOR
  75. #define SHADERGRAPH_SAMPLE_SCENE_COLOR(uv) shadergraph_SampleSceneColor(uv)
  76. #endif
  77. #ifndef SHADERGRAPH_SAMPLE_SCENE_NORMAL
  78. #define SHADERGRAPH_SAMPLE_SCENE_NORMAL(uv) shadergraph_SampleSceneNormal(uv)
  79. #endif
  80. #ifndef SHADERGRAPH_BAKED_GI
  81. #define SHADERGRAPH_BAKED_GI(positionWS, normalWS, positionSS, uvStaticLightmap, uvDynamicLightmap, applyScaling) shadergraph_BakedGI(positionWS, normalWS, positionSS, uvStaticLightmap, uvDynamicLightmap, applyScaling)
  82. #endif
  83. #ifndef SHADERGRAPH_REFLECTION_PROBE
  84. #define SHADERGRAPH_REFLECTION_PROBE(viewDir, normalOS, lod) shadergraph_ReflectionProbe(viewDir, normalOS, lod)
  85. #endif
  86. #ifndef SHADERGRAPH_FOG
  87. #define SHADERGRAPH_FOG(position, color, density) shadergraph_Fog(position, color, density)
  88. #endif
  89. #ifndef SHADERGRAPH_AMBIENT_SKY
  90. #define SHADERGRAPH_AMBIENT_SKY float3(0,0,0)
  91. #endif
  92. #ifndef SHADERGRAPH_AMBIENT_EQUATOR
  93. #define SHADERGRAPH_AMBIENT_EQUATOR float3(0,0,0)
  94. #endif
  95. #ifndef SHADERGRAPH_AMBIENT_GROUND
  96. #define SHADERGRAPH_AMBIENT_GROUND float3(0,0,0)
  97. #endif
  98. #ifndef SHADERGRAPH_OBJECT_POSITION
  99. #define SHADERGRAPH_OBJECT_POSITION GetAbsolutePositionWS(UNITY_MATRIX_M._m03_m13_m23)
  100. #endif
  101. #ifndef SHADERGRAPH_RENDERER_BOUNDS_MIN
  102. #define SHADERGRAPH_RENDERER_BOUNDS_MIN float3(0, 0, 0)
  103. #endif
  104. #ifndef SHADERGRAPH_RENDERER_BOUNDS_MAX
  105. #define SHADERGRAPH_RENDERER_BOUNDS_MAX float3(0, 0, 0)
  106. #endif
  107. float shadergraph_SampleSceneDepth(float2 uv)
  108. {
  109. return 1;
  110. }
  111. float3 shadergraph_SampleSceneColor(float2 uv)
  112. {
  113. return 0;
  114. }
  115. float3 shadergraph_SampleSceneNormal(float2 uv)
  116. {
  117. return 0;
  118. }
  119. float3 shadergraph_BakedGI(float3 positionWS, float3 normalWS, uint2 positionSS, float2 uvStaticLightmap, float2 uvDynamicLightmap, bool applyScaling)
  120. {
  121. return 0;
  122. }
  123. float3 shadergraph_ReflectionProbe(float3 viewDir, float3 normalOS, float lod)
  124. {
  125. return 0;
  126. }
  127. void shadergraph_Fog(float3 position, out float4 color, out float density)
  128. {
  129. color = 0;
  130. density = 0;
  131. }
  132. #endif // UNITY_GRAPHFUNCTIONS_INCLUDED