Jump to content
  • Advertisement
congard

OpenGL One shader and conditions in it or several shaders for each case

Recommended Posts

Hello! There is a shader that draws geometry. And I need to add switches between (for example) normal mapping, texture mapping, and so on... How best to implement this? Add if conditions or create separate shaders for each case? Or is it better to combine?

Share this post


Link to post
Share on other sites
Advertisement

Just a few random thoughts:

- one draw call needs one shader pipeline bound

- glsl supports shader subroutines, spirv not (yet ?)

- performance can suffer when pipelines with complex interfaces are switched

- simple pipelines don't impact performance that much

- draw calls can be batched to all use the same pipeline

- state influences shader compiling and execution

Less with APIs like Vulkan as the state is part of the pipeline afaik, but opengl starts to recompile shaders when states change and make that necessary. Debug messages tell me that ...

 

If it is just the method of normal calculation or surface colour, i'd go with a single pipeline and pass in a uniform to select the routine (Edit because the rest of the interface doesn't change). Thus i keep the ability to switch between versions more easily, if that is necessary. But hey, just random thoughts .... my experience is limited.

 

Edited by Green_Baron

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!