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

InputNode: Added .setPrecision() #25561

Merged
merged 2 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions examples/jsm/nodes/core/InputNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class InputNode extends Node {
this.isInputNode = true;

this.value = value;
this.precision = 'medium';

}

Expand All @@ -31,6 +32,14 @@ class InputNode extends Node {

}

setPrecision( precision ) {

this.precision = precision;

return this;

}

serialize( data ) {

super.serialize( data );
Expand All @@ -42,6 +51,8 @@ class InputNode extends Node {
data.valueType = getValueType( this.value );
data.nodeType = this.nodeType;

data.precision = this.precision;

}

deserialize( data ) {
Expand All @@ -51,6 +62,8 @@ class InputNode extends Node {
this.nodeType = data.nodeType;
this.value = Array.isArray( data.value ) ? getValueFromType( data.valueType, ...data.value ) : data.value;

if ( data.precision !== undefined ) this.precision = data.precision;

if ( this.value && this.value.fromArray ) this.value = this.value.fromArray( data.value );

}
Expand Down
32 changes: 27 additions & 5 deletions examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ const glslMethods = {
[ MathNode.ATAN2 ]: 'atan'
};

const precisionLib = {
low: 'lowp',
medium: 'mediump',
high: 'highp'
};

function getIncludeSnippet( name ) {

return `#include <${name}>`;
Expand Down Expand Up @@ -460,29 +466,45 @@ class WebGLNodeBuilder extends NodeBuilder {

const uniforms = this.uniforms[ shaderStage ];

let snippet = '';
let output = '';

for ( const uniform of uniforms ) {

let snippet = null;

if ( uniform.type === 'texture' ) {

snippet += `uniform sampler2D ${uniform.name}; `;
snippet = `sampler2D ${uniform.name}; `;

} else if ( uniform.type === 'cubeTexture' ) {

snippet += `uniform samplerCube ${uniform.name}; `;
snippet = `samplerCube ${uniform.name}; `;

} else {

const vectorType = this.getVectorType( uniform.type );

snippet += `uniform ${vectorType} ${uniform.name}; `;
snippet = `${vectorType} ${uniform.name}; `;

}

const precision = uniform.node.precision;

if ( precision !== 'medium' ) {

snippet = 'uniform ' + precisionLib[ precision ] + ' ' + snippet;
sunag marked this conversation as resolved.
Show resolved Hide resolved

} else {

snippet = 'uniform ' + snippet;

}

output += snippet;

}

return snippet;
return output;

}

Expand Down