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

NodeMaterial: ShaderNode updates #22644

Merged
merged 3 commits into from
Oct 5, 2021
Merged

NodeMaterial: ShaderNode updates #22644

merged 3 commits into from
Oct 5, 2021

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 5, 2021

Description

  • ContextNode: { cache : false } support -> to disable temp vars
  • CondNode: conditional node
  • ShaderNode: object input as params like FunctionCallNode
  • NormalMapNode: perturbNormal2ArbNode -> GLSL converted to ShaderNode
  • ShaderNode: more functions added
  • OperatorNode: Support for more than two argument value
  • OperatorNode: boolean support ==

NormalMapNode

Code comparison

ShaderNode

const perturbNormal2ArbNode = new ShaderNode( ( inputs ) => {

	const { eye_pos, surf_norm, mapN, faceDirection, uv } = inputs;

	// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988

	const q0 = join( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
	const q1 = join( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
	const st0 = dFdx( uv.st );
	const st1 = dFdy( uv.st );

	const N = surf_norm; // normalized

	const q1perp = cross( q1, N );
	const q0perp = cross( N, q0 );

	const T = add( mul( q1perp, st0.x ), mul( q0perp, st1.x ) );
	const B = add( mul( q1perp, st0.y ), mul( q0perp, st1.y ) );

	const det = max( dot( T, T ), dot( B, B ) );
	const scale = cond( equals( det, 0 ), 0, mul( faceDirection, inversesqrt( det ) ) );

	return normalize( add( mul( T, mul( mapN.x, scale ) ), mul( B, mul( mapN.y, scale ) ), mul( N, mapN.z ) ) );

} );

GLSL

export const perturbNormal2Arb = new FunctionNode( `
vec3 ( vec3 eye_pos, vec3 surf_norm, vec3 mapN, float faceDirection, const in vec2 uv ) {

	// Workaround for Adreno 3XX dFd*( vec3 ) bug. See #9988

	vec3 q0 = vec3( dFdx( eye_pos.x ), dFdx( eye_pos.y ), dFdx( eye_pos.z ) );
	vec3 q1 = vec3( dFdy( eye_pos.x ), dFdy( eye_pos.y ), dFdy( eye_pos.z ) );
	vec2 st0 = dFdx( uv.st );
	vec2 st1 = dFdy( uv.st );

	vec3 N = surf_norm; // normalized

	vec3 q1perp = cross( q1, N );
	vec3 q0perp = cross( N, q0 );

	vec3 T = q1perp * st0.x + q0perp * st1.x;
	vec3 B = q1perp * st0.y + q0perp * st1.y;

	float det = max( dot( T, T ), dot( B, B ) );
	float scale = ( det == 0.0 ) ? 0.0 : faceDirection * inversesqrt( det );

	return normalize( T * ( mapN.x * scale ) + B * ( mapN.y * scale ) + N * mapN.z );

}` );

This contribution is funded by Google via Igalia.

@mrdoob mrdoob added this to the r134 milestone Oct 5, 2021
@mrdoob mrdoob merged commit bd84a6d into mrdoob:dev Oct 5, 2021
@mrdoob
Copy link
Owner

mrdoob commented Oct 5, 2021

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants