x


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?

more ▼

asked Aug 16 '12 at 02:10 PM

cod gravatar image

cod
7 1 4 11

(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

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

more ▼

answered Aug 16 '12 at 02:17 PM

ScroodgeM gravatar image

ScroodgeM
7.6k 2 6

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?

Aug 16 '12 at 02:22 PM cod
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 instead 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.

Aug 16 '12 at 02:30 PM ScroodgeM
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1650
x1467
x29

asked: Aug 16 '12 at 02:10 PM

Seen: 308 times

Last Updated: Aug 16 '12 at 02:30 PM