Blending materials objects with terrain in game

Hello everyone - I would like to ask - on blenderartist there is a topic on dynamic mixing of materials of objects with a terrain - the beginning of the discussion was a post about the distance fields used for this in an unreal engine - I tried to make my own implementation but still could not mix normals and AO between two objects - and I cheated a little, I assign the degree of mixing to the vertexes of the object coloring it works, but it doesn’t work when mixing normals - I’m surprised that this topic is not covered in the game engine section - Hey, can you help me? - Blending terrain and objects - #2 by RSEhlers , and actually I wonder if it is still possible to mix the normals of objects and ambient at the intersection of the object with the terrain, or will you have to write a shader for this, as does the unreal engine and the unity engine? I think that a simple implementation of such a technique would allow many developers to mix objects with terrain without worrying about seams or intersection boundaries that spoil the view and would allow them to attract more audience who would be interested in the UPBGE/Range engine - if anyone is interested, I can upload my file, which is a simple experiment (изменено)


Assuming the object is always going to be aligned to a plane, flat or slope, the normal of the object could be mixed to an object-aligned ‘up’ normal, that will match the plane the object is placed on.


The normals are inverted in Blender Internal/GLSL viewport shading, that’s why an upwards normal vector is (0.0, 0.0, -1.0).
This also assumes the terrain does not have normal maps.

2 Likes

Hi, thanks for this information, this is very useful information, but I assume that at the game level there will not be a perfectly flat terrain surface - there will always be hills, pits, and some kind of relief - what then? as far as I know, in an unreal engine, distance fields work with any terrain and any inclination of objects - is this possible in the UPBGE game engine? and using normal maps of objects and mixing them with the terrain is also an important part if the developer makes a game with elements of even a little realism - detailing the terrain in this case will be an important part - perhaps there is a way to combine the normal of the map of objects and the actual normal of objects through the nodes of the mix? Thank you for giving me the information to think about, I’ll try to combine it all



Your solution is very interesting - the only thing it doesn’t always work for me since I use a sphere for a planet (maybe I’m doing something wrong myself), but it’s definitely better than my attempts to mix the numbers of objects with nodes, I’ll try to add shaders such as bloom, chromatic abberation in the future, maybe they will smooth out the places even more transitions and intersections of objects - thank you for your help, I really appreciate it

The normal of a surface point on a sphere is always the normalized direction vector from the center of the sphere to said point, with that said:

The direction vector averaged with a zero length vector (0.0, 0.0, 0.0) will output the length of the vector from the value socket. The length is the distance from the center to the point, subtracting the radius of the sphere will give 0.0 at the surface, providing a blend gradient that can be used to control the mix factor, so no vertex colors are needed.

2 Likes

Thanks for explaining all these things related to nodes, today I tried again to cheat and get normals through the code and set the normals at the object at the intersection by throwing rays from the vertices of objects - it seems to work the same way, but my triplanar projection of the planet is not very well done - because at sharp angles on objects the texture stretches - that It doesn’t look very nice, but I’ll think about how to remove it. I don’t want to use the texture node of the image from the loops since I can’t change its texture in the game and I use the texture node of the game mode since I can change these textures with a script so as not to keep a lot of planets in the file



This is what I managed to achieve using your first assembly of nodes and my simple script to mix normals and diffuse textures at the intersection of objects with the planet - thanks again, the script does not work as well separately from nodes as with nodes

If it is not difficult for you, can you tell me if it is possible to use normal maps and parallax maps in such node assemblies? they make the textures of the surface and objects more detailed and they can also be downloaded if, for example, the desert planet changes to an ice planet - that’s what I really want to achieve - even if I have to use scripts and nodes, then I want to post the finished file here and on the discord in the range engine theme so that any developer can mix surface objects with the landscape, this is what is in the Unity and Unreal engine, but not in the Range and UPBGE v.0.2.5 engine



I also noticed an interesting feature -if you normalize the vertices with a script to the lighting source in the scene, the quality of the shadows becomes better, as does the mixing of the model with the landscape itself - of course it is not idiotic and GLSL would fit much better here, but I am not strong in this programming language