0

Maybe questions seems strange , but , please take a look at the summarized shader code listed below :

Shader "AngryBots/PlanarRealtimeReflection" {
    Properties {
        ...
    }

    SubShader {
        LOD 400

        Tags { "RenderType"="Opaque" }
        Fog { Mode Off }

        Pass {
            ... 


        }       
    }

    SubShader {
        LOD 200

        Tags { "RenderType"="Opaque" }
        Fog { Mode Off }

        Pass {


        ....

        }       
    } 
}

Every sub shader has a different LOD , I know the much bigger LOD has more details and wants more GPU Processing , So How should we number the LOD of our shaders ? how the device GPU understands the numbers !

So how Can I Find that my shader LOD is 500 or 700 or 300?

I had read the unity3d manual which tells me for example the BumpedMapDiffuse Shader For PC's are 500 ! But how can I convert it for mobile devices ?

2
  • 1
    Think of LOD as manual filtering. It doesn't unlock any extra potential or give you more details, it's just a way of manually disabling certain shaders if you know you are in a constrained environment like an iPad vs. a PC. Changing the allowable LOD is done by you, no behind the scenes alg.
    – Jerdak
    Aug 8, 2014 at 19:24
  • you want to tell me that GPUS won't work with them at all ? I Should write some scripts and control them by hand ? so what is the duty of them ? I can use shader.isSupported attribute! Aug 8, 2014 at 19:26

2 Answers 2

3

Unity's ShaderLab level of detail (LOD)* is a convenience feature for developers that helps them support multiple platforms in a single shader. The basic idea is that an application might have a SweetLightingShader that only works on PCs. Suppose the iPad doesn't support SweetLightingShader but it does support SemiSweetLightingShader. You could maintain two separate shaders or, even better, merge them in to a single shader and use LOD to decide what functionality to use.

*Do not confuse ShaderLab LOD with geometric LOD, they are independent topics.

Here is an example shader with 2 levels of detail:

Shader "Custom/ExampleLighting" {
    Properties {
        _MainTex ("Base (RGB)", 2D) = "white" {}
    }
    SubShader { // SweetLighting
        LOD 200
        Pass { Color (1,0,0,0) }
    }
    SubShader { // SemiSweetLighting
        LOD 100
        Pass { Color (0,1,0,0) }
    }
    FallBack "Diffuse"
}

The LOD can be set like so:

public class SwitchLod : MonoBehaviour {
    public Shader myShader;

    void Start() {
        myShader.maximumLOD = 100; //Use SemiSweetLighting -or-
        myShader.maximumLOD = 200; //Use SweetLighting
    }
}

The first subshader to meet the LOD requirements is the one used. From the docs:

When Unity renders a shader, it will go over all subshaders and use the first one that the hardware supports.

Note that the documentation for Shader.globalMaximumLOD states that it is the Shader LOD level for all shaders. This does not appear to be directly true, that's why my example sets the LOD for the shader directly. The AngryBots demo that comes with Unity uses the following snippet to apply the global maximum LOD to all shaders:

Shader.globalMaximumLOD = quality;
for (var s : Shader in shaders.shaders) {
    s.maximumLOD = quality;    
}
1

Shader LOD is extremely useful when you are need to support a range of GPUs with different performance. For example, if you want your game to run smoothly on both iPhone4 and iPhone5S.

Usual practice is to compose a shader as a set of several sub-shaders (consider them as a versions of the same shader) with different LODs. You may implement complex per-pixel lighting in sub-shaders with bigger LODs and rough per-vertex lighting in those with smaller LODs. Then you may enable appropriate versions of shaders in your code using Shader.globalMaximumLOD

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.