fabric.effect 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  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: { parent: USE_ALPHA_TEST, 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: 1.0, 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: { parent: IS_ANISOTROPY, slide : true, range : [0.0, 1.0] , step : 0.0001 } }
  19. anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { parent: IS_ANISOTROPY, slide : true, range : [0, 1.0] , step : 0.0001 } }
  20. anisotropyMapResolutionHeight: { value: 0.0, target: anisotropyParam.w, editor: { parent: FIX_ANISOTROPIC_ROTATION_MAP } }
  21. addOnShadowBias: { value: 0.0, target: anisotropyParam.z }
  22. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  23. normalMap: { value: normal }
  24. pbrMap: { value: grey }
  25. occlusionMap: { value: white }
  26. anisotropyMap: { value: black, editor : { parent: IS_ANISOTROPY } }
  27. sheenColor: { value: [1.0, 1.0, 1.0, 1.0], linear: true, editor: { type: color } }
  28. sheenRoughness: { value: 1.0, target: emissiveScaleParam.x, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  29. sheenOpacity: { value: 1.0, target: emissiveScaleParam.y, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  30. sheenIntensity: { value: 1.0, target: emissiveScaleParam.w, editor: { slide: true, range: [1.0, 3.0], step: 0.001 } }
  31. sheenColorMap: { value: white, editor: { parent: USE_SHEEN_COLOR_MAP } }
  32. sheenDataMap: { value: white, editor: { parent: USE_SHEEN_DATA_MAP, tooltips: 'r: sheen roughness g: sheen opacity' } }
  33. - &forward-add
  34. vert: standard-vs
  35. frag: standard-fs
  36. phase: forward-add
  37. propertyIndex: 0
  38. embeddedMacros: { CC_FORWARD_ADD: true }
  39. depthStencilState:
  40. depthFunc: equal
  41. depthTest: true
  42. depthWrite: false
  43. blendState:
  44. targets:
  45. - blend: true
  46. blendSrc: one
  47. blendDst: one
  48. blendSrcAlpha: zero
  49. blendDstAlpha: one
  50. - &shadow-caster
  51. vert: shadow-caster-vs
  52. frag: shadow-caster-fs
  53. phase: shadow-caster
  54. propertyIndex: 0
  55. rasterizerState:
  56. cullMode: front
  57. properties:
  58. tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
  59. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
  60. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  61. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  62. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  63. - &reflect-map
  64. vert: standard-vs
  65. frag: reflect-map-fs
  66. phase: reflect-map
  67. propertyIndex: 0
  68. - &planar-shadow
  69. vert: planar-shadow-vs
  70. frag: planar-shadow-fs
  71. phase: planar-shadow
  72. propertyIndex: 0
  73. depthStencilState:
  74. depthTest: true
  75. depthWrite: false
  76. stencilTestFront: true
  77. stencilFuncFront: not_equal
  78. stencilPassOpFront: replace
  79. stencilRef: 0x80 # only use the leftmost bit
  80. stencilReadMask: 0x80
  81. stencilWriteMask: 0x80
  82. blendState:
  83. targets:
  84. - blend: true
  85. blendSrc: src_alpha
  86. blendDst: one_minus_src_alpha
  87. blendDstAlpha: one_minus_src_alpha
  88. - &deferred
  89. vert: standard-vs
  90. frag: standard-fs
  91. pass: gbuffer
  92. phase: gbuffer
  93. embeddedMacros: { CC_PIPELINE_TYPE: 1 }
  94. propertyIndex: 0
  95. - name: transparent
  96. passes:
  97. - vert: standard-vs
  98. frag: standard-fs
  99. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  100. depthStencilState: &d1
  101. depthTest: true
  102. depthWrite: false
  103. blendState: &b1
  104. targets:
  105. - blend: true
  106. blendSrc: src_alpha
  107. blendDst: one_minus_src_alpha
  108. blendDstAlpha: one_minus_src_alpha
  109. properties: *props
  110. - *forward-add
  111. - *shadow-caster
  112. - *planar-shadow
  113. - &deferred-forward
  114. vert: standard-vs
  115. frag: standard-fs
  116. phase: deferred-forward
  117. embeddedMacros: { CC_PIPELINE_TYPE: 0 }
  118. propertyIndex: 0
  119. depthStencilState: *d1
  120. blendState: *b1
  121. }%
  122. CCProgram shared-ubos %{
  123. uniform Constants {
  124. vec4 tilingOffset;
  125. vec4 albedo;
  126. vec4 albedoScaleAndCutoff;
  127. vec4 pbrParams;
  128. vec4 sheenColor;
  129. vec4 emissiveScaleParam;
  130. vec4 anisotropyParam;
  131. };
  132. }%
  133. CCProgram macro-remapping %{
  134. // ui displayed macros
  135. #pragma define-meta HAS_SECOND_UV
  136. #pragma define-meta USE_TWOSIDE
  137. #pragma define-meta IS_ANISOTROPY
  138. #pragma define-meta USE_VERTEX_COLOR
  139. #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
  140. #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
  141. #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY
  142. #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
  143. #define CC_SURFACES_LIGHTING_SHEEN 1
  144. // sheen need tangent
  145. #define CC_SURFACES_USE_TANGENT_SPACE 1
  146. // functionality for each effect
  147. #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31
  148. }%
  149. CCProgram surface-vertex %{
  150. #define CC_SURFACES_VERTEX_MODIFY_SHADOW_BIAS
  151. vec2 SurfacesVertexModifyShadowBias(in SurfacesStandardVertexIntermediate In, vec2 originShadowBias)
  152. {
  153. return originShadowBias + vec2(anisotropyParam.z, 0.0);
  154. }
  155. #define CC_SURFACES_VERTEX_MODIFY_UV
  156. void SurfacesVertexModifyUV(inout SurfacesStandardVertexIntermediate In)
  157. {
  158. In.texCoord = In.texCoord * tilingOffset.xy + tilingOffset.zw;
  159. #if CC_SURFACES_USE_SECOND_UV
  160. In.texCoord1 = In.texCoord1 * tilingOffset.xy + tilingOffset.zw;
  161. #endif
  162. }
  163. }%
  164. CCProgram surface-fragment %{
  165. #if USE_ALBEDO_MAP
  166. uniform sampler2D albedoMap;
  167. #pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
  168. #endif
  169. #if USE_NORMAL_MAP
  170. uniform sampler2D normalMap;
  171. #pragma define-meta NORMAL_UV options([v_uv, v_uv1])
  172. #endif
  173. #pragma define-meta DEFAULT_UV options([v_uv, v_uv1])
  174. #if USE_PBR_MAP
  175. uniform sampler2D pbrMap;
  176. #endif
  177. #if USE_OCCLUSION_MAP
  178. uniform sampler2D occlusionMap;
  179. #endif
  180. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  181. uniform sampler2D anisotropyMap;
  182. #endif
  183. #if USE_SHEEN_COLOR_MAP
  184. uniform sampler2D sheenColorMap;
  185. #endif
  186. #if USE_SHEEN_DATA_MAP
  187. uniform sampler2D sheenDataMap;
  188. #endif
  189. #pragma define OCCLUSION_CHANNEL r
  190. #pragma define ROUGHNESS_CHANNEL g
  191. #pragma define METALLIC_CHANNEL b
  192. #pragma define SPECULAR_INTENSITY_CHANNEL a
  193. #if USE_ALPHA_TEST
  194. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
  195. #endif
  196. #define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
  197. vec4 SurfacesFragmentModifyAnisotropyParams(out float isRotation)
  198. {
  199. float anisotropyRotation = anisotropyParam.y * PI;
  200. float anisotropyShape = anisotropyParam.x;
  201. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  202. // Rotation angle should disable trilinear filtering
  203. vec4 tex = texture(anisotropyMap, DEFAULT_UV);
  204. anisotropyRotation = fract(anisotropyRotation * 0.5 + tex.y) * PI2;
  205. // less value is better for SP exported shape
  206. anisotropyShape *= tex.x;
  207. #endif
  208. isRotation = 1.0;
  209. return vec4(anisotropyShape, anisotropyRotation, 0.0, 0.0);
  210. }
  211. #define CC_SURFACES_FRAGMENT_MODIFY_SHEEN_PARAMS
  212. vec4 SurfacesFragmentModifySheenParams()
  213. {
  214. vec4 param = emissiveScaleParam;
  215. #if USE_SHEEN_DATA_MAP
  216. param.xy *= texture(sheenDataMap, FSInput_texcoord).xy;
  217. #endif
  218. return param;
  219. }
  220. #define CC_SURFACES_FRAGMENT_MODIFY_SHEEN_COLOR
  221. vec3 SurfacesFragmentModifySheenColor()
  222. {
  223. #if USE_SHEEN_COLOR_MAP
  224. return sheenColor.rgb * texture(sheenColorMap, FSInput_texcoord).rgb;
  225. #else
  226. return sheenColor.rgb;
  227. #endif
  228. }
  229. #include <common-functions>
  230. }%
  231. CCProgram standard-vs %{
  232. precision highp float;
  233. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  234. #include <macro-remapping>
  235. #include <surfaces/effect-macros/common-macros>
  236. // 2. common include with corresponding shader stage, include before surface functions
  237. #include <surfaces/includes/common-vs>
  238. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  239. // see surfaces/default-functions/xxx.chunk
  240. #include <shared-ubos>
  241. #include <surface-vertex>
  242. // 4. surface include with corresponding shader stage and shading-model (optional)
  243. #include <surfaces/includes/standard-vs>
  244. // 5. shader entry with corresponding shader stage and technique usage/type
  245. #include <shading-entries/main-functions/render-to-scene/vs>
  246. }%
  247. CCProgram shadow-caster-vs %{
  248. precision highp float;
  249. #include <macro-remapping>
  250. #include <surfaces/effect-macros/render-to-shadowmap>
  251. #include <surfaces/includes/common-vs>
  252. #include <shared-ubos>
  253. #include <surface-vertex>
  254. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  255. }%
  256. CCProgram planar-shadow-vs %{
  257. precision highp float;
  258. #include <macro-remapping>
  259. #include <surfaces/effect-macros/render-planar-shadow>
  260. #include <surfaces/includes/common-vs>
  261. #include <shared-ubos>
  262. #include <surface-vertex>
  263. #include <shading-entries/main-functions/render-planar-shadow/vs>
  264. }%
  265. CCProgram standard-fs %{
  266. // shading-model : standard
  267. // lighting-model : standard (isotropy / anisotropy pbr)
  268. // shader stage : fs
  269. // technique usage/type : render-to-scene
  270. precision highp float;
  271. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  272. #include <macro-remapping>
  273. #include <surfaces/effect-macros/common-macros>
  274. // 2. common include with corresponding shader stage, include before surface functions
  275. #include <surfaces/includes/common-fs>
  276. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  277. // see surfaces/default-functions/xxx.chunk
  278. #include <shared-ubos>
  279. #include <surface-fragment>
  280. // 4. lighting-model (optional)
  281. #include <lighting-models/includes/standard>
  282. // 5. surface include with corresponding shader stage and shading-model (optional)
  283. #include <surfaces/includes/standard-fs>
  284. // 6. shader entry with corresponding shader stage and technique usage/type
  285. #include <shading-entries/main-functions/render-to-scene/fs>
  286. }%
  287. CCProgram shadow-caster-fs %{
  288. precision highp float;
  289. #include <macro-remapping>
  290. #include <surfaces/effect-macros/render-to-shadowmap>
  291. #include <surfaces/includes/common-fs>
  292. #include <shared-ubos>
  293. #include <surface-fragment>
  294. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  295. }%
  296. CCProgram planar-shadow-fs %{
  297. precision highp float;
  298. #include <macro-remapping>
  299. #include <surfaces/effect-macros/render-planar-shadow>
  300. #include <surfaces/includes/common-fs>
  301. #include <shared-ubos>
  302. #include <surface-fragment>
  303. #include <shading-entries/main-functions/render-planar-shadow/fs>
  304. }%
  305. CCProgram reflect-map-fs %{
  306. precision highp float;
  307. #include <macro-remapping>
  308. #include <surfaces/effect-macros/common-macros>
  309. #include <surfaces/includes/common-fs>
  310. #include <shared-ubos>
  311. #include <surface-fragment>
  312. #include <lighting-models/includes/standard>
  313. #include <surfaces/includes/standard-fs>
  314. #include <shading-entries/main-functions/render-to-reflectmap/fs>
  315. }%