houdini-softbody-v3.effect 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  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. vatSpeed: { value: 1.0, target: vatParams.x, editor: { displayName: AnimationSpeed } }
  10. vatFrameCount: { value: 0.0, target: vatParams.y, editor: { displayName: NumOfFrames } }
  11. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, linear: true, editor: { displayName: Albedo, type: color } }
  12. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  13. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST, slide: true, range: [0, 1.0], step: 0.001 } }
  14. occlusion: { value: 0.0, target: pbrParams.x, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  15. roughness: { value: 0.5, target: pbrParams.y, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  16. metallic: { value: 0.0, target: pbrParams.z, editor: { slide: true, range: [0, 1.0], step: 0.001 } }
  17. specularIntensity: { value: 0.5, target: pbrParams.w, editor: { slide: true, range: [0.0, 1.0], step: 0.001 } }
  18. emissive: { value: [0.0, 0.0, 0.0, 1.0], linear: true, editor: { type: color } }
  19. emissiveScale: { value: [1.0, 1.0, 1.0], target: emissiveScaleParam.xyz }
  20. normalStrength: { value: 1.0, target: emissiveScaleParam.w, editor: { parent: USE_NORMAL_MAP, slide: true, range: [0, 5.0], step: 0.001 } }
  21. anisotropyIntensity: { value: 1.0, target: anisotropyParam.x, editor: { parent: IS_ANISOTROPY, slide : true, range : [0.0, 1.0] , step : 0.0001 } }
  22. anisotropyRotation: { value: 0.0, target: anisotropyParam.y, editor: { parent: IS_ANISOTROPY, slide : true, range : [0, 1.0] , step : 0.0001 } }
  23. anisotropyMapResolutionHeight: { value: 0.0, target: anisotropyParam.w, editor: { parent: FIX_ANISOTROPIC_ROTATION_MAP } }
  24. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  25. normalMap: { value: normal }
  26. pbrMap: { value: grey }
  27. occlusionMap: { value: white }
  28. emissiveMap: { value: grey }
  29. anisotropyMap: { value: black, editor : { parent: IS_ANISOTROPY } }
  30. vatPositionMap: { value: grey, target: vatPositionTexture, editor: { displayName: PositionMap } }
  31. vatPosSignMap: { value: white, target: vatPosSignTexture, editor: { displayName: PosSignMap } }
  32. vatRotationMap: { value: grey, target: vatRotationTexture, editor: { displayName: RotationMap } }
  33. vatRotSignMap: { value: white, target: vatRotSignTexture, editor: { displayName: RotSignMap } }
  34. vatRotAlphaMap: { value: grey, target: vatRotAlphaTexture, editor: { displayName: RotAlphaMap } }
  35. rasterizerState: &r1
  36. cullMode: none
  37. - &forward-add
  38. vert: standard-vs
  39. frag: standard-fs
  40. phase: forward-add
  41. propertyIndex: 0
  42. embeddedMacros: { CC_FORWARD_ADD: true }
  43. rasterizerState:
  44. cullMode: none
  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: front
  63. properties:
  64. mainColor: { value: [1.0, 1.0, 1.0, 1.0], target: albedo, editor: { displayName: Albedo, type: color } }
  65. albedoScale: { value: [1.0, 1.0, 1.0], target: albedoScaleAndCutoff.xyz }
  66. alphaThreshold: { value: 0.5, target: albedoScaleAndCutoff.w, editor: { parent: USE_ALPHA_TEST } }
  67. mainTexture: { value: grey, target: albedoMap, editor: { displayName: AlbedoMap } }
  68. - &reflect-map
  69. vert: standard-vs
  70. frag: reflect-map-fs
  71. phase: reflect-map
  72. propertyIndex: 0
  73. - &deferred-forward
  74. vert: standard-vs
  75. frag: standard-fs
  76. phase: deferred-forward
  77. propertyIndex: 0
  78. rasterizerState: *r1
  79. - name: transparent
  80. passes:
  81. - vert: standard-vs
  82. frag: standard-fs
  83. embeddedMacros: { CC_FORCE_FORWARD_SHADING: true }
  84. depthStencilState: &d1
  85. depthTest: true
  86. depthWrite: false
  87. blendState: &b1
  88. targets:
  89. - blend: true
  90. blendSrc: src_alpha
  91. blendDst: one_minus_src_alpha
  92. blendDstAlpha: one_minus_src_alpha
  93. - *forward-add
  94. - *shadow-caster
  95. - &deferred-forward
  96. vert: standard-vs
  97. frag: standard-fs
  98. phase: deferred-forward
  99. embeddedMacros: { CC_PIPELINE_TYPE: 0 }
  100. depthStencilState: *d1
  101. blendState: *b1
  102. propertyIndex: 0
  103. }%
  104. CCProgram shared-ubos %{
  105. uniform Constants {
  106. vec4 vatParams;
  107. vec4 albedo;
  108. vec4 albedoScaleAndCutoff;
  109. vec4 pbrParams;
  110. vec4 emissive;
  111. vec4 emissiveScaleParam;
  112. vec4 anisotropyParam;
  113. };
  114. }%
  115. CCProgram macro-remapping %{
  116. // ui displayed macros
  117. #pragma define-meta HAS_SECOND_UV
  118. #pragma define-meta USE_TWOSIDE
  119. #pragma define-meta IS_ANISOTROPY
  120. #define CC_SURFACES_USE_SECOND_UV HAS_SECOND_UV
  121. #define CC_SURFACES_USE_TWO_SIDED USE_TWOSIDE
  122. #define CC_SURFACES_LIGHTING_ANISOTROPIC IS_ANISOTROPY
  123. // depend on UI macros
  124. #if USE_NORMAL_MAP || IS_ANISOTROPY
  125. #define CC_SURFACES_USE_TANGENT_SPACE 1
  126. #endif
  127. #define CC_SURFACES_LIGHTING_ANISOTROPIC_ENVCONVOLUTION_COUNT 31
  128. }%
  129. CCProgram surface-vertex %{
  130. #include <common/mesh/vat-animation>
  131. uniform highp sampler2D vatPositionTexture;
  132. uniform highp sampler2D vatPosSignTexture;
  133. uniform highp sampler2D vatRotationTexture;
  134. uniform highp sampler2D vatRotSignTexture;
  135. uniform highp sampler2D vatRotAlphaTexture;
  136. #define CC_SURFACES_VERTEX_MODIFY_LOCAL_POS
  137. vec3 SurfacesVertexModifyLocalPos(in SurfacesStandardVertexIntermediate In)
  138. {
  139. vec3 pos = In.position.xyz;
  140. vec2 originUV = In.texCoord, thisFrameUV, nextFrameUV;
  141. #if CC_SURFACES_USE_SECOND_UV
  142. originUV = In.texCoord1;
  143. #endif
  144. float numOfFrames = vatParams.y, speed = vatParams.x;
  145. float frameLerp = VATGetAnimUV(thisFrameUV, nextFrameUV, originUV, numOfFrames, speed, cc_time.x);
  146. pos += VATGetLocalPosition(thisFrameUV
  147. #if USE_SMOOTH_ANIMATION
  148. , nextFrameUV, frameLerp
  149. #endif
  150. , vatPositionTexture, vatPosSignTexture);
  151. return pos;
  152. }
  153. #define CC_SURFACES_VERTEX_MODIFY_LOCAL_SHARED_DATA
  154. void SurfacesVertexModifyLocalSharedData(inout SurfacesStandardVertexIntermediate In)
  155. {
  156. vec3 normal = In.normal.xyz;
  157. vec2 originUV = In.texCoord, thisFrameUV, nextFrameUV;
  158. #if CC_SURFACES_USE_SECOND_UV
  159. originUV = In.texCoord1;
  160. #endif
  161. float numOfFrames = vatParams.y, speed = vatParams.x;
  162. float frameLerp = VATGetAnimUV(thisFrameUV, nextFrameUV, originUV, numOfFrames, speed, cc_time.x);
  163. normal = VATGetLocalNormal(normal, thisFrameUV
  164. #if USE_SMOOTH_ANIMATION
  165. , nextFrameUV, frameLerp
  166. #endif
  167. , vatRotationTexture, vatRotSignTexture, vatRotAlphaTexture);
  168. In.normal.xyz = normalize(normal);
  169. #if CC_SURFACES_USE_TANGENT_SPACE
  170. vec3 tangent = In.tangent.xzy;
  171. tangent = VATGetLocalNormal(tangent, thisFrameUV
  172. #if USE_SMOOTH_ANIMATION
  173. , nextFrameUV, frameLerp
  174. #endif
  175. , vatRotationTexture, vatRotSignTexture, vatRotAlphaTexture);
  176. In.tangent.xyz = normalize(tangent);
  177. #endif
  178. }
  179. }%
  180. CCProgram surface-fragment %{
  181. #if USE_ALBEDO_MAP
  182. uniform sampler2D albedoMap;
  183. #pragma define-meta ALBEDO_UV options([v_uv, v_uv1])
  184. #endif
  185. #if USE_NORMAL_MAP
  186. uniform sampler2D normalMap;
  187. #pragma define-meta NORMAL_UV options([v_uv, v_uv1])
  188. #endif
  189. #pragma define-meta DEFAULT_UV options([v_uv, v_uv1])
  190. #if USE_PBR_MAP
  191. uniform sampler2D pbrMap;
  192. #endif
  193. #if USE_OCCLUSION_MAP
  194. uniform sampler2D occlusionMap;
  195. #endif
  196. #if USE_EMISSIVE_MAP
  197. uniform sampler2D emissiveMap;
  198. #pragma define-meta EMISSIVE_UV options([v_uv, v_uv1])
  199. #endif
  200. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  201. uniform sampler2D anisotropyMap;
  202. #endif
  203. #pragma define OCCLUSION_CHANNEL r
  204. #pragma define ROUGHNESS_CHANNEL g
  205. #pragma define METALLIC_CHANNEL b
  206. #pragma define SPECULAR_INTENSITY_CHANNEL a
  207. #if USE_ALPHA_TEST
  208. #pragma define-meta ALPHA_TEST_CHANNEL options([a, r])
  209. #endif
  210. #define CC_SURFACES_FRAGMENT_MODIFY_BASECOLOR_AND_TRANSPARENCY
  211. vec4 SurfacesFragmentModifyBaseColorAndTransparency()
  212. {
  213. vec4 baseColor = albedo;
  214. #if USE_VERTEX_COLOR
  215. baseColor.rgb *= SRGBToLinear(FSInput_vertexColor.rgb); // use linear
  216. baseColor.a *= FSInput_vertexColor.a;
  217. #endif
  218. #if USE_ALBEDO_MAP
  219. vec4 texColor = texture(albedoMap, ALBEDO_UV);
  220. texColor.rgb = SRGBToLinear(texColor.rgb);
  221. baseColor *= texColor;
  222. #endif
  223. #if USE_ALPHA_TEST
  224. if (baseColor.ALPHA_TEST_CHANNEL < albedoScaleAndCutoff.w) discard;
  225. #endif
  226. baseColor.rgb *= albedoScaleAndCutoff.xyz;
  227. return baseColor;
  228. }
  229. #define CC_SURFACES_FRAGMENT_ALPHA_CLIP_ONLY
  230. void SurfacesFragmentAlphaClipOnly()
  231. {
  232. #if USE_ALPHA_TEST
  233. float alpha = albedo.ALPHA_TEST_CHANNEL;
  234. #if USE_VERTEX_COLOR
  235. alpha *= FSInput_vertexColor.a;
  236. #endif
  237. #if USE_ALBEDO_MAP
  238. alpha = texture(albedoMap, ALBEDO_UV).ALPHA_TEST_CHANNEL;
  239. #endif
  240. if (alpha < albedoScaleAndCutoff.w) discard;
  241. #endif
  242. }
  243. #define CC_SURFACES_FRAGMENT_MODIFY_WORLD_NORMAL
  244. vec3 SurfacesFragmentModifyWorldNormal()
  245. {
  246. vec3 normal = FSInput_worldNormal;
  247. #if USE_NORMAL_MAP
  248. vec3 nmmp = texture(normalMap, NORMAL_UV).xyz - vec3(0.5);
  249. normal = CalculateNormalFromTangentSpace(nmmp, emissiveScaleParam.w, normal.xyz, FSInput_worldTangent, FSInput_mirrorNormal);
  250. #endif
  251. return normalize(normal);
  252. }
  253. #define CC_SURFACES_FRAGMENT_MODIFY_ANISOTROPY_PARAMS
  254. vec4 SurfacesFragmentModifyAnisotropyParams(out float isRotation)
  255. {
  256. float anisotropyRotation = anisotropyParam.y * PI;
  257. float anisotropyShape = anisotropyParam.x;
  258. #if IS_ANISOTROPY && USE_ANISOTROPY_MAP
  259. // Rotation angle should disable trilinear filtering
  260. vec4 tex = texture(anisotropyMap, DEFAULT_UV);
  261. anisotropyRotation = fract(anisotropyRotation * 0.5 + tex.y) * PI2;
  262. // less value is better for SP exported shape
  263. anisotropyShape *= tex.x;
  264. #endif
  265. isRotation = 1.0;
  266. return vec4(anisotropyShape, anisotropyRotation, 0.0, 0.0);
  267. }
  268. #define CC_SURFACES_FRAGMENT_MODIFY_EMISSIVE
  269. vec3 SurfacesFragmentModifyEmissive()
  270. {
  271. vec3 emissive = emissive.rgb;
  272. #if USE_EMISSIVE_MAP
  273. emissive = SRGBToLinear(texture(emissiveMap, EMISSIVE_UV).rgb);
  274. #endif
  275. return emissive * emissiveScaleParam.xyz;
  276. }
  277. #define CC_SURFACES_FRAGMENT_MODIFY_PBRPARAMS
  278. vec4 SurfacesFragmentModifyPBRParams()
  279. {
  280. vec4 pbr = pbrParams;
  281. pbr.x = 1.0;
  282. #if USE_PBR_MAP
  283. vec4 res = texture(pbrMap, DEFAULT_UV);
  284. pbr.x = mix(1.0, res.OCCLUSION_CHANNEL, pbrParams.x);
  285. pbr.y *= res.ROUGHNESS_CHANNEL;
  286. pbr.z *= res.METALLIC_CHANNEL;
  287. pbr.w *= res.SPECULAR_INTENSITY_CHANNEL;
  288. #endif
  289. #if USE_OCCLUSION_MAP
  290. pbr.x = mix(1.0, texture(occlusionMap, DEFAULT_UV).OCCLUSION_CHANNEL, pbrParams.x);
  291. #endif
  292. return pbr;
  293. }
  294. }%
  295. CCProgram standard-vs %{
  296. precision highp float;
  297. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  298. #include <macro-remapping>
  299. #include <surfaces/effect-macros/common-macros>
  300. // 2. common include with corresponding shader stage, include before surface functions
  301. #include <surfaces/includes/common-vs>
  302. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  303. // see surfaces/default-functions/xxx.chunk
  304. #include <shared-ubos>
  305. #include <surface-vertex>
  306. // 4. surface include with corresponding shader stage and shading-model (optional)
  307. #include <surfaces/includes/standard-vs>
  308. // 5. shader entry with corresponding shader stage and technique usage/type
  309. #include <shading-entries/main-functions/render-to-scene/vs>
  310. }%
  311. CCProgram shadow-caster-vs %{
  312. precision highp float;
  313. #include <macro-remapping>
  314. #include <surfaces/effect-macros/render-to-shadowmap>
  315. #include <surfaces/includes/common-vs>
  316. #include <shared-ubos>
  317. #include <surface-vertex>
  318. #include <shading-entries/main-functions/render-to-shadowmap/vs>
  319. }%
  320. CCProgram standard-fs %{
  321. // shading-model : standard
  322. // lighting-model : standard (isotropy / anisotropy pbr)
  323. // shader stage : fs
  324. // technique usage/type : render-to-scene
  325. precision highp float;
  326. // 1. surface internal macros, for technique usage or remapping some user (material) macros to surface internal macros
  327. #include <macro-remapping>
  328. #include <surfaces/effect-macros/common-macros>
  329. // 2. common include with corresponding shader stage, include before surface functions
  330. #include <surfaces/includes/common-fs>
  331. // 3. user surface functions that can use user (effect) parameters (ubo Constants)
  332. // see surfaces/default-functions/xxx.chunk
  333. #include <shared-ubos>
  334. #include <surface-fragment>
  335. // 4. lighting-model (optional)
  336. #include <lighting-models/includes/standard>
  337. // 5. surface include with corresponding shader stage and shading-model (optional)
  338. #include <surfaces/includes/standard-fs>
  339. // 6. shader entry with corresponding shader stage and technique usage/type
  340. #include <shading-entries/main-functions/render-to-scene/fs>
  341. }%
  342. CCProgram shadow-caster-fs %{
  343. precision highp float;
  344. #include <macro-remapping>
  345. #include <surfaces/effect-macros/render-to-shadowmap>
  346. #include <surfaces/includes/common-fs>
  347. #include <shared-ubos>
  348. #include <surface-fragment>
  349. #include <shading-entries/main-functions/render-to-shadowmap/fs>
  350. }%
  351. CCProgram reflect-map-fs %{
  352. precision highp float;
  353. #include <macro-remapping>
  354. #include <surfaces/effect-macros/common-macros>
  355. #include <surfaces/includes/common-fs>
  356. #include <shared-ubos>
  357. #include <surface-fragment>
  358. #include <lighting-models/includes/standard>
  359. #include <surfaces/includes/standard-fs>
  360. #include <shading-entries/main-functions/render-to-reflectmap/fs>
  361. }%