Shaders are faster then SpatialMaterial?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By sante

Hello everybody.
I’m asking for something about ShadersMaterials performances vs. SpatialMaterial…
Suppose one have to do a simple work, like apply a single diffuse texture to a mesh, doing it with a couple row shader is better (in speed terms) respect using a simple and confortable SpatialMaterial or performance are the same?
Naturally I’m speaking in “pratical situation”, rather then theory…

Many thanks

:bust_in_silhouette: Reply From: Ninfur

Practically I wouldn’t worry about it. There are usually a lot of other things that affect performance way more, like not sharing material between objects.

There is no difference between a SpatialMaterial and a ShaderMaterial if they do the same operation and produce the same material. If you right click a SpatialMaterial and convert it into a ShaderMaterial they should have more or less identical performance.

Now, if you don’t need everything the SpatialMaterial does, you can write a ShaderMaterial that does less operations, and in turn will have better performance. But I’m pretty sure the difference will be negligible, unless you have hundreads of non-shared material instances.

For example, the shader below will have better performance than the default SpatialMaterial, due to making less operations.

shader_type spatial;
render_mode unshaded;

void fragment() {
    ALBEDO = vec3(1.0, 0.0, 0.0);
}

Understood. Thanks

sante | 2022-08-31 17:59