Switching shader Lighting On/Off from script

Hello everyone!

I’m trying to write a script that would be able to tell a shader whether it should use lighting or not.

I am familiar with possibility to add Lighting On/Off before CGPROGRAM line (as addressed here: Shader: Light off in CGPROGRAM - Unity Answers ) but I was wondering if it was possible to toggle it from MonoBehaviour?

I tried adding preprocessor directives like

SubShader 
{
	Tags {  "RenderType" = "Opaque" }
     
    #if LIGHTING_ON
	Lighting On
    #else
    Lighting Off

    CGPROGRAM
    #pragma surface surf Lambert
    #pragma multi_compile LIGHTING_OFF LIGHTING_ON
    // ...
}

and toggle lighting with material.EnableKeyword but it throws me syntax error. I guess I can’t use preprocessor directives before CGPROGRAM line?

Is there something like material.shader.SetLighting(true)? Should I write two different shaders, one with Lighting On and one with Lighting Off and switch between them or is there a better way?

I’m new to shaders so I hope I’m not missing something obvious. Any help is appreciated. Thank you!

EDIT 1:
I don’t want to do my lighting calculations. I would like to use surface shader with built-in Lambert shading like in my example.

EDIT 2:
As @Jessespike suggested, it would be possible to copy-paste Unitys implementation of Lambert lighting model and have it wrapped inside #if LIGHTING_ON - #else preprocessor directives, but would I still be able to use baked lightmaps?

You could write your own property called _Lighting and have that as a condition to do lighting calculations.

In script:

	material.SetFloat("_Lighting", 0f);	// turn off;
	material.SetFloat("_Lighting", 1f);	// turn on;

In shader:

	if (_Lighting != 0f)
	{
		// do light calcuations
	}