Is it possible to set a different diffuse texture for every instanced model? or as an alternative do a texture transform per instance so i can use a texture atlas?
a shader can only have a limited amount of texture inputs, so this isn’t possible by design. but you can use a texture array for this. all textures get resized to the same size, and then you can get a different array texture slice per instance. there is an example in this thread:
RenderTextureArray.zip (1.0 MB)
thx tonfilm. that works.
i tried something to change the texture index per model. not sure if thats a good way to do it.
i will have around 200-1000 (or even more) instanced models and every model needs a different texture. texture resolution itself is very small (around 64x64 pixels).
I believe DX11 limit for texture array 2D is (2048 array slices)
if you have a lot of small textures maybe atlasing is also an option. pack all your textures into one big one and set different texture transforms to your geometry.
@elektromeier I think instead of using a get slice to order the textures before creating the array (which potentially leads to unnecessary “doubles”) it would be nicer to pass some kind of Index Buffer that is then used to select the textures on the gpu accordingly. Unfortunately I don’t know how to achieve this exactly maybe @tonfilm can shed some light on this.
@schlonzo i was thinking about texture atlasing but i dont know how to offset the texture with instanced geometry.
@bjoern yes, thats what i was afraid of. my knowledge about the stride pipeline is very limited.
i think your approach is perfectly fine, @elektromeier.
if you have enough memory, it is no problem to build a big array texture with doubled entries. especially when they are only 64px. unless you have to rebuild it dynamically very often.
if you need to change the texture per instance often (rebuild the texture array), the shader would need another input for a dynamic buffer with the index per instance. as @bjoern said.
you have to configure your valuemaps etc. to show the pins for uv transform, sampling etc.
but I don’t know how this is handled internally… It should work it if the shader, which does the instancing, supports it.
I am just starting to dive into stride, but I am also interested in a solution for this.
this will sample the texture array with an index per instance:
RenderTextureArray2.zip (1.0 MB)
thanks a lot for your help. this solves my problem.
just for learning reasons i tried to patch texcoords per instance by try and error and not really understanding whats going on. guess what: its not working. blinking red spheres in the renderer.
TexTransformInstanced.vl (81.0 KB)
it looks like you got everything right, kudos! the only problem is, that we didn’t provide shader implementations for Vector2 buffers. ShaderFX is still experimental and we only have float and Vector4 at the moment. see: VL.Stride.Runtime/src/Effects/ShaderFX/Buffer
but that’s an easy fix, you can extend the shader library with the missing implementation locally, and then your patch works just fine: TexTransformInstanced.zip (18.9 KB)
i’ll add these to the VL.Stride as well.
This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.