- Home /
 
Set the shader lod value yourself
Good day.
I'm developing a lod system.
As I want to support lod fading, I was looking into how Unity does it using shaders.
As far as I can tell, the Unity LodGroup uses the shader keyword "unity_LODFade" to tell the shader what lod level it has. 
The question:
How can I do the same as the Unity Lod system in respect to fading?
In other words, how can I set a per object shader value in a way, that it is being used by existing shaders using fading?
What I've tried:
I've found the built in shader property name here:
https://docs.unity3d.com/Manual/SL-UnityShaderVariables.html 
I've tried setting a fade value using the following code:
 private MaterialPropertyBlock propBlock;
 private Renderer renderer;  
 [Range(0,1)]
 [SerializeField]
 private float fade;  
 private void OnEnable()
 {
     this.propBlock = new MaterialPropertyBlock();
     this.renderer = this.GetComponent<Renderer>();
 }  
 private void Update() 
 {
     this.renderer.GetPropertyBlock(this.propBlock);
     this.propBlock.SetVector("unity_LODFade", new Vector4(this.fade, this.fade * 16, 0, 0));
     this.renderer.SetPropertyBlock(this.propBlock);
 }
 
               However, this didn't seem to do anything at all.
Also, when using the LodGroup component and only reading the value, it always seemed to be (0,0,0,0).
(I've tried the code using a SpeedTree.)
Thank you
Chillersanim 
Answer by sewy · Apr 16, 2021 at 06:06 PM
For anyone who gets here, check this: https://forum.unity.com/threads/setting-unity_lodfade-from-script.881881/#post-7047778
Your answer