BabylonJS / Babylon.js

Babylon.js is a powerful, beautiful, simple, and open game and rendering engine packed into a friendly JavaScript framework.
http://www.babylonjs.com
Apache License 2.0
23.31k stars 3.44k forks source link

NME custom Attributes #12549

Closed sebavan closed 2 years ago

sebavan commented 2 years ago

It would be great to have the possibility to use custom attributes through the NME editor.

It is currently possible by code in the NodeMaterial input block but not through the editor.

https://forum.babylonjs.com/t/how-to-make-nme-material-for-thin-instances-with-color-attribute/30469/6?u=sebavan

carolhmj commented 2 years ago

@sebavan @PatrickRyanMS for this, would changing the Attribute line on the NME from Options to a Text Input suffice? image

sebavan commented 2 years ago

Almost :-) It would also require a new mode being Custom Attribute and only in this mode having a text input.

PatrickRyanMS commented 2 years ago

How would the custom attribute get used in NME? And how do we preview it? For shaders that deal with things like vertex color, we need to load in a preview model with vertex color. But how are we handling custom attributes?

carolhmj commented 2 years ago

I think we don't need to preview custom attributes, as we won't know what they are beforehand.

deltakosh commented 2 years ago

And if the user wants to test they can drop their own mesh in the preview window anyway

PatrickRyanMS commented 2 years ago

And if the user wants to test they can drop their own mesh in the preview window anyway

This is where I am confused. If it's a custom parameter and we don't know what it's for, how do we apply it to a user-provided mesh? Especially if it's a parameter for something like a thin instance where the meshes rendered in the preview window are not thin instances. I agree that we can't render something we don't know how to handle, but is that distinction ok since NME stand-alone does not have a scene attached and there is no way to validate what any custom parameter is doing until you attach it to a scene? At minimum, we should probably put some language in the parameters panel of a custom parameter that we do not render the results of custom parameters in the preview window.

philharlow commented 2 years ago

In case this helps anyone, I found a workaround for my situation by using a normal input block with this snippet:

const selectedBlock = nodeMaterial.getBlockByName("selected");
if (selectedBlock instanceof BABYLON.InputBlock) {
  selectedBlock.setAsAttribute("selected");
  nodeMaterial.build();
}
carolhmj commented 2 years ago

Especially if it's a parameter for something like a thin instance where the meshes rendered in the preview window are not thin instances.

You have a good point on this, maybe we should at least add an option on the drop down to render a few instances/thin instances so the user could preview shaders that vary per instance 🤔

deltakosh commented 2 years ago

Closing for now as there is a way to do it by code and doing it in NME does not provide additional benefit