Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transpiler: Improve tree shaking support #28707

Merged
merged 2 commits into from
Jun 20, 2024
Merged

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Jun 20, 2024

Description

Added PURE and inline setLayout() making it more compatible with tree shaking.

import { pow2, float, sub, sqrt, EPSILON, max, div, tslFn } from 'three/nodes';

export const V_GGX_SmithCorrelated = /*#__PURE__*/ tslFn( ( [ alpha, dotNL, dotNV ] ) => {

	const a2 = float( pow2( alpha ) ).toVar();
	const gv = float( dotNL.mul( sqrt( a2.add( sub( 1.0, a2 ).mul( pow2( dotNV ) ) ) ) ) ).toVar();
	const gl = float( dotNV.mul( sqrt( a2.add( sub( 1.0, a2 ).mul( pow2( dotNL ) ) ) ) ) ).toVar();

	return div( 0.5, max( gv.add( gl ), EPSILON ) );

} ).setLayout( {
	name: 'V_GGX_SmithCorrelated',
	type: 'float',
	inputs: [
		{ name: 'alpha', type: 'float', qualifier: 'in' },
		{ name: 'dotNL', type: 'float', qualifier: 'in' },
		{ name: 'dotNV', type: 'float', qualifier: 'in' }
	]
} );

@sunag sunag added WebGPU TSL Three.js Shading Language labels Jun 20, 2024
@sunag sunag added this to the r166 milestone Jun 20, 2024
@sunag sunag marked this pull request as ready for review June 20, 2024 15:56
@sunag sunag merged commit 01dc3d9 into mrdoob:dev Jun 20, 2024
11 checks passed
@sunag sunag deleted the dev-tsl-encoder branch June 20, 2024 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
TSL Three.js Shading Language WebGPU
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant