threepipe
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

index.html 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Screen Shader Advanced</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <!-- Import maps polyfill -->
  8. <!-- Remove this when import maps will be widely supported -->
  9. <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
  10. <script type="importmap">
  11. {
  12. "imports": {
  13. "threepipe": "./../../dist/index.mjs",
  14. "@threepipe/plugin-tweakpane": "./../../plugins/tweakpane/dist/index.mjs"
  15. }
  16. }
  17. </script>
  18. <style id="example-style">
  19. html, body, #canvas-container, #mcanvas {
  20. width: 100%;
  21. height: 100%;
  22. margin: 0;
  23. overflow: hidden;
  24. }
  25. </style>
  26. <script type="module" src="../examples-utils/global-loading.mjs"></script>
  27. <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
  28. <script id="example-script" type="module">
  29. import {_testFinish, _testStart, ThreeViewer, Color} from 'threepipe'
  30. import {TweakpaneUiPlugin} from "@threepipe/plugin-tweakpane"
  31. // Set a custom screen shader snippet to modify the final rendered image.
  32. // Here, `diffuseColor` is the final color of the pixel which can be modified.
  33. // This happens before the final post-processing effects(like tonemap, vignette, film-grain etc.) are applied.
  34. // Checkout the ScreenPass guide for more details: https://threepipe.org/docs/guides/screen-pass
  35. const viewer = new ThreeViewer({
  36. canvas: document.getElementById('mcanvas'),
  37. screenShader: {
  38. pars: ` // this is added before the main function
  39. uniform vec3 tintColor;
  40. vec4 applyTint(vec4 color) {
  41. return vec4(color.rgb * tintColor, color.a);
  42. }
  43. `,
  44. main: ` // this is added inside the main function
  45. diffuseColor = applyTint(diffuseColor);
  46. `
  47. }
  48. })
  49. // add the uniform js reference to the screen pass material
  50. viewer.renderManager.screenPass.material.uniforms.tintColor = {
  51. value: new Color(0, 0, 1) // blue tint
  52. }
  53. async function init() {
  54. viewer.scene.backgroundColor.set(0)
  55. await Promise.all([
  56. viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr'),
  57. viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  58. autoCenter: true,
  59. autoScale: true,
  60. })])
  61. // Add the color to the UI
  62. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  63. ui.appendChild({
  64. type: 'color',
  65. property: [viewer.renderManager.screenPass.material.uniforms.tintColor, 'value'],
  66. label: 'Tint Color',
  67. description: 'Change the tint color applied to the final rendered image.',
  68. onChange: ()=>{
  69. viewer.setDirty()
  70. }
  71. })
  72. }
  73. _testStart()
  74. init().finally(_testFinish)
  75. </script>
  76. </head>
  77. <body>
  78. <div id="canvas-container">
  79. <canvas id="mcanvas"></canvas>
  80. </div>
  81. </body>