|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <title>Screen Shader Material</title>
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- Import maps polyfill -->
- <!-- Remove this when import maps will be widely supported -->
- <script async src="https://unpkg.com/es-module-shims@1.6.3/dist/es-module-shims.js"></script>
-
- <script type="importmap">
- {
- "imports": {
- "threepipe": "./../../dist/index.mjs",
- "@threepipe/plugin-tweakpane": "./../../plugins/tweakpane/dist/index.mjs"
- }
- }
-
- </script>
- <style id="example-style">
- html, body, #canvas-container, #mcanvas {
- width: 100%;
- height: 100%;
- margin: 0;
- overflow: hidden;
- }
- </style>
- <script type="module" src="../examples-utils/global-loading.mjs"></script>
- <script type="module" src="../examples-utils/simple-code-preview.mjs"></script>
- <script id="example-script" type="module">
- import {_testFinish, _testStart, ThreeViewer, Color, ExtendedShaderMaterial, CopyShader, FrontSide, NoBlending} from 'threepipe'
- import {TweakpaneUiPlugin} from "@threepipe/plugin-tweakpane"
-
- // Set a custom screen shader to render final image.
- // 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.
- // Checkout the ScreenPass guide for more details: https://threepipe.org/docs/guides/screen-pass
- const viewer = new ThreeViewer({
- canvas: document.getElementById('mcanvas'),
- tonemap: true,
- screenShader: new ExtendedShaderMaterial({
- ...CopyShader,
- // 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
- fragmentShader: `
- #include <packing>
-
- varying vec2 vUv;
- uniform vec3 tintColor;
-
- void main() {
-
- vec4 diffuseColor = tDiffuseTexelToLinear (texture2D(tDiffuse, vUv));
-
- #glMarker
-
- diffuseColor.rgb *= tintColor;
-
- gl_FragColor = diffuseColor;
- #include <colorspace_fragment>
- }
- `,
- uniforms: {
- tDiffuse: {value: null},
- tTransparent: {value: null},
- tintColor: {value: new Color(0, 1, 0)},
- },
- transparent: true,
- blending: NoBlending,
- side: FrontSide,
- } /*as ShaderMaterialParameters*/, ['tDiffuse', 'tTransparent'])
- })
-
- async function init() {
- viewer.scene.backgroundColor.set(0)
-
- await viewer.setEnvironmentMap('https://threejs.org/examples/textures/equirectangular/venice_sunset_1k.hdr')
-
- await viewer.load('https://threejs.org/examples/models/gltf/DamagedHelmet/glTF/DamagedHelmet.gltf', {
- autoCenter: true,
- autoScale: true,
- })
-
- // Add the color to the UI
- const ui = viewer.addPluginSync(TweakpaneUiPlugin, true)
- ui.appendChild({
- type: 'color',
- property: [viewer.renderManager.screenPass.material.uniforms.tintColor, 'value'],
- label: 'Tint Color',
- description: 'Change the tint color applied to the final rendered image.',
- onChange: ()=>{
- viewer.setDirty()
- }
- })
-
- }
-
- _testStart()
- init().finally(_testFinish)
- </script>
- </head>
- <body>
- <div id="canvas-container">
- <canvas id="mcanvas"></canvas>
- </div>
-
- </body>
|