TSL: Introduce builtinAOContext and Enhance AO Post-Processing Example#32378
Conversation
…tml with transparent material support
📦 Bundle sizeFull ESM build, minified and gzipped.
🌳 Bundle size after tree-shakingMinimal build including a renderer, camera, empty scene, and dependencies.
|
There was a problem hiding this comment.
Pull request overview
This PR introduces a new TSL node materialTransparent that exposes a material's transparent property to shaders, and demonstrates its usage in the ambient occlusion post-processing example to properly handle transparent materials by disabling AO on them.
- Added
materialTransparentTSL node to access material transparency state in shaders - Enhanced the AO post-processing example to conditionally apply AO based on material transparency
- Added GUI controls to adjust transparent mesh opacity for better demonstration
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/nodes/accessors/MaterialProperties.js | Adds the new materialTransparent uniform node that tracks the material's transparent property |
| src/Three.TSL.js | Exports the new materialTransparent node in the TSL namespace (correctly alphabetized) |
| examples/webgpu_postprocessing_ao.html | Demonstrates materialTransparent usage by conditionally applying AO (value of 1 for transparent materials, sampled AO for opaque), adds transparent mesh to scene with opacity controls |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
|
Instead of using a uniform, I would like to modify three.js/src/materials/nodes/NodeMaterial.js Lines 1063 to 1077 in 77ebf27 Instead of const aoSample = aoPassOutput.sample( screenUV ).r;
scenePass.contextNode = context( {
getAO: ( node, { material } ) => {
if ( material.transparent === true ) return node;
return node !== null ? node.mul( aoSample ) : aoSample ;
}
} );I think to finish up we can create a internal(core) function to include the code above to use like: scenePass.contextNode = bultinAOContext( aoPassOutput.sample( screenUV ).r );The general idea is to eliminate the need for an additional uniform and, with the @Mugen87 I think we can do the same in the SSS example. const aoSample = aoPassOutput.sample( screenUV ).r,;
scenePass.contextNode = bultinShadowContext( aoSample, light ); |
|
Sounds good! Definitely a step in the right direction. |
…lTransparent export
|
@sunag I’ve just updated the PR. I’m still not completely confident I understand all of the context, though. |
|
I like how these new functions simplify the setup on app level. Even |
Overview
This PR introduces
a new TSL nodebuiltinAOContext and demonstrates its usage by improving the ambient occlusion post-processing example to properly handle transparent materials.materialTransparentThe PR is based on this PR: #32276 (Cc. @sunag)
Dev:
output.mp4
PR:
output1.mp4