viewportSharedTexture
Provides a globally shared, unique viewport texture instance, allowing multiple independent materials or effects to efficiently access the same screen render result, avoiding resource redundancy.
Core Advantages
Ensures that only one viewport texture exists throughout the entire rendering pipeline, regardless of how many effects need to read the screen, thus greatly saving GPU memory and bandwidth and significantly improving performance.
Common Uses
Multiple independent refractive/transparent materials
Mixing material effects with post-processing
Dynamic UI background blur
How to adjust
It is adjusted in the same way as other viewport texture nodes, primarily by changing its `uvNode` (sampling position) and `levelNode` (sampling clarity/Mipmap level). For example, use distorted UVs for distortion effects, or a higher `level` for efficient background blurring.
Code Examples
1// Effect A (e.g., an invert-color material):
2// Directly sample the shared texture and invert its color
3const colorA = viewportSharedTexture().rgb.oneMinus();
4
5// Effect B (e.g., a refraction material):
6// Sample from the same shared texture using distorted UVs
7const distortedUV = screenUV().add( normalWorld.xy.mul( 0.1 ) );
8const colorB = viewportSharedTexture( distortedUV );