Shader optimization question

Can anyone tell me the best way to use same shader among multiple model.
Eg no 1.
Shader 1 -> model 1
Shader 1 -> model 2


Eg no 2.
Shader 1 -> model 1
Shader 1 (clone new 1) -> model 2

i hope someone able to understand it.
The reson i asking this, because of when i draw model1 i have 2 textures have to set shader 1, When i render model2 i have only 1 texture and here come with the problem, the 2nd texture cache from model1 remain in the shader.

I think you are looking for Multi-Pass Shader Rendering

This might help, only glanced at it:

So you want to render meshes with either one or two textures?

Then either you need two shaders, or one shader and a boolean

float4 materialColour = tex2D(sampler1, uv);
float4 surfaceColour = 1;
if (hastwotextures)

float4 diffuseColour = materialColour * surfaceColour;

Wouldn’t it be better to just make a shader that takes 2 textures and use both.
Or to make a shader that uses one texture and send in either texture you want to use to the effect ?

Im not sure i can see much use for a second pass maybe to get away with not loading a new effect or something. Unless that works with a already loaded rendertarget as the input from the first pass to the second pass with the data updated.
Never tried that, i just didn’t think it would work, would be pretty cool if it did.

1 Like