threepipe
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

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 viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  56. await viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  57. autoCenter: true,
  58. autoScale: true,
  59. })
  60. // Add the color to the UI
  61. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  62. ui.appendChild({
  63. type: 'color',
  64. property: [viewer.renderManager.screenPass.material.uniforms.tintColor, 'value'],
  65. label: 'Tint Color',
  66. description: 'Change the tint color applied to the final rendered image.',
  67. onChange: ()=>{
  68. viewer.setDirty()
  69. }
  70. })
  71. }
  72. _testStart()
  73. init().finally(_testFinish)
  74. </script>
  75. </head>
  76. <body>
  77. <div id="canvas-container">
  78. <canvas id="mcanvas"></canvas>
  79. </div>
  80. </body>