Advertisement

Reflectance model question

Started by September 17, 2019 07:11 PM
2 comments, last by DerTroll 5 years, 4 months ago

Q1: Does such a need arise at all? Or should the reflectance model be used globally for the entire scene?

Q2: If it is necessary to implement in the shader switching between reflectance models (OrenNayar, Lambert etc), how to do it better? Create a separate shader for each reflectance model? Or use something like


// fragment shader

uniform float reflectanceModel;
...
switch (reflectanceModel) {
  case 0.0:
      diffuse = lambert(...);
      break;
  case 1.0:
      diffuse = orenNayar(...);
      break;
  case 2.0:
      ...
      break;
}

I will be grateful for your advice

Using a dynamic branch is generally not a great idea for this unless you're not concerned about performance. Compilers will usually generate sub-optimal code for what you described, since it won't be able to optimize well across the boundary of your branch and also because you'll end up with the register usage of your worst-case shader model. You may also end up sampling more maps and/or using more constants than you need, since different shading models may require more or less parameters. The shading model is definitely the sort of thing you would normally split off different shader permutations for in normal game scenarios.

As for whether you need multiple models...that completely depends on what you're aiming for and also the art style of your game.

 

 

Advertisement
2 hours ago, congard said:

Does such a need arise at all? Or should the reflectance model be used globally for the entire scene?

Depends on your game. If you want to simulate different kinds of surfaces on different objects and it can't be handled by a single model, then you might need multiple models... if that's what you are asking for.

 

2 hours ago, congard said:

Q2: If it is necessary to implement in the shader switching between reflectance models (OrenNayar, Lambert etc), how to do it better? Create a separate shader for each reflectance model? Or use something like

Branches (if-else, switch) usually have a big impact on shader performance. Read the first answer from this link if you want to know why. So you should either use multiple shaders or you can try using OpenGL subroutines. In any case, it is advisable to sort your data accordingly to avoid multiple state changes.

 

Greetings

... Got ninja'd by @MJP  :(

This topic is closed to new replies.

Advertisement