houdini-rigidbody-v2.effect 15 KB

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