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