Hello, I’d like to know, if it is possible to use the world position as the uv coordinates for a procedural noise texture? so that it doesn’t rely on the uv map. and if it is possibly, how to?
and i’d like to know if and how to use this noise texture as a bump map
how would i do this? is this done by using NoiseProceduralTexture setVector3?
and using the noise texture directly as the bump texture obviously doesn’t work like intended. what is that perturbation block? i am using javascript, no node editor.
You probably need to use either a NodeMaterial and use the world position as input of the noise block, or use a ShaderMaterial and there you can use your own noise function. You will probably have an easier time win a NodeMaterial though. Here is a simple example:
ok. thank you. i’ll check that out. where are those node materials stored? should i generate code when i am done? or is it just save to import them as you did in your playground example?
No problem Right now the material is stored on Babylon’s server, but you can export either the code or the corresponding json for loading locally without internet.
You can also build your NodeMaterial by code Babylon.js docs or using something like BSL if you don’t want to use a visual editor
that’s what i’d like to. because i don’t really need anything fancy. just a bumpy normal map. i find it a bit inconvinient to have quite a bunch of code describing a node setup, instead of having some simple functions to directly convert a heightmap to a normal map, or to set the coordinates of a procedural noise texture.
but i am new to babylon.js, so maybe that’s just the way it is.
To make a normal map from your bump map, you can use an offline solution: NormalMap-Online
If you want to convert your heightmap into a normal map in realtime, that’s completely doable be we are no longer in the realm of “nothing fancy, just simple functions” ^^
Now if you want to change texture coordinates for the procedural texture you already have, you can do so like this:
the problem is, that i don’t want to rely on uv coordinates for the texture. i thought it would be nice to use a noise texture using the object coordinates for the bump map. i do this in blender all the time and it is very convenient, because you don’t need to care about uv mapping in that case at all.
in the example you have that streching at the top and the bottom, which simply wouln’t exist if the noise textures coordinates where taken from the object positions.
having a normal map texture requires a proper uv layout. maybe i need to bake the textures in blender and use that. i just though with procedural textures i could keep the file sizes to a minimum.
I am not sure I get what you are after, just to be sure we are on the same page:
You want to sample a bump map using world coordinates + noise i.e color = texture(bumpMap, worldPos + noise) ?
because you don’t need to care about uv mapping in that case at all.
For uv-less mapping, you also have tri-planar mapping available: Babylon.js docs
in the example you have that streching at the top and the bottom, which simply wouln’t exist if the noise textures coordinates where taken from the object positions.
That’s because the procedural texture is 2d, while you need a 3d texture indeed. The NodeMaterial example I shared with you supports 3d noise, but I am not sure there is a 3d equivalent to NoiseProceduralTexture.
Using NodeMaterial’s PerturbNormal block, you can perturb the existing normal without uvs, as long as you know how to sample your normal map
no, i’d like to retrieve get the noise texture value at the objects position.
in blender, i normally take the texture coordinate node and use it’s object output as the input of the noise texture node. this guarantees perfect distribution of the texture along all kind of meshes. it just works.
i’ll have a look at that triplanar mapping. and probably need to dive a bit deeper into this shader programming. i just thought maybe there was an easy way to achive that look i am going for.
and now that you mentioned the NoiseProceduralTexture is 2d, it makes complete sense, that it doesn’t work like i’d want it to.
Given the images you showed, I think a triplanar material with your noise textures will work just fine. Otherwise, I am getting quite close with a NodeMaterial:
after experimenting a bit, i came along a strange behaviour. it seems, that the normals are somehow rotated, since the lighting direction seems to be off. what could cause this?
I noticed that as well You can instead apply scaling to your noise to control the perturbation strength. For the lighting direction, I am not sure, but @Evgeni_Popov might know something about this as well ^^
Indeed, when using object space, strength is not used by the fragment code.
Regarding the normal, the normalMapColor input expects a normal with [0,1] coordinates and not [-1, 1], because this input generally comes from a normal map, which has components between 0 and 1. So, you have to remap the output of HeightToNormal to the [0,1] range.
Also, I think because it’s in object space, the result depends on the determinant of the object world matrix. For glTF objects, you should multiply the output of HeightToNormal by (-1,1,1) to compensate for the special “root” node we add when the object is loaded. Note that in the preview window of NME, all objects comes from a glTF file, BUT we bake the current transformation for the sphere and cube objects, which means that you don’t need the correction for these two objects!