Download

Vertex shader for landscape

Hello, i have a question about what would be more efficient to use on landscape - vertex shader vs pixel shader. All over internet people are saying to use vertex shader because it is more efficient, but it depends on the triangles count. I’ve made 2 versions of similar shaders and both of them have very similar shader complexity and instructions count. As i know shader complexity preview mode generates coloring based on instructions count ( as documentation say so) but does it take into account what type of shader it is - vertex or pixel? I have a third person view in game, and using world composition. With pixel shader the performance impact depends on how many pixels of this shader are present in camera view, with vertex shader it depends on how many vertex the object has because all of them are computed if even a small part of the object is present in camera view( f.e. if i have 500k vertex on landscape and player will look in to sky and would see only 10% of this land - in this situation vertex shader is more render costly because all of 500k vertex will be computed, on the other hand with pixel shader only this 10% of the land pixels will affect performance), if i’am correct. So what would be more efficient to use in my situation? Please correct me if i’m wrong, because i’m a novice in this field.
Does vertex shader somehow make use of the landscape LODs?
My landscape specs
505x505, 63, 4 (2x2),126x126,16 (4x4)

Shader complexity of both materials
left - vertex ( used 3 custom UV chanels), right- pixel

Stats
Vertex: http://prntscr.com/j06twb
Pixel: http://prntscr.com/j06uak

Thx in advance for any help, because after all of this info in the inet i’m stuck and cannot proceed further…

As a rule of thumb, if you can offload certain calculations from pixel shader to vertex shader without visual impact, you should do so without hesitations. There are exceptions, but for your situation, it is certainly not the case.

Ok, now it’ more clear, thank you. Could you clarify one more thing - lets say that i’m using custom uv chanel to tile all of the texture ( global tiling), but i want to additionally have the possibility to tile each texture separately, so i will multiply by parameter after each texcoord that hooked on texture sampler, i’ve read somewhere that if you are using vertex shader the ideal variant is that you doesn’t do any math after texcoord that hooked up on texture sample - all math are calculated on custom uv and you plug clean texcoord on Texture sample ( solely for selecting appropriate custom UV chanel if you are using several). Is it true that additional math that doesn’t run on custom UV input is costing a lot more than the same math on pixel shader?

or if you can plug some calculations ( in my case global tiling) to vertex shader it’s already very good and so i could free myself from using some crafty Substance Designer technics to add editional per texture tiling that i need and simple multiply each texture before texture sampler?

depending on what you’re trying to do, offloading things to the vertex shader on a landscape might not be a good idea. problem being that the landscape vertices shift all the time due to LOD, which can easily lead to unwanted visual results

When you are sampling a texture, using coordinates, that rely on math done in pixel shader, it is usually called dependent texture fetch.

Avoiding dependent texture fetches at all costs is still applicable to some mobile platforms, but on average PC it does not matter that much.

At some point it becomes faster to calculate UVs in pixel shader, instead of using extra interpolators from vertex to pixel stage.

Unless you are targeting specific fossil mobile hardware, you should continue doing that and not worrying about it at all.

if i understand correct - LODs will lead to texture distortion in distance due to updated vert positions? but i have fog and slight blur in distance and also different texture ( simple noise texture mult on color) so if the problem in distortion - it’s not a big deal. But if i will gain a good performance optimisation from vert shader - it’s worth it i think, or is there any other issues?

I make this game for PC only for now. Well, if i multiply each texcoord on parameter, then somehow shader complexity of the vertex shader becomes bigger than the same setup in pixel shader, and moreover, the vertex shader isn’t so well scalable with quality switch in comparison to the the pixel shader ( similar shader setups)…