threepipe
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Screen Shader Material</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, ExtendedShaderMaterial, CopyShader, FrontSide, NoBlending} from 'threepipe'
  30. import {TweakpaneUiPlugin} from "@threepipe/plugin-tweakpane"
  31. // Set a custom screen shader to render final image.
  32. // Here, `#glMarker` is defined for external plugins(like tonemap, vignette) to be able to extend the screen shader. They expect diffuseColor to be present in the context, and modify it accordingly.
  33. // Checkout the ScreenPass guide for more details: https://threepipe.org/docs/guides/screen-pass
  34. const viewer = new ThreeViewer({
  35. canvas: document.getElementById('mcanvas'),
  36. tonemap: true,
  37. screenShader: new ExtendedShaderMaterial({
  38. ...CopyShader,
  39. // Custom fragment shader. Note that this is not the default full shader, it needs to handle gbuffer, transparent target etc as well, checkout the full default shader - https://github.com/repalash/threepipe/blob/master/src/postprocessing/ScreenPass.glsl
  40. fragmentShader: `
  41. #include <packing>
  42. varying vec2 vUv;
  43. uniform vec3 tintColor;
  44. void main() {
  45. vec4 diffuseColor = tDiffuseTexelToLinear (texture2D(tDiffuse, vUv));
  46. #glMarker
  47. diffuseColor.rgb *= tintColor;
  48. gl_FragColor = diffuseColor;
  49. #include <colorspace_fragment>
  50. }
  51. `,
  52. uniforms: {
  53. tDiffuse: {value: null},
  54. tTransparent: {value: null},
  55. tintColor: {value: new Color(0, 1, 0)},
  56. },
  57. transparent: true,
  58. blending: NoBlending,
  59. side: FrontSide,
  60. } /*as ShaderMaterialParameters*/, ['tDiffuse', 'tTransparent'])
  61. })
  62. async function init() {
  63. viewer.scene.backgroundColor.set(0)
  64. await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
  65. await viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
  66. autoCenter: true,
  67. autoScale: true,
  68. })
  69. // Add the color to the UI
  70. const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
  71. ui.appendChild({
  72. type: 'color',
  73. property: [viewer.renderManager.screenPass.material.uniforms.tintColor, 'value'],
  74. label: 'Tint Color',
  75. description: 'Change the tint color applied to the final rendered image.',
  76. onChange: ()=>{
  77. viewer.setDirty()
  78. }
  79. })
  80. }
  81. _testStart()
  82. init().finally(_testFinish)
  83. </script>
  84. </head>
  85. <body>
  86. <div id="canvas-container">
  87. <canvas id="mcanvas"></canvas>
  88. </div>
  89. </body>