simple-skin.effect 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  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. specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  16. normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
  17. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  18. normalMap: { value: normal }
  19. pbrMap: { value: grey, editor: { displayName: PbrOrRoughnessMap } }
  20. occlusionMap: { value: white }
  21. sssIntensity: { value: 1.0, target: scatterParams.z, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 1.0], step: 0.001 } }
  22. preIntegratedSkinMap: { value: grey, editor: { parent: USE_PREINTEGRATED_SKIN } }
  23. sssCurvatureMap: { value: white, editor: { parent: USE_PREINTEGRATED_SKIN } }
  24. sssCurvature: { value: 0.1, target: scatterParams.w, editor: { parent: USE_PREINTEGRATED_SKIN, slide: true, range: [0, 1.0], step: 0.001 } }
  25. sssColoration: { value: 1.0, target: dualLobeParams.z, editor: { parent: USE_PREINTEGRATED_SKIN, slide: true, range: [0, 10.0], step: 0.001 } }
  26. cavityMap: { value: white, editor: { tooltip: 'cavity map or specular map' } }
  27. maskMap: { value: black, editor: { parent: USE_BACK_LIT } }
  28. thickness: { value: 0.0, target: scatterParams.x, editor: { parent: USE_BACK_LIT, displayName: Object Thickness, range: [0, 1000.0], tooltip: 'i18n:ENGINE.assets.effect.propertyTips.transmitThicknessWithShadowMap' } }
  29. extinction: { value: 0.0, target: scatterParams.y, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Extinction, slide: true, range: [0, 10.0], step: 0.001, tooltip: 'i18n:ENGINE.assets.effect.propertyTips.transmitExtinctionWithShadowMap' } }
  30. transmitColor: { value: [1.0, 0.2, 0.1, 1.0], linear: true, editor: { parent: USE_BACK_LIT, displayName: Transmit Scatter Color, type: color, tooltip: 'The color of scattered lighting, red for human skin' } }
  31. dualLobeRoughness: { value: 0.5, target: dualLobeParams.x, editor: { parent: USE_DUAL_LOBE_SPECULAR, range: [0, 1.0] } }
  32. dualLobeIntensity: { value: 0.02, target: dualLobeParams.w, editor: { parent: USE_DUAL_LOBE_SPECULAR, slide: true, range: [0, 0.1], step: 0.001 } }
  33. rasterizerState: &r1
  34. cullMode: None
  35. depthStencilState: &d1
  36. depthFunc: less_equal
  37. depthTest: true
  38. depthWrite: true
  39. - &forward-add
  40. vert: standard-vs
  41. frag: standard-fs
  42. phase: forward-add
  43. propertyIndex: 0
  44. embeddedMacros: { CC_FORWARD_ADD: true }
  45. depthStencilState:
  46. depthFunc: equal
  47. depthTest: true
  48. depthWrite: false
  49. blendState:
  50. targets:
  51. - blend: true
  52. blendSrc: one
  53. blendDst: one
  54. blendSrcAlpha: zero
  55. blendDstAlpha: one
  56. - &shadow-caster
  57. vert: shadow-caster-vs
  58. frag: shadow-caster-fs
  59. phase: shadow-caster
  60. propertyIndex: 0
  61. rasterizerState:
  62. cullMode: none
  63. properties:
  64. tilingOffset: { value: [1.0, 1.0, 0.0, 0.0] }
  65. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
  66. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  67. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  68. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  69. - &deferred-forward
  70. vert: standard-vs
  71. frag: standard-fs
  72. phase: deferred-forward
  73. propertyIndex: 0
  74. rasterizerState: *r1
  75. depthStencilState: *d1
  76. - name: transparent
  77. passes:
  78. - vert: standard-vs
  79. frag: standard-fs
  80. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  81. depthStencilState: &dt
  82. depthTest: true
  83. depthWrite: false
  84. blendState: &b1
  85. targets:
  86. - blend: true
  87. blendSrc: src_alpha
  88. blendDst: one_minus_src_alpha
  89. blendDstAlpha: one_minus_src_alpha
  90. properties: *props
  91. - *forward-add
  92. - *shadow-caster
  93. - &deferred-forward-transparent
  94. vert: standard-vs
  95. frag: standard-fs
  96. phase: deferred-forward
  97. embeddedMacros: { CC_PIPELINE_TYPE: 0 }
  98. depthStencilState: *dt
  99. blendState: *b1
  100. propertyIndex: 0
  101. }%
  102. CCProgram shared-ubos %{
  103. uniform Constants {
  104. vec4 tilingOffset;
  105. vec4 albedo;
  106. vec4 albedoScaleAndCutoff;
  107. vec4 pbrParams;
  108. vec4 emissiveScaleParam;
  109. vec4 transmitColor;
  110. vec4 scatterParams;
  111. vec4 dualLobeParams;
  112. };
  113. }%
  114. CCProgram macro-remapping %{
  115. // ui displayed macros
  116. #pragma define-meta HAS_SECOND_UV
  117. #pragma define-meta USE_TWOSIDE
  118. #pragma define-meta USE_VERTEX_COLOR
  119. #pragma define-meta USE_BACK_LIT
  120. #pragma define-meta USE_PREINTEGRATED_SKIN
  121. #pragma define-meta USE_DUAL_LOBE_SPECULAR
  122. #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
  123. #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
  124. #define CC_SURFACES_USE_VERTEX_COLOR USE_VERTEX_COLOR
  125. #define CC_SURFACES_LIGHTING_DUAL_LOBE_SPECULAR USE_DUAL_LOBE_SPECULAR
  126. #define CC_SURFACES_LIGHTING_TRANSMIT_DIFFUSE USE_BACK_LIT
  127. #define CC_SURFACES_LIGHTING_USE_SHADOWMAP_TRANSMIT USE_BACK_LIT
  128. #define CC_SURFACES_LIGHTING_SSS 1
  129. // depend on UI macros
  130. #if USE_NORMAL_MAP
  131. #define CC_SURFACES_USE_TANGENT_SPACE 1
  132. #endif
  133. }%
  134. CCProgram surface-vertex %{
  135. }%
  136. CCProgram surface-fragment %{
  137. #if USE_ALBEDO_MAP
  138. uniform sampler2D albedoMap;
  139. #pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
  140. #endif
  141. #if USE_NORMAL_MAP
  142. uniform sampler2D normalMap;
  143. #pragma define-meta NORMAL_UV options([v_uv, v_uv1])
  144. #endif
  145. #pragma define-meta DEFAULT_UV options([v_uv, v_uv1])
  146. #if USE_PBR_MAP
  147. uniform sampler2D pbrMap;
  148. #endif
  149. #if USE_OCCLUSION_MAP
  150. uniform sampler2D occlusionMap;
  151. #endif
  152. #pragma define OCCLUSION_CHANNEL r
  153. #pragma define ROUGHNESS_CHANNEL g
  154. #pragma define METALLIC_CHANNEL b
  155. #pragma define SPECULAR_INTENSITY_CHANNEL a
  156. #if USE_ALPHA_TEST
  157. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
  158. #endif
  159. //////////////////User Defines
  160. #if USE_BACK_LIT
  161. uniform sampler2D maskMap;
  162. #endif
  163. #if USE_PREINTEGRATED_SKIN
  164. uniform sampler2D sssCurvatureMap;
  165. #endif
  166. uniform sampler2D cavityMap;
  167. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_SCATTERING_PARAMS
  168. vec4 SurfacesFragmentModifyTransmitScatteringParams()
  169. {
  170. return vec4(scatterParams.y * 50.0, 0.0, 1.0, 0.01);
  171. }
  172. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_DIFFUSE_PARAMS
  173. vec4 SurfacesFragmentModifyTransmitDiffuseParams()
  174. {
  175. float mask = 1.0;
  176. #if USE_BACK_LIT
  177. mask = texture(maskMap, FSInput_texcoord).x;
  178. #endif
  179. return vec4(scatterParams.x, mask, 1.0, 1.0);
  180. }
  181. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_IN_SCATTERING_COLOR
  182. vec3 SurfacesFragmentModifyTransmitInScatteringColor()
  183. {
  184. return vec3(0.0);//1.0, 0.2, 0.05);
  185. }
  186. #define CC_SURFACES_FRAGMENT_MODIFY_TRANSMIT_OUT_SCATTERING_COLOR
  187. vec3 SurfacesFragmentModifyTransmitOutScatteringColor()
  188. {
  189. return transmitColor.rgb;
  190. }
  191. #define CC_SURFACES_FRAGMENT_MODIFY_DUAL_LOBE_SPECULAR_PARAMS
  192. vec4 SurfacesFragmentModifyDualLobeSpecularParams(float roughness)
  193. {
  194. return vec4(dualLobeParams.x * roughness, 0.0, 0.0, dualLobeParams.w);
  195. }
  196. #define CC_SURFACES_FRAGMENT_MODIFY_SSS_PARAMS
  197. vec4 SurfacesFragmentModifySSSParams()
  198. {
  199. float sssCurvature = scatterParams.w;
  200. #if USE_PREINTEGRATED_SKIN
  201. sssCurvature *= texture(sssCurvatureMap, FSInput_texcoord).x;
  202. #endif
  203. return vec4(scatterParams.z, sssCurvature, dualLobeParams.z, 0.0);
  204. }
  205. #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
  206. vec4 SurfacesFragmentModifyPBRParams()
  207. {
  208. vec4 pbr = pbrParams;
  209. pbr.x = 1.0;
  210. pbr.z = 0.0;
  211. #if USE_PBR_MAP
  212. // ao and metallic ignored from pbrMap
  213. vec4 res = texture(pbrMap, DEFAULT_UV);
  214. pbr.y *= res.ROUGHNESS_CHANNEL;
  215. pbr.w *= res.SPECULAR_INTENSITY_CHANNEL;
  216. #endif
  217. #if USE_OCCLUSION_MAP
  218. pbr.x = mix(1.0, texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL, pbrParams.x);
  219. #endif
  220. float cavity = texture(cavityMap, FSInput_texcoord).x;
  221. pbr.w *= cavity;
  222. return pbr;
  223. }
  224. #include <common-functions>
  225. #include <lighting-models/default-functions/simple-skin>
  226. }%
  227. CCProgram standard-vs %{
  228. precision highp float;
  229. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  230. #include <macro-remapping>
  231. #include <surfaces/effect-macros/common-macros>
  232. // 2. common include with corresponding shader stage, include before surface functions
  233. #include <surfaces/includes/common-vs>
  234. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  235. // see surfaces/default-functions/xxx.chunk
  236. #include <shared-ubos>
  237. #include <surface-vertex>
  238. // 4. surface include with corresponding shader stage and shading-model (optional)
  239. #include <surfaces/includes/standard-vs>
  240. // 5. shader entry with corresponding shader stage and technique usage/type
  241. #include <shading-entries/main-functions/render-to-scene/vs>
  242. }%
  243. CCProgram shadow-caster-vs %{
  244. precision highp float;
  245. #include <macro-remapping>
  246. #include <surfaces/effect-macros/render-to-shadowmap>
  247. #include <surfaces/includes/common-vs>
  248. #include <shared-ubos>
  249. #include <surface-vertex>
  250. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  251. }%
  252. CCProgram standard-fs %{
  253. // shading-model : standard
  254. // lighting-model : standard (isotropy / anisotropy pbr)
  255. // shader stage : fs
  256. // technique usage/type : render-to-scene
  257. precision highp float;
  258. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  259. #include <macro-remapping>
  260. #include <surfaces/effect-macros/common-macros>
  261. // 2. common include with corresponding shader stage, include before surface functions
  262. #include <surfaces/includes/common-fs>
  263. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  264. // see surfaces/default-functions/xxx.chunk
  265. #include <shared-ubos>
  266. #include <surface-fragment>
  267. // 4. lighting-model (optional)
  268. #include <lighting-models/includes/standard>
  269. // 5. surface include with corresponding shader stage and shading-model (optional)
  270. #include <surfaces/includes/standard-fs>
  271. // 6. shader entry with corresponding shader stage and technique usage/type
  272. #include <shading-entries/main-functions/render-to-scene/fs>
  273. }%
  274. CCProgram shadow-caster-fs %{
  275. precision highp float;
  276. #include <macro-remapping>
  277. #include <surfaces/effect-macros/render-to-shadowmap>
  278. #include <surfaces/includes/common-fs>
  279. #include <shared-ubos>
  280. #include <surface-fragment>
  281. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  282. }%
  283. CCProgram reflect-map-fs %{
  284. precision highp float;
  285. #include <macro-remapping>
  286. #include <surfaces/effect-macros/common-macros>
  287. #include <surfaces/includes/common-fs>
  288. #include <shared-ubos>
  289. #include <surface-fragment>
  290. #include <lighting-models/includes/standard>
  291. #include <surfaces/includes/standard-fs>
  292. #include <shading-entries/main-functions/render-to-reflectmap/fs>
  293. }%