builtin-pipeline-settings.ts 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452
  1. /*
  2. Copyright (c) 2021-2024 Xiamen Yaji Software Co., Ltd.
  3. https://www.cocos.com/
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights to
  7. use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
  8. of the Software, and to permit persons to whom the Software is furnished to do so,
  9. subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. import {
  21. _decorator, Camera, CCBoolean, CCFloat, CCInteger, Component,
  22. Material, rendering, Texture2D,
  23. } from 'cc';
  24. import { EDITOR } from 'cc/env';
  25. import {
  26. BloomType,
  27. fillRequiredPipelineSettings, makePipelineSettings, PipelineSettings,
  28. } from './builtin-pipeline-types';
  29. const { ccclass, disallowMultiple, executeInEditMode, menu, property, requireComponent, type } = _decorator;
  30. @ccclass('BuiltinPipelineSettings')
  31. @menu('Rendering/BuiltinPipelineSettings')
  32. @requireComponent(Camera)
  33. @disallowMultiple
  34. @executeInEditMode
  35. export class BuiltinPipelineSettings extends Component {
  36. @property
  37. private readonly _settings: PipelineSettings = makePipelineSettings();
  38. getPipelineSettings(): PipelineSettings {
  39. return this._settings;
  40. }
  41. // Enable/Disable
  42. onEnable(): void {
  43. fillRequiredPipelineSettings(this._settings);
  44. const cameraComponent = this.getComponent(Camera)!;
  45. const camera = cameraComponent.camera;
  46. camera.pipelineSettings = this._settings;
  47. if (EDITOR) {
  48. this._tryEnableEditorPreview();
  49. }
  50. }
  51. onDisable(): void {
  52. const cameraComponent = this.getComponent(Camera)!;
  53. const camera = cameraComponent.camera;
  54. if (camera) {
  55. camera.pipelineSettings = null;
  56. }
  57. if (EDITOR) {
  58. this._disableEditorPreview();
  59. }
  60. }
  61. // Editor Preview
  62. @property(CCBoolean)
  63. protected _editorPreview = false;
  64. @property({
  65. displayName: 'Editor Preview (Experimental)',
  66. type: CCBoolean,
  67. })
  68. get editorPreview(): boolean {
  69. return this._editorPreview;
  70. }
  71. set editorPreview(v: boolean) {
  72. this._editorPreview = v;
  73. if (EDITOR) {
  74. this._tryEnableEditorPreview();
  75. }
  76. }
  77. public _tryEnableEditorPreview(): void {
  78. if (rendering === undefined) {
  79. return;
  80. }
  81. if (this._editorPreview) {
  82. rendering.setEditorPipelineSettings(this._settings);
  83. } else {
  84. this._disableEditorPreview();
  85. }
  86. }
  87. public _disableEditorPreview(): void {
  88. if (rendering === undefined) {
  89. return;
  90. }
  91. const current = rendering.getEditorPipelineSettings() as PipelineSettings | null;
  92. if (current === this._settings) {
  93. rendering.setEditorPipelineSettings(null);
  94. }
  95. }
  96. // MSAA
  97. @property({
  98. group: { id: 'MSAA', name: 'Multisample Anti-Aliasing' },
  99. type: CCBoolean,
  100. })
  101. get MsaaEnable(): boolean {
  102. return this._settings.msaa.enabled;
  103. }
  104. set MsaaEnable(value: boolean) {
  105. this._settings.msaa.enabled = value;
  106. if (EDITOR) {
  107. this._tryEnableEditorPreview();
  108. }
  109. }
  110. @property({
  111. group: { id: 'MSAA', name: 'Multisample Anti-Aliasing', style: 'section' },
  112. type: CCInteger,
  113. range: [2, 4, 2],
  114. })
  115. set msaaSampleCount(value: number) {
  116. value = 2 ** Math.ceil(Math.log2(Math.max(value, 2)));
  117. value = Math.min(value, 4);
  118. this._settings.msaa.sampleCount = value;
  119. if (EDITOR) {
  120. this._tryEnableEditorPreview();
  121. }
  122. }
  123. get msaaSampleCount(): number {
  124. return this._settings.msaa.sampleCount;
  125. }
  126. // Shading Scale
  127. @property({
  128. group: { id: 'ShadingScale', name: 'ShadingScale', style: 'section' },
  129. type: CCBoolean,
  130. })
  131. set shadingScaleEnable(value: boolean) {
  132. this._settings.enableShadingScale = value;
  133. if (EDITOR) {
  134. this._tryEnableEditorPreview();
  135. }
  136. }
  137. get shadingScaleEnable(): boolean {
  138. return this._settings.enableShadingScale;
  139. }
  140. @property({
  141. tooltip: 'i18n:postprocess.shadingScale',
  142. group: { id: 'ShadingScale', name: 'ShadingScale' },
  143. type: CCFloat,
  144. range: [0.01, 4, 0.01],
  145. slide: true,
  146. })
  147. set shadingScale(value: number) {
  148. this._settings.shadingScale = value;
  149. if (EDITOR) {
  150. this._tryEnableEditorPreview();
  151. }
  152. }
  153. get shadingScale(): number {
  154. return this._settings.shadingScale;
  155. }
  156. // Bloom
  157. @property({
  158. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  159. type: CCBoolean,
  160. })
  161. set bloomEnable(value: boolean) {
  162. this._settings.bloom.enabled = value;
  163. if (EDITOR) {
  164. this._tryEnableEditorPreview();
  165. }
  166. }
  167. get bloomEnable(): boolean {
  168. return this._settings.bloom.enabled;
  169. }
  170. @type(BloomType)
  171. @property({
  172. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  173. })
  174. set bloomType(value: BloomType) {
  175. this._settings.bloom.type = value;
  176. if (EDITOR) {
  177. this._tryEnableEditorPreview();
  178. }
  179. }
  180. get bloomType(): BloomType {
  181. return this._settings.bloom.type;
  182. }
  183. @property({
  184. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  185. type: Material,
  186. })
  187. set kawaseBloomMaterial(value: Material) {
  188. if (this._settings.bloom.kawaseFilterMaterial === value) {
  189. return;
  190. }
  191. this._settings.bloom.kawaseFilterMaterial = value;
  192. if (EDITOR) {
  193. this._tryEnableEditorPreview();
  194. }
  195. }
  196. get kawaseBloomMaterial(): Material {
  197. return this._settings.bloom.kawaseFilterMaterial!;
  198. }
  199. @property({
  200. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  201. type: Material,
  202. })
  203. set mipmapBloomMaterial(value: Material) {
  204. if (this._settings.bloom.mipmapFilterMaterial === value) {
  205. return;
  206. }
  207. this._settings.bloom.mipmapFilterMaterial = value;
  208. if (EDITOR) {
  209. this._tryEnableEditorPreview();
  210. }
  211. }
  212. get mipmapBloomMaterial(): Material {
  213. return this._settings.bloom.mipmapFilterMaterial!;
  214. }
  215. @property({
  216. tooltip: 'i18n:bloom.enableAlphaMask',
  217. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  218. type: CCBoolean,
  219. })
  220. set bloomEnableAlphaMask(value: boolean) {
  221. this._settings.bloom.enableAlphaMask = value;
  222. if (EDITOR) {
  223. this._tryEnableEditorPreview();
  224. }
  225. }
  226. get bloomEnableAlphaMask(): boolean {
  227. return this._settings.bloom.enableAlphaMask;
  228. }
  229. @property({
  230. tooltip: 'i18n:bloom.iterations',
  231. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  232. type: CCInteger,
  233. range: [1, 6, 1],
  234. slide: true,
  235. })
  236. set bloomIterations(value: number) {
  237. this._settings.bloom.iterations = value;
  238. if (EDITOR) {
  239. this._tryEnableEditorPreview();
  240. }
  241. }
  242. get bloomIterations(): number {
  243. return this._settings.bloom.iterations;
  244. }
  245. @property({
  246. tooltip: 'i18n:bloom.threshold',
  247. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  248. type: CCFloat,
  249. min: 0,
  250. })
  251. set bloomThreshold(value: number) {
  252. this._settings.bloom.threshold = value;
  253. }
  254. get bloomThreshold(): number {
  255. return this._settings.bloom.threshold;
  256. }
  257. @type(CCFloat)
  258. @property({
  259. group: { id: 'Bloom', name: 'Bloom (PostProcessing)', style: 'section' },
  260. })
  261. set bloomIntensity(value: number) {
  262. this._settings.bloom.intensity = value;
  263. if (EDITOR) {
  264. this._tryEnableEditorPreview();
  265. }
  266. }
  267. get bloomIntensity(): number {
  268. return this._settings.bloom.intensity;
  269. }
  270. // Color Grading (LDR)
  271. @property({
  272. group: { id: 'Color Grading', name: 'ColorGrading (LDR) (PostProcessing)', style: 'section' },
  273. type: CCBoolean,
  274. })
  275. set colorGradingEnable(value: boolean) {
  276. this._settings.colorGrading.enabled = value;
  277. if (EDITOR) {
  278. this._tryEnableEditorPreview();
  279. }
  280. }
  281. get colorGradingEnable(): boolean {
  282. return this._settings.colorGrading.enabled;
  283. }
  284. @property({
  285. group: { id: 'Color Grading', name: 'ColorGrading (LDR) (PostProcessing)', style: 'section' },
  286. type: Material,
  287. })
  288. set colorGradingMaterial(value: Material) {
  289. if (this._settings.colorGrading.material === value) {
  290. return;
  291. }
  292. this._settings.colorGrading.material = value;
  293. if (EDITOR) {
  294. this._tryEnableEditorPreview();
  295. }
  296. }
  297. get colorGradingMaterial(): Material {
  298. return this._settings.colorGrading.material!;
  299. }
  300. @property({
  301. tooltip: 'i18n:color_grading.contribute',
  302. group: { id: 'Color Grading', name: 'ColorGrading (LDR) (PostProcessing)', style: 'section' },
  303. type: CCFloat,
  304. range: [0, 1, 0.01],
  305. slide: true,
  306. })
  307. set colorGradingContribute(value: number) {
  308. this._settings.colorGrading.contribute = value;
  309. }
  310. get colorGradingContribute(): number {
  311. return this._settings.colorGrading.contribute;
  312. }
  313. @property({
  314. tooltip: 'i18n:color_grading.originalMap',
  315. group: { id: 'Color Grading', name: 'ColorGrading (LDR) (PostProcessing)', style: 'section' },
  316. type: Texture2D,
  317. })
  318. set colorGradingMap(val: Texture2D) {
  319. this._settings.colorGrading.colorGradingMap = val;
  320. if (EDITOR) {
  321. this._tryEnableEditorPreview();
  322. }
  323. }
  324. get colorGradingMap(): Texture2D {
  325. return this._settings.colorGrading.colorGradingMap!;
  326. }
  327. // FXAA
  328. @property({
  329. group: { id: 'FXAA', name: 'Fast Approximate Anti-Aliasing (PostProcessing)', style: 'section' },
  330. type: CCBoolean,
  331. })
  332. set fxaaEnable(value: boolean) {
  333. this._settings.fxaa.enabled = value;
  334. if (EDITOR) {
  335. this._tryEnableEditorPreview();
  336. }
  337. }
  338. get fxaaEnable(): boolean {
  339. return this._settings.fxaa.enabled;
  340. }
  341. @property({
  342. group: { id: 'FXAA', name: 'Fast Approximate Anti-Aliasing (PostProcessing)', style: 'section' },
  343. type: Material,
  344. })
  345. set fxaaMaterial(value: Material) {
  346. if (this._settings.fxaa.material === value) {
  347. return;
  348. }
  349. this._settings.fxaa.material = value;
  350. if (EDITOR) {
  351. this._tryEnableEditorPreview();
  352. }
  353. }
  354. get fxaaMaterial(): Material {
  355. return this._settings.fxaa.material!;
  356. }
  357. // FSR
  358. @property({
  359. group: { id: 'FSR', name: 'FidelityFX Super Resolution', style: 'section' },
  360. type: CCBoolean,
  361. })
  362. set fsrEnable(value: boolean) {
  363. this._settings.fsr.enabled = value;
  364. if (EDITOR) {
  365. this._tryEnableEditorPreview();
  366. }
  367. }
  368. get fsrEnable(): boolean {
  369. return this._settings.fsr.enabled;
  370. }
  371. @property({
  372. group: { id: 'FSR', name: 'FidelityFX Super Resolution', style: 'section' },
  373. type: Material,
  374. })
  375. set fsrMaterial(value: Material) {
  376. if (this._settings.fsr.material === value) {
  377. return;
  378. }
  379. this._settings.fsr.material = value;
  380. if (EDITOR) {
  381. this._tryEnableEditorPreview();
  382. }
  383. }
  384. get fsrMaterial(): Material {
  385. return this._settings.fsr.material!;
  386. }
  387. @property({
  388. group: { id: 'FSR', name: 'FidelityFX Super Resolution', style: 'section' },
  389. type: CCFloat,
  390. range: [0, 1, 0.01],
  391. slide: true,
  392. })
  393. set fsrSharpness(value: number) {
  394. this._settings.fsr.sharpness = value;
  395. }
  396. get fsrSharpness(): number {
  397. return this._settings.fsr.sharpness;
  398. }
  399. @property({
  400. group: { id: 'ToneMapping', name: 'ToneMapping', style: 'section' },
  401. type: Material,
  402. })
  403. set toneMappingMaterial(value: Material) {
  404. if (this._settings.toneMapping.material === value) {
  405. return;
  406. }
  407. this._settings.toneMapping.material = value;
  408. if (EDITOR) {
  409. this._tryEnableEditorPreview();
  410. }
  411. }
  412. get toneMappingMaterial(): Material {
  413. return this._settings.toneMapping.material!;
  414. }
  415. }