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

Adding triplanar mapping #15048

Closed
Fyrestar opened this issue Oct 13, 2018 · 9 comments
Closed

Adding triplanar mapping #15048

Fyrestar opened this issue Oct 13, 2018 · 9 comments

Comments

@Fyrestar
Copy link

This would be a useful feature to have by default, besides terrains, when sculpting shapes or using primitives to construct a scene. It currently requires to generate a geometry with proper UV coordinates.

I'd suggest local and global mapping, since organic textures work fine for mixed axes and will then seamlessly mix with intersecting objects.

I've implemented it with a mapping property on the material which is by default THREE.UVMapping, in setProgram i set a modelScale uniform for local mapping.

https://mevedia.com/img/triplanar.mp4

@mrdoob mrdoob added this to the rXX milestone Oct 16, 2018
@mrdoob
Copy link
Owner

mrdoob commented Oct 16, 2018

Sounds good to me. Should it be THREE.TriplanarMapping?

@mrdoob
Copy link
Owner

mrdoob commented Oct 16, 2018

Actually, it may be tricky to implement in the current material/texture API design, but maybe it's easier in the node material design?

/ping @sunag

@sunag
Copy link
Collaborator

sunag commented Oct 16, 2018

but maybe it's easier in the node material design?

Certainly is more easier creating a node for this... and follow the code bellow TriplanarMapping is not only a UV change it should be liked to texture for the blending:

https://github.com/keijiro/StandardTriplanar/blob/33544a08761f8f028f5e76785c697ad3df7370e4/Assets/Triplanar/Shaders/StandardTriplanar.shader#L65-L76

@sunag
Copy link
Collaborator

sunag commented Oct 16, 2018

Maybe something like:

var tex = new THREE.TriplanarTextureNode( texture, uv );

@sunag
Copy link
Collaborator

sunag commented Oct 16, 2018

I've implemented it with a mapping property on the material which is by default THREE.UVMapping, in setProgram i set a modelScale uniform for local mapping.

The approach of the video would be something like:?

var uvModelScale = new THREE.OperatorNode(
	new THREE.UVNode(),
	new THREE.Vector3Node( model.scale ),
	THREE.OperatorNode.MUL
);

@Fyrestar
Copy link
Author

I've implemented it in the THREE shader chunks (the video), for every map type there is just simple #ifdef either using texture2D or textureTriplanar. It's also required to either pass the worldPosition or localPosition ( position * modelScale ). The normal used for blending also needs to be passed in the right space either object or world.

This technique uses the planes of all axes and a texture sample per axis and blends them by the normal. All core changes it required where in the WebGLRenderer.js setProgram for the model scale uniform if the material uses triplanar mapping and in WebGLProgram.js setting the mapping constant of the material in the fragment header.

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 23, 2021

Since there is a node example demonstrating triplanar mapping, this issue can be closed. This approach will also be possible with the new material system.

@Mugen87 Mugen87 closed this as completed Mar 23, 2021
@Mugen87 Mugen87 removed this from the rXXX milestone Mar 23, 2021
@ghost
Copy link

ghost commented Mar 4, 2022

@Mugen87 Hi Michael, I could not see the triplanar example you are talking about,

Could you please clarify?

Thanks

@Mugen87
Copy link
Collaborator

Mugen87 commented Mar 5, 2022

The mentioned example is not available anymore since it depended on the "old" node material which was removed with r138. Over time there will be a new example that shows how to do this with the "new" node system.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants