I have a system to render many objects, but I don’t know how to render more tan one object with same shader, let me explain:
I have a sphere and a cylinder, but both objects can be rendered by different shaders, example: Shader1: Shader to render object using 1 texture Shader2: Shader to render object using 2 textures
Both objects need to coexist in space, so if I want to render sphere with shader 1 and I use: shader1 resources:
context_->PSSetShaderResources(0, 1, &texture);
context_->PSSetSamplers(0, 1, &sampler);
…
shader2 resources:
context_->PSSetShaderResources(1, 1, &texture);
context_->PSSetSamplers(1, 1, &sampler);
context_->PSSetShaderResources(2, 1, &texture);
context_->PSSetSamplers(2, 1, &sampler);
…
in Shader1 the resources are references like this:
Texture2D colorTexture: register(t0);
SamplerState sampler: register(s0);
And in Shader2 the resources are references like this:
Texture2D colorTexture: register(t1);
SamplerState sampler: register(s1);
Texture2D colorTexture: register(t2);
SamplerState sampler: register(s2);
But what if I need to use shader1 resource’s in shader2???? How to manage those resources or do I need to replicate shader2 with shader1 registers?? this is the simplest example, this is part of a very much complex system with many many shaders and many textures, but I don’t know in what slot will be setted the resources, this can be absolutely generic, example, slot 5 will be used for texture 1 of shader2… It is possible to render many objects with minimal change of shaders, but the resources could be updated at any time.. I’m using directX11.