Chapter 10 Fragment Post Processing use different texture colors

I’ve finished going through Chapter 10, and I wanted to try one of the challenges, namely using a different texture color for the two windows.
I was trying to do this programmatically, but I haven’t found a clean way to replace the pixel data from the MTLTexture for the second window to have a different color.
How should I approach this? Just create a new texture image with a different color and load that instead? Or pass a flag in the fragment shader?

In any case, is there a clean, good way to do this programmatically at load time?

Hi @theseus and welcome to the forum :smiley:!

For the window color, if you’re using a solid color, there is no real reason to use a texture. You could pass the shader function a float3 to set the color.

If you want to use a texture, then you can set up multiple textures up front at load time in different MTLTexture buffers, and pass the relevant texture to the fragment shader.

If you are using a solid color and a texture, the texture really only has to be one pixel big, as you can stretch the texture in the fragment shader using the sampler’s address mode as described in Chapter 6.5 Samplers. address::repeat.

1 Like

Hi @caroline thanks a lot for your reply!
All these options make sense, I’ll try them out!

1 Like