passing a float from script to shader

Hi guys. I’m trying to pass a float into my custom skybox shader from a script. I looked everywhere and I still have no idea how to do it. Any help is much appreciated.
Here is my shader:

    Shader "RenderFX/CustomSky" {
Properties {
	_Tex0 ("Cubemap0", Cube) = "white" {}
	_Tex1 ("Cubemap1", Cube) = "white" {}
	_BlendFactor ("BlendFactor", float) = 0.5
}

SubShader {
	Tags { "Queue"="Background" "RenderType"="Background" }
	Cull Off ZWrite Off Fog { Mode Off }

	Pass {
		
		CGPROGRAM
		#pragma vertex vert
		#pragma fragment frag
		#pragma fragmentoption ARB_precision_hint_fastest

		#include "UnityCG.cginc"

		samplerCUBE _Tex0;
		samplerCUBE _Tex1;
		uniform float _BlendFactor;

		
		struct appdata_t {
			float4 vertex : POSITION;
			float3 texcoord : TEXCOORD0;
		};

		struct v2f {
			float4 vertex : POSITION;
			float3 texcoord : TEXCOORD0;
		};

		v2f vert (appdata_t v)
		{
			v2f o;
			o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
			o.texcoord = v.texcoord;
			return o;
		}

		fixed4 frag (v2f i) : COLOR
		{
			fixed4 tex0 = texCUBE (_Tex0, i.texcoord);
			fixed4 tex1 = texCUBE (_Tex1, i.texcoord);
			
			fixed4 col = (tex0 *_BlendFactor)+( tex1 * (1.0 -_BlendFactor));
			return col;
		}
		ENDCG 
	}
} 	

Fallback Off

Here is my script:

var globalLight : GameObject;
static var localGameTime : float;
static var maxTime : float = 20; //amount of time passed in seconds before the timer resets

function Start()
{
	localGameTime = 0;
}

function FixedUpdate()
{
	localGameTime = Time.fixedTime%maxTime;
	CycleLightLocal();
	Debug.Log(localGameTime);
	//**Here I want to pass localGameTime/maxTime into the shader as an Uniform**
}

function CycleLightLocal()
{
	globalLight.transform.Rotate((360/maxTime) * 0.02, 0, 0, Space.Self);	
}

I apologize for bad formatting. Cheers. Kamil

Any time you need to communicate with a shader, you can do it through the Material class.

Essentially, you would just get reference to the skybox, perhaps through RenderSettings.skybox:

Skybox _skybox = RenderSettings.skybox;

Skybox only has one property, material. So if you want to communicate a float to the material’s shader you can use the methods Material.GetFloat(“_PropertyName”) and Material.SetFloat(“_PropertyName”, float)

So with your shader it would be:

_skybox.material.SetFloat("_BlendFactor", .5F); //C#
_skybox.material.SetFloat("_BlendFactor", 0.5); //JS

Hope that helps.

==

thanks! I sort of got it to work the way I wanted. Here’s the code I used:

var _skybox : Material;

var globalLight : GameObject;

static var localGameTime : float;
static var maxTime : float = 20; //amount of time passed in seconds before the timer resets

function Start()
{
localGameTime = 0;
_skybox = RenderSettings.skybox;

}

function FixedUpdate()
{
localGameTime = Time.fixedTime%maxTime;

CycleLightLocal();


Debug.Log(localGameTime);
_skybox.SetFloat("_BlendFactor", localGameTime/maxTime); 

}

function CycleLightLocal()
{
globalLight.transform.Rotate((360/maxTime) * 0.02, 0, 0, Space.Self);
}

Kamil