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

Nodes: Optional varying interpolation #24821

Merged
merged 4 commits into from
Oct 21, 2022
Merged

Nodes: Optional varying interpolation #24821

merged 4 commits into from
Oct 21, 2022

Conversation

sunag
Copy link
Collaborator

@sunag sunag commented Oct 19, 2022

Related issue: #24410

Description

NodeMaterial is interchangeable and uses nodes as elements to build other nodes. When you do this using varying it can generate some unnecessary varyings for the final result, for example: If you use a normalWorld, this will call normalView which also uses a varying. This generated varyings that were not used.

This update checks which shader stage varying is being used to see if interpolation is really needed, and if not, it automatically converts to a simple variable.

WebGPU

webgpu_cubemap_adjustments.html

After

// varyings
struct NodeVaryingsStruct {
	@location( 1 ) nodeVarying1 : vec2<f32>,
	@location( 2 ) nodeVarying2 : vec3<f32>,
	@location( 3 ) nodeVarying3 : vec4<f32>,
	@location( 4 ) nodeVarying4 : vec3<f32>,
	@location( 6 ) nodeVarying6 : vec3<f32>,
	@location( 8 ) nodeVarying8 : vec3<f32>,
	@location( 9 ) nodeVarying9 : vec3<f32>,
	@builtin( position ) Vertex : vec4<f32>
};

// vars
var nodeVarying0 : vec3<f32>;
var nodeVarying5 : vec3<f32>;
var nodeVarying7 : vec4<f32>;
var nodeVarying10 : vec3<f32>;

Before

// varyings
struct NodeVaryingsStruct {
	@location( 0 ) nodeVarying0 : vec3<f32>,
	@location( 1 ) nodeVarying1 : vec2<f32>,
	@location( 2 ) nodeVarying2 : vec3<f32>,
	@location( 3 ) nodeVarying3 : vec4<f32>,
	@location( 4 ) nodeVarying4 : vec3<f32>,
	@location( 5 ) nodeVarying5 : vec3<f32>,
	@location( 6 ) nodeVarying6 : vec3<f32>,
	@location( 7 ) nodeVarying7 : vec4<f32>,
	@location( 8 ) nodeVarying8 : vec3<f32>,
	@location( 9 ) nodeVarying9 : vec3<f32>,
	@location( 10 ) nodeVarying10 : vec3<f32>,
	@builtin( position ) Vertex : vec4<f32>
};

// vars

WebGL

webgl_nodes_materials_standard.html

After

// varyings
varying vec2 nodeVarying0;
varying vec4 nodeVarying1;
/*varying*/ vec3 nodeVarying2;
varying vec3 nodeVarying3;
/*varying*/ vec3 nodeVarying4; 

Before

// varyings
varying vec2 nodeVarying0;
varying vec4 nodeVarying1;
varying vec3 nodeVarying2;
varying vec3 nodeVarying3;
varying vec3 nodeVarying4; 

This contribution is funded by Google

@sunag sunag added this to the r146 milestone Oct 19, 2022

snippets.push( `@location( ${index} ) ${ varying.name } : ${ this.getType( varying.type ) }` );

} else if ( vars.includes( varying ) === false ) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use sets for vars?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's better to work with indexing in vars, since that sets would only be for a specific case.

@sunag sunag merged commit 0f89c6c into mrdoob:dev Oct 21, 2022
@sunag sunag deleted the dev-varying-opt branch October 27, 2022 07:14
@joshuaellis joshuaellis mentioned this pull request Oct 31, 2022
19 tasks
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.

2 participants