- Home /
Terrain shader optimisation
It's better and faster to use the default terrain texture splatting(1 for each channel) or to send to the terrain shader just 1 texture atlas and then unpack it here?
Answer by ScroodgeM · Aug 16, 2012 at 02:17 PM
by default terrain takes 1 pixel 4 times from 4 different textures, then blends it based on splat mask.
using atlas you should not just take 4 pixels, but also pre-calculate mapping per texture to mapping for atlas and also take pixel 4 times.
so you just will get some more calculations, especially if source textures are different resolution
well, I made a shader which takes the four textures in the atlas(all of the same resolution), and then I apply them to the terrain using the frac function and multiplying for a float2 is it faster then having 4 different textures and what are the downsides?
void surf (Input IN, inout SurfaceOutput o) { fixed4 splat_control = tex2D (_Control, IN.uv_Control); fixed3 col; col = splat_control.r * tex2D (_Splat0, IN.uv_Splat0).rgb; col += splat_control.g * tex2D (_Splat1, IN.uv_Splat1).rgb; col += splat_control.b * tex2D (_Splat2, IN.uv_Splat2).rgb; col += splat_control.a * tex2D (_Splat3, IN.uv_Splat3).rgb; o.Albedo = col; o.Alpha = 0.0; }
this is original's function. i think you have some more calculations. using a atlas ins$$anonymous$$d of textutes useful to batch drawcalls between different materials. in this case it will not decrease drawcalls.
btw, you can check ALU instructions in compiledshader. methinks in your shader it's some more instructions than here.