- Home /
Selecting shader based on video card
Hello, I'm trying to optimize some shaders that I would like to use depending on video card model.
For example: Nvidia 8500 -- use simple shader (diffuse) Nvidia 9500 -- use medium shader (cubemap + diffuse) Nvidia 265 and up -- use compelx shader (cubemap + rim light)
How can I determine what video card is in the machine, and select the shader to use depending on that?
Thanks.
Answer by burnumd · May 30, 2011 at 07:25 PM
While you can get specific makes and models of graphics card using SystemInfo.graphicsDeviceVendorID, SystemInfo.graphicsDeviceID, and SystemInfo.graphicsDeviceName, those are more typically used to exclude certain cards if an effect or shader doesn't work on them. In general, what you ought to do is first attempt to put a fallback pass in your shader. Typically this just involves adding Fallback "Diffuse"
after closing your SubShader. If you're not comfortable mucking about with shaders, you should check against the card's capabilities (also found in the SystemInfo class) rather than the card's specific identifiers. Properties like graphicsDeviceVersion and graphicsShaderLevel should be particularly useful, but familiarize yourself with the documentation for the entire class (it's not overly complex).
Thank you burnumd. The reason I wanted to use different shaders according to card spec, is because even tho the 8500 can use the shader, it slows badly in game when I use it.
Another optimization I was thinking about is swapping shaders based on distance, but I don't know if unity can do this automatically.
Thanks again.
In that case you're doing what I described in the beginning of my answer. Namely, excluding a graphics set from doing something. Unity can swap the shader on a material instance. I don't know if you mean "Automatically" as in "flip a switch and it'll do it," but you can definitely code it yourself using $$anonymous$$aterial.shader: http://unity3d.com/support/documentation/ScriptReference/$$anonymous$$aterial-shader.html
Your answer
Follow this Question
Related Questions
Mesh.Optimize() in Unity 5.6.0 1 Answer
Intensive Shaders + Dynamic Batching 1 Answer
How to force the compilation of a shader in Unity? 5 Answers