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

TSL: Adding toType conversion #28344

Merged
merged 2 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion examples/jsm/nodes/functions/PhysicalLightingModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ const evalIridescence = tslFn( ( { outsideIOR, eta2, cosTheta1, thinFilmThicknes

// Second interface
const baseIOR = Fresnel0ToIor( baseF0.clamp( 0.0, 0.9999 ) ); // guard against 1.0
const R1 = IorToFresnel0( baseIOR, iridescenceIOR.vec3() );
const R1 = IorToFresnel0( baseIOR, iridescenceIOR.toVec3() );
const R23 = F_Schlick( { f0: R1, f90: 1.0, dotVH: cosTheta2 } );
const phi23 = vec3(
baseIOR.x.lessThan( iridescenceIOR ).cond( Math.PI, 0.0 ),
Expand Down
4 changes: 2 additions & 2 deletions examples/jsm/nodes/math/HashNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ class HashNode extends Node {

// Taken from https://www.shadertoy.com/view/XlGcRh, originally from pcg-random.org

const state = this.seedNode.uint().mul( 747796405 ).add( 2891336453 );
const state = this.seedNode.toUint().mul( 747796405 ).add( 2891336453 );
const word = state.shiftRight( state.shiftRight( 28 ).add( 4 ) ).bitXor( state ).mul( 277803737 );
const result = word.shiftRight( 22 ).bitXor( word );

return result.float().mul( 1 / 2 ** 32 ); // Convert to range [0, 1)
return result.toFloat().mul( 1 / 2 ** 32 ); // Convert to range [0, 1)

}

Expand Down
60 changes: 29 additions & 31 deletions examples/jsm/nodes/shadernode/ShaderNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -586,37 +586,35 @@ export const bmat4 = new ConvertType( 'bmat4' );
export const string = ( value = '' ) => nodeObject( new ConstNode( value, 'string' ) );
export const arrayBuffer = ( value ) => nodeObject( new ConstNode( value, 'ArrayBuffer' ) );

addNodeElement( 'color', color );
addNodeElement( 'float', float );
addNodeElement( 'int', int );
addNodeElement( 'uint', uint );
addNodeElement( 'bool', bool );
addNodeElement( 'vec2', vec2 );
addNodeElement( 'ivec2', ivec2 );
addNodeElement( 'uvec2', uvec2 );
addNodeElement( 'bvec2', bvec2 );
addNodeElement( 'vec3', vec3 );
addNodeElement( 'ivec3', ivec3 );
addNodeElement( 'uvec3', uvec3 );
addNodeElement( 'bvec3', bvec3 );
addNodeElement( 'vec4', vec4 );
addNodeElement( 'ivec4', ivec4 );
addNodeElement( 'uvec4', uvec4 );
addNodeElement( 'bvec4', bvec4 );
addNodeElement( 'mat2', mat2 );
addNodeElement( 'imat2', imat2 );
addNodeElement( 'umat2', umat2 );
addNodeElement( 'bmat2', bmat2 );
addNodeElement( 'mat3', mat3 );
addNodeElement( 'imat3', imat3 );
addNodeElement( 'umat3', umat3 );
addNodeElement( 'bmat3', bmat3 );
addNodeElement( 'mat4', mat4 );
addNodeElement( 'imat4', imat4 );
addNodeElement( 'umat4', umat4 );
addNodeElement( 'bmat4', bmat4 );
addNodeElement( 'string', string );
addNodeElement( 'arrayBuffer', arrayBuffer );
addNodeElement( 'toColor', color );
addNodeElement( 'toFloat', float );
addNodeElement( 'toInt', int );
addNodeElement( 'toUint', uint );
addNodeElement( 'toBool', bool );
addNodeElement( 'toVec2', vec2 );
addNodeElement( 'toIvec2', ivec2 );
addNodeElement( 'toUvec2', uvec2 );
addNodeElement( 'toBvec2', bvec2 );
addNodeElement( 'toVec3', vec3 );
addNodeElement( 'toIvec3', ivec3 );
addNodeElement( 'toUvec3', uvec3 );
addNodeElement( 'toBvec3', bvec3 );
addNodeElement( 'toVec4', vec4 );
addNodeElement( 'toIvec4', ivec4 );
addNodeElement( 'toUvec4', uvec4 );
addNodeElement( 'toBvec4', bvec4 );
addNodeElement( 'toMat2', mat2 );
addNodeElement( 'toImat2', imat2 );
addNodeElement( 'toUmat2', umat2 );
addNodeElement( 'toBmat2', bmat2 );
addNodeElement( 'toMat3', mat3 );
addNodeElement( 'toImat3', imat3 );
addNodeElement( 'toUmat3', umat3 );
addNodeElement( 'toBmat3', bmat3 );
addNodeElement( 'toMat4', mat4 );
addNodeElement( 'toImat4', imat4 );
addNodeElement( 'toUmat4', umat4 );
addNodeElement( 'toBmat4', bmat4 );

// basic nodes
// HACK - we cannot export them from the corresponding files because of the cyclic dependency
Expand Down
2 changes: 1 addition & 1 deletion examples/jsm/nodes/utils/TimerNode.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,6 @@ export default TimerNode;
export const timerLocal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.LOCAL, timeScale, value ) );
export const timerGlobal = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.GLOBAL, timeScale, value ) );
export const timerDelta = ( timeScale, value = 0 ) => nodeObject( new TimerNode( TimerNode.DELTA, timeScale, value ) );
export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME ).uint();
export const frameId = nodeImmutable( TimerNode, TimerNode.FRAME ).toUint();

addNodeClass( 'TimerNode', TimerNode );