hair.effect 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505
  1. // Copyright (c) 2017-2022 Xiamen Yaji Software Co., Ltd.
  2. CCEffect %{
  3. techniques:
  4. - name: opaque
  5. passes:
  6. - vert: standard-vs
  7. frag: standard-fs
  8. properties: &props
  9. tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
  10. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } }
  11. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  12. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  13. occlusion: { value: 0.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  14. roughness: { value: 0.5, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  15. metallic: { value: 0.0, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  16. specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  17. normalStrength: { value: 0.4, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
  18. anisotropyIntensity: { value: 1.0, target: anisotropyParam.x, editor: { slide : true, range : [0.0, 1.0] , step : 0.0001 } }
  19. anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { slide : true, range : [0, 1.0] , step : 0.0001 } }
  20. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  21. transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: TransparencyMap } }
  22. normalMap: { value: normal }
  23. pbrMap: { value: grey }
  24. occlusionMap: { value: white }
  25. anisotropyMap: { value: black }
  26. roughnessTRT: { value: 0.2, target: trtParams.x, editor: { displayName: TRT Roughness Offset, slide: true, range: [0, 1.0], step: 0.001, tooltip: 'The extend range of internal reflection lighting around the direct specular' } }
  27. offsetTRT: { value: 0.0, target: trtParams.y, editor: { displayName: TRT Lighting Offset, slide: true, range: [-0.5, 0.5], step: 0.001, tooltip: 'The position offset of internal reflection lighting compared to direct specular' } }
  28. IntensityTRT: { value: 2.0, target: trtParams.w, editor: { displayName: TRT Intensity, slide: true, range: [0, 10.0], step: 0.01 } }
  29. baseColorTRT: { value: [0.5, 0.33, 0.18, 1.0], target: trtColor, linear: true, editor: { displayName: TRT Albedo, type: color, tooltip: 'The color of internal reflection lighting' } }
  30. ScatterCoefTT: { value: 0.0, target: ttParams.x, editor: { displayName: TT Scatter Coef, slide: true, range: [0, 1.0], step: 0.01, tooltip: 'The saturation of internal transmit lighting color' } }
  31. IntensityTT: { value: 1.0, target: ttParams.w, editor: { displayName: TT Intensity, slide: true, range: [0, 1.0], step: 0.01 } }
  32. baseColorTT: { value: [0.5, 0.33, 0.18, 1.0], target: ttColor, linear: true, editor: { displayName: TT Albedo, type: color, tooltip: 'The color of internal transmit lighting, allow the light color to vary between backlit and light-facing areas' } }
  33. thickness: { value: 1.0, target: ttParams.y, editor: { parent: USE_BACK_LIT, displayName: Scatter Thickness, slide: true, range: [0, 1.0], step: 0.001, tooltip: 'The extend range of internal reflection lighting around the direct specular' } }
  34. extinction: { value: 0.0, target: ttParams.z, editor: { parent: USE_BACK_LIT, displayName: Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001, tooltip: 'The position offset of internal reflection lighting compared to direct specular' } }
  35. transmitColor: { value: [0.7, 0.5, 0.3, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting' } }
  36. thicknessMap: { value: white, editor: { parent: USE_BACK_LIT } }
  37. selfShadowMap: { value: white, editor: { parent: USE_SELF_SHADOW_MAP } }
  38. rasterizerState:
  39. cullMode: None
  40. depthStencilState:
  41. depthFunc: less_equal
  42. depthTest: true
  43. depthWrite: true
  44. - switch: USE_TRANSPARENCY_PASS_BACK
  45. vert: standard-vs
  46. frag: standard-fs
  47. properties: *props
  48. rasterizerState:
  49. cullMode: Front
  50. depthStencilState:
  51. depthFunc: less
  52. depthTest: true
  53. depthWrite: false
  54. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true, INVERSE_ALPHA_TEST: true }
  55. blendState:
  56. targets:
  57. - blend: true
  58. blendSrc: src_alpha
  59. blendDst: one_minus_src_alpha
  60. blendSrcAlpha: one
  61. blendDstAlpha: one_minus_src_alpha
  62. - switch: USE_TRANSPARENCY_PASS_FRONT
  63. vert: standard-vs
  64. frag: standard-fs
  65. properties: *props
  66. rasterizerState:
  67. cullMode: Back
  68. depthStencilState:
  69. depthFunc: less
  70. depthTest: true
  71. depthWrite: false
  72. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true, INVERSE_ALPHA_TEST: true }
  73. blendState:
  74. targets:
  75. - blend: true
  76. blendSrc: src_alpha
  77. blendDst: one_minus_src_alpha
  78. blendSrcAlpha: one
  79. blendDstAlpha: one_minus_src_alpha
  80. - &forward-add
  81. vert: standard-vs
  82. frag: standard-fs
  83. phase: forward-add
  84. propertyIndex: 0
  85. embeddedMacros: { CC_FORWARD_ADD: true }
  86. depthStencilState:
  87. depthFunc: equal
  88. depthTest: true
  89. depthWrite: false
  90. blendState:
  91. targets:
  92. - blend: true
  93. blendSrc: one
  94. blendDst: one
  95. blendSrcAlpha: zero
  96. blendDstAlpha: one
  97. - switch: USE_TRANSPARENCY_PASS_BACK
  98. vert: standard-vs
  99. frag: standard-fs
  100. propertyIndex: 0
  101. rasterizerState:
  102. cullMode: Front
  103. depthStencilState:
  104. depthFunc: less
  105. depthTest: true
  106. depthWrite: false
  107. embeddedMacros: { CC_FORWARD_ADD: true, INVERSE_ALPHA_TEST: true }
  108. blendState:
  109. targets:
  110. - blend: true
  111. blendSrc: src_alpha
  112. blendDst: one
  113. blendSrcAlpha: zero
  114. blendDstAlpha: one
  115. - switch: USE_TRANSPARENCY_PASS_FRONT
  116. vert: standard-vs
  117. frag: standard-fs
  118. propertyIndex: 0
  119. rasterizerState:
  120. cullMode: Back
  121. depthStencilState:
  122. depthFunc: less
  123. depthTest: true
  124. depthWrite: false
  125. embeddedMacros: { CC_FORWARD_ADD: true, INVERSE_ALPHA_TEST: true }
  126. blendState:
  127. targets:
  128. - blend: true
  129. blendSrc: src_alpha
  130. blendDst: one
  131. blendSrcAlpha: zero
  132. blendDstAlpha: one
  133. - &shadow-caster
  134. vert: shadow-caster-vs
  135. frag: shadow-caster-fs
  136. phase: shadow-caster
  137. propertyIndex: 0
  138. rasterizerState:
  139. cullMode: front
  140. properties:
  141. tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
  142. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
  143. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  144. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  145. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  146. transparencyMap: { value: white, editor: { parent: USE_TRANSPRENCY_MAP, displayName: TransparencyMap } }
  147. - &reflect-map
  148. vert: standard-vs
  149. frag: reflect-map-fs
  150. phase: reflect-map
  151. propertyIndex: 0
  152. - name: transparent
  153. passes:
  154. - vert: standard-vs
  155. frag: standard-fs
  156. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  157. depthStencilState:
  158. depthTest: true
  159. depthWrite: false
  160. blendState:
  161. targets:
  162. - blend: true
  163. blendSrc: src_alpha
  164. blendDst: one_minus_src_alpha
  165. blendDstAlpha: one_minus_src_alpha
  166. properties: *props
  167. - *forward-add
  168. - *shadow-caster
  169. }%
  170. CCProgram shared-ubos %{
  171. uniform Constants {
  172. vec4 tilingOffset;
  173. vec4 albedo;
  174. vec4 albedoScaleAndCutoff;
  175. vec4 pbrParams;
  176. vec4 emissiveScaleParam;
  177. vec4 anisotropyParam;
  178. vec4 trtColor;
  179. vec4 trtParams;
  180. vec4 ttColor;
  181. vec4 ttParams;
  182. vec4 transmitColor;
  183. };
  184. }%
  185. CCProgram macro-remapping %{
  186. // ui displayed macros
  187. #pragma define-meta HAS_SECOND_UV
  188. #pragma define-meta USE_TWOSIDE
  189. #pragma define IS_ANISOTROPY 1
  190. #pragma define-meta USE_VERTEX_COLOR
  191. #pragma define-meta USE_DITHERED_ALPHA_TEST
  192. #pragma define-meta USE_BACK_LIT
  193. #pragma define-meta USE_HIGH_QUALITY_REFLECTION
  194. #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
  195. #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
  196. #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY
  197. #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
  198. #define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT
  199. #define CC_SURFACES_LIGHTING_TRT 1
  200. #define CC_SURFACES_LIGHTING_TT 1
  201. #define CC_SURFACES_TRANSFER_CLIP_POS 1
  202. // depend on UI macros
  203. #if IS_ANISOTROPY || USE_NORMAL_MAP
  204. #define CC_SURFACES_USE_TANGENT_SPACE 1
  205. #endif
  206. // functionality for each effect
  207. #if USE_HIGH_QUALITY_REFLECTION
  208. #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 9
  209. #endif
  210. }%
  211. CCProgram surface-vertex %{
  212. }%
  213. CCProgram surface-fragment %{
  214. #if USE_ALBEDO_MAP
  215. uniform sampler2D albedoMap;
  216. #pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
  217. #endif
  218. #if USE_NORMAL_MAP
  219. uniform sampler2D normalMap;
  220. #pragma define-meta NORMAL_UV options([v_uv, v_uv1])
  221. #endif
  222. #pragma define-meta DEFAULT_UV options([v_uv, v_uv1])
  223. #if USE_PBR_MAP
  224. uniform sampler2D pbrMap;
  225. #endif
  226. #if USE_OCCLUSION_MAP
  227. uniform sampler2D occlusionMap;
  228. #endif
  229. #pragma define OCCLUSION_CHANNEL r
  230. #pragma define ROUGHNESS_CHANNEL g
  231. #pragma define METALLIC_CHANNEL b
  232. #pragma define SPECULAR_INTENSITY_CHANNEL a
  233. #if USE_ALPHA_TEST
  234. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
  235. #endif
  236. //////////////////User Defines
  237. #include <common/effect/special-effects>
  238. #if USE_TRANSPRENCY_MAP
  239. uniform sampler2D transparencyMap;
  240. #endif
  241. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  242. uniform sampler2D anisotropyMap;
  243. #endif
  244. #if USE_BACK_LIT && USE_THICKNESS_MAP
  245. uniform sampler2D thicknessMap;
  246. #endif
  247. #if USE_SELF_SHADOW_MAP
  248. uniform sampler2D selfShadowMap;
  249. #endif
  250. #define CC_SURFACES_FRAGMENT_MODIFY_TRT_PARAMS
  251. vec4 SurfacesFragmentModifyTRTParams()
  252. {
  253. return trtParams;
  254. }
  255. #define CC_SURFACES_FRAGMENT_MODIFY_TRT_COLOR
  256. vec3 SurfacesFragmentModifyTRTColor()
  257. {
  258. return trtColor.rgb;
  259. }
  260. #define CC_SURFACES_FRAGMENT_MODIFY_TT_PARAMS
  261. vec4 SurfacesFragmentModifyTTParams()
  262. {
  263. return ttParams;
  264. }
  265. #define CC_SURFACES_FRAGMENT_MODIFY_TT_COLOR
  266. vec3 SurfacesFragmentModifyTTColor(in vec3 baseColor)
  267. {
  268. return mix(baseColor.rgb, ttColor.rgb, ttColor.a); //ttColor can be (0.992, 0.808, 0.516)
  269. }
  270. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS
  271. vec4 SurfacesFragmentModifyTransmitScatteringParams()
  272. {
  273. float depth = SURFACES_MAX_TRANSMIT_DEPTH_VALUE;
  274. depth = ttParams.y;
  275. #if USE_BACK_LIT && USE_THICKNESS_MAP
  276. // depth = texture(thicknessMap, FSInput_texcoord).x;
  277. // depth = pow(depth, 1.0);
  278. // depth = 1.0 - depth;
  279. // depth *= ttParams.y;
  280. #endif
  281. return vec4(ttParams.z, 0.0, 0.0, depth);
  282. }
  283. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_DIFFUSE_PARAMS
  284. vec4 SurfacesFragmentModifyTransmitDiffuseParams()
  285. {
  286. float mask = 1.0;
  287. #if USE_BACK_LIT && USE_THICKNESS_MAP
  288. mask = texture(thicknessMap, FSInput_texcoord).x;
  289. mask = pow(mask, 1.0);
  290. mask = 1.0 - mask;
  291. mask *= 10.0;
  292. // depth *= ttParams.y;
  293. #endif
  294. return vec4(1.0, mask, 0.0, 1.0);
  295. }
  296. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR
  297. vec3 SurfacesFragmentModifyTransmitInScatteringColor()
  298. {
  299. return vec3(0.0);
  300. }
  301. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
  302. vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
  303. {
  304. return transmitColor.rgb;
  305. }
  306. #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
  307. vec4 SurfacesFragmentModifyBaseColorAndTransparency()
  308. {
  309. vec4 baseColor = albedo;
  310. #if USE_VERTEX_COLOR
  311. baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear
  312. baseColor.a *= FSInput_vertexColor.a;
  313. #endif
  314. #if USE_ALBEDO_MAP
  315. vec4 texColor = texture(albedoMap, ALBEDO_UV);
  316. texColor.rgb = SRGBToLinear(texColor.rgb);
  317. baseColor *= texColor;
  318. #endif
  319. #if USE_TRANSPRENCY_MAP
  320. baseColor.a = texture(transparencyMap, ALBEDO_UV).x;
  321. #endif
  322. #if USE_DITHERED_ALPHA_TEST
  323. #if CC_SURFACES_TRANSFER_CLIP_POS
  324. DitheredAlphaClip(FSInput_clipPos, cc_viewPort.zw, baseColor.ALPHA_TEST_CHANNEL + (1.0 - albedoScaleAndCutoff.w));
  325. #endif
  326. #endif
  327. #if USE_ALPHA_TEST
  328. #if INVERSE_ALPHA_TEST
  329. if (baseColor.ALPHA_TEST_CHANNEL >= albedoScaleAndCutoff.w) discard;
  330. #else
  331. if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
  332. #endif
  333. #endif
  334. baseColor.rgb *= albedoScaleAndCutoff.xyz;
  335. return baseColor;
  336. }
  337. #define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
  338. void SurfacesFragmentAlphaClipOnly()
  339. {
  340. #if USE_ALPHA_TEST
  341. float alpha = albedo.ALPHA_TEST_CHANNEL;
  342. #if USE_VERTEX_COLOR
  343. alpha *= FSInput_vertexColor.a;
  344. #endif
  345. #if USE_ALBEDO_MAP
  346. alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL;
  347. #endif
  348. #if USE_TRANSPRENCY_MAP
  349. alpha = texture(transparencyMap, ALBEDO_UV).x;
  350. #endif
  351. if (alpha < albedoScaleAndCutoff.w) discard;
  352. #endif
  353. }
  354. #define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
  355. vec4 SurfacesFragmentModifyAnisotropyParams(out float isRotation)
  356. {
  357. float anisotropyRotation = anisotropyParam.y * PI;
  358. float anisotropyShape = anisotropyParam.x;
  359. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  360. // Rotation angle should disable trilinear filtering
  361. vec4 tex = texture(anisotropyMap, DEFAULT_UV);
  362. anisotropyRotation = fract(anisotropyRotation * 0.5 + tex.y) * PI2;
  363. // less value is better for SP exported shape
  364. anisotropyShape *= tex.x;
  365. #endif
  366. isRotation = 1.0;
  367. return vec4(anisotropyShape, anisotropyRotation, 0.0, 0.0);
  368. }
  369. #include <common-functions>
  370. // definition of SurfacesMaterialData structure with corresponding shading-model
  371. #include <surfaces/data-structures/standard>
  372. // see <lighting-models/default-functions/XXXX> for more overrided functions, XXXX is lighting-model name
  373. #include <lighting-models/includes/common>
  374. #define CC_SURFACES_LIGHTING_MODIFY_FINAL_RESULT
  375. void SurfacesLightingModifyFinalResult(inout LightingResult result, in LightingIntermediateData lightingData, in SurfacesMaterialData surfaceData, in LightingMiscData miscData)
  376. {
  377. #if USE_SELF_SHADOW_MAP
  378. result.shadow *= texture(selfShadowMap, DEFAULT_UV).x;
  379. #endif
  380. }
  381. }%
  382. CCProgram standard-vs %{
  383. precision highp float;
  384. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  385. #include <macro-remapping>
  386. #include <surfaces/effect-macros/common-macros>
  387. // 2. common include with corresponding shader stage, include before surface functions
  388. #include <surfaces/includes/common-vs>
  389. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  390. // see surfaces/default-functions/xxx.chunk
  391. #include <shared-ubos>
  392. #include <surface-vertex>
  393. // 4. surface include with corresponding shader stage and shading-model (optional)
  394. #include <surfaces/includes/standard-vs>
  395. // 5. shader entry with corresponding shader stage and technique usage/type
  396. #include <shading-entries/main-functions/render-to-scene/vs>
  397. }%
  398. CCProgram shadow-caster-vs %{
  399. precision highp float;
  400. #include <macro-remapping>
  401. #include <surfaces/effect-macros/render-to-shadowmap>
  402. #include <surfaces/includes/common-vs>
  403. #include <shared-ubos>
  404. #include <surface-vertex>
  405. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  406. }%
  407. CCProgram standard-fs %{
  408. // shading-model : standard
  409. // lighting-model : standard (isotropy / anisotropy pbr)
  410. // shader stage : fs
  411. // technique usage/type : render-to-scene
  412. precision highp float;
  413. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  414. #include <macro-remapping>
  415. #include <surfaces/effect-macros/common-macros>
  416. // 2. common include with corresponding shader stage, include before surface functions
  417. #include <surfaces/includes/common-fs>
  418. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  419. // see surfaces/default-functions/xxx.chunk
  420. #include <shared-ubos>
  421. #include <surface-fragment>
  422. // 4. lighting-model (optional)
  423. #include <lighting-models/includes/standard>
  424. // 5. surface include with corresponding shader stage and shading-model (optional)
  425. #include <surfaces/includes/standard-fs>
  426. // 6. shader entry with corresponding shader stage and technique usage/type
  427. #include <shading-entries/main-functions/render-to-scene/fs>
  428. }%
  429. CCProgram shadow-caster-fs %{
  430. precision highp float;
  431. #include <macro-remapping>
  432. #include <surfaces/effect-macros/render-to-shadowmap>
  433. #include <surfaces/includes/common-fs>
  434. #include <shared-ubos>
  435. #include <surface-fragment>
  436. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  437. }%
  438. CCProgram reflect-map-fs %{
  439. precision highp float;
  440. #include <macro-remapping>
  441. #include <surfaces/effect-macros/common-macros>
  442. #include <surfaces/includes/common-fs>
  443. #include <shared-ubos>
  444. #include <surface-fragment>
  445. #include <lighting-models/includes/standard>
  446. #include <surfaces/includes/standard-fs>
  447. #include <shading-entries/main-functions/render-to-reflectmap/fs>
  448. }%