Rendering textures vs Procedural Patterns

Hello all,

I have a generic question which has been bothering me as of late.Say we have 2D primitives such as a square. And we want to apply an image to it. If we had the option to do it both ways which would ultimately be faster to render?

1)Having the image as a texture and applying it on the square with a shader?
2) Using a shader when rendering the square which will be able to procedurally generate the pattern we want to apply to it. Much like the brick and mortar wall from the Orange book’s example.

So again repeating my question, which of the two would be faster? I would guess it would depend on the actual pattern. Say if we had a black and white texture with half the pixels black and the other half white it would be faster to go with procedural generation, right?

But I guess that in any other case … any more complicated shaders to generate the skin(pattern) our 2D shapes would have on them would be inherently slower than just having a bitmap of the thing, making a texture out of it and applying it on the shape.I am lead to this conclusion by the fact that most graphics cards have lots of hardware solely dedicated to textures.

But I would like the opinion of people here. What do you think is faster? Thanks for taking the time to read my topic!

If you have memory constraints and/or need quasi infinite details, the procedural approach can be interesting.
Otherwise, it is better to use a texture because rendering time does not depends on the pattern complexity.
For anything non-trivial, a procedural shader will probably be quite slower.
A problem with procedural graphics is the filtering : high frequency changes will be nasty, even if there are ways to procedurally filter, whereas texture mipmap/aniso offer good filtering out of the box.
Sometimes a good approach is to mix textures procedurally, that way most of the pattern complexities are baked in various textures, and fine tuning can be done procedurally. An example for the brick and mortar wall, have a high res texture for bricks, a high res texture for mortar, but let the shader choose between these two.

I see. Thanks zBuffer. As I suspected. No fortunately there are no memory constraints for my application but I thought it would be interesting to try to render some of the stuff procedurally. Ah well … speed over interesting challenges I guess.

You say it does not depend on the pattern’s complexity because the fragment shader runs for every fragment anyway?

I think he meant that for a texture, it’s just mapping an image to an object, whatever the image could look like, the algorithm is always the same and run as fast for all images (at least for same sizes): generally just an axis change, with some scaling, it is fast, very fast, graphic cards do it since many years now, whereas for procedural textures, the rendering depends on the algotithm complexity (more you use functions, the slower it will be).

Yeah that’s what I assumed too. Well guys thanks for the input, it’s good to have other people’s thoughts on this.