Skip to content

Understanding building / accessing a material map in an abstract way inside a Fn function without passing an argument #31173

@Samsy

Description

@Samsy

Description

As far as my understanding goes :

Assigning a pre-computed Fn into a node like colorNode then to a bunch of materials reduces dramatically the building time of a node per material since it's been " pre-computed "

Like :

export const colorNode = Fn( ([color] ) => {
  
  var c = materialColor.toVar();

  c.r.assign(0.0);

  return c;
})()

material.colorNode = colorNode
material2.colorNode = colorNode
material3.colorNode = colorNode

etc..

Assigning a non computed Fn into a node, increases building time X materials required to be built :

Image

Fiddle example

export const textureNode = /*#__PURE__*/ Fn( ( [uu, map ]  ) => {
  
  var coord0 = uu.toVar();
  coord0.x.addAssign(-0.1)

  var coord1 = uu.toVar();

  var coord2 = uu.toVar();
  coord2.x.addAssign(0.1)

  var c  = texture( map, coord0 ).toVar()

  var c2 = texture( map, coord1 ).toVar()

  var c3 = texture( map, coord2 ).toVar()

  var final = vec4( c.r, c2.g, c3.b, 1.0 );

  return final;
})


material.colorNode = textureNode( uv(), material.map ); 

I've got a use-case here where in which I build for example a RGB shift colorNode
That takes in a texture as arg of a Fn

My question is, how can I build this node so it can be pre-computed once ? and re-usable by any material that has any maps ?

The material is the same for all the meshes in the scene, and would just need to assign a pre-computed Fn into the colorNode directly, but unfortunately, on build time it goes through an expensive builder for first render as it need to re-build the node for each, even though this is the same one

Is there a way to access the material.map but in an abstract way without passing it to the Fn argurment, but more as a reference like the materialColor etc.. but like materialMap ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    TSLThree.js Shading Language

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions