good afternoon everyone, tell me how to correctly transfer data to the shader. The situation is the following - I need to select part of the terrain, for this, when selecting with the mouse, I transfer the coordinates to the shader, 4 variables (2 edges of the frame)
(from script)
TerrainMaterial.SetVector("_SelArea", new Vector4(z0, x0, z1, x1));
visually I get the desired result, the area is highlighted in the desired color, but when adjusting the frame, that is, changing the coordinates and transferring them to the shader, the FPS drops by 2-3 times, and if you also move the camera, everything happens in very large jerks.
What’s the best way to pass coordinates to the shader?
Well, firstly, it already works (probably it gets better during compilation), and secondly, it still doesn’t change the situation, the performance drop is the same…
Change Float to Vector did not lead to any changes.
I conducted a series of tests and settled on the fact that a sharp drop in FPS occurs precisely during the transfer of data to the shader. Initially, I transferred the value every frame since the adjustment came from mouse movement, then I set a limit on the transfer of data only when the coordinates change and at intervals of 0.2 seconds, but even with this, the FPS drops precisely during the data transfer, I note that I even disabled the use of these variables in the shader, all the same, but I don’t know how else to transfer coordinates to the shader…
I think I can guess what the problem might be, although I don’t know how to solve it, I’ll try to describe the situation: I have 144 small terrains (64x64 and resolution 512x512), this is done so that I can edit them during the game (large terrains are expensive), all terrains have the same material, it is to this material that I send this data so that a certain area is highlighted, I think this is the problem, but how to approach the solution from the other side…
I don’t see any perf problem on these screenshots.
Also, Editor is usually not indicative of the built application performance. Please check the built player.
thanks, but I solved this problem in a different way, I created one texture for a 768x768 material (mask) and mark the selection in the pixels of this mask, dynamically taking into account the selected area, in general it works much better, there are no more jumps and drops in performance…