Jump to content
  • Advertisement
congard

OpenGL Reflectance model question

Recommended Posts

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

Edited by congard

Share this post


Link to post
Share on other sites
Advertisement

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.

 

 

Share this post


Link to post
Share on other sites
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  :(

Edited by DerTroll

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!