One texture with multiple Magfilter settings

I have a texture, produced by render to texture, which I want to use with two different Magfilter settings on different models. Since the Magfilter is set per texture, there does not appear to be a way to do this.

The models in question happen to be rendered to different buffers, so changing the Magfilter settings between rendering the buffers would also be sufficient.

Is there a way to accomplish this? The only work arounds I can see is implementing my own filtering in a shader, or duplicating the texture into second buffer via render to texture.

Use case: This is for my deferred shaded pipeline. I often want to use the scene’s normals, colors etc. pixel for pixel with no filtering, but there are some cases (such distortion effects and part of my SSAO pass) that would like to sample them with basic linear filtering.


This is not currently possible, but it has been discussed to split out a Sampler class from Texture that stores mipmap settings. That would be a major API overhaul, though.

For now, you can make a shallow copy of the texture.

I only see Texture.makeCopy, which apparently duplicates the texture memory. Is that what you mean? Doing that every frame for a couple of full screen textures seems like a bad idea, though easier than my other ideas.

i’ve seen a game which use a different way to relate textures and materials.
in that game, a texture is an element of a material, and a texture can be used for different materials, and the texture filtering setting is stored in materials. which means a texture can have different filters when it’s used in different materials.
also, a material stores texture stages and depthtest settings, fog setting etc…

that seems a good way, since a texture often occupy more memory that a material setting.

Maybe optional filtering settings on the TextureState that override the texture? (That would not break existing code)

My use-case is for shader-inputs, so I need some extra way to get the data specified there. Maybe another overloaded setShaderInput function that takes a texture and filtering settings? That would be ideal for my current use case.

While I don’t need it, one thing to think about is at least BAM files should support whatever change is made here, if one is made.

Shaders typically work with samplers, which are objects that specify the texture sampling (and filtering) settings. Perhaps we should create a small class for that and allow passing such an object alongside the texture. Or, we store the texture in the sampler object, and allow passing the sampler object itself, which seems to be a popular approach in CgFX and COLLADA and the like.