Hello,
I want to create a sky in the background that will have a radial gradient color. I did that by making a custom shader which makes the color change depending on the distance of the scaled uv's from (0.5, 0.5).
Since I want this shader to be applied on a sprite that will cover the whole screen I figured I could use NGUI to do that since I can attach a script that makes the sprite have the same scale as the screen resolution and everything should work. However since I need a different shader than what my other GUI uses, I created a new atlas that uses my shader, and I added a sprite in my GUI that scales with the screen resolution.
This works fine in the editor. However when I build this for the web player I just see a flat color. I tested various changes in the shader code just in case there is an incompatible command somewhere however what I realized is that the reason why this doesn't work is because the UV's of the sprite are not what I expect.
Do you change the uv's of a sprite at runtime? Here is the code for my shader:
Shader "Unlit/RadialGradient" {
Properties {
_Color ("Center Color", Color) = (1,1,1,1)
_OuterColor ("OuterColor", Color) = (1,1,1,1)
_Radius( "Radius", Float ) = 1.0
_Falloff( "Falloff", Float ) = 1.0
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
Pass
{
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
ColorMask RGB
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
fixed4 _Color;
fixed4 _OuterColor;
fixed _Radius;
fixed _Falloff;
struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : POSITION;
float2 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 IN) : COLOR
{
float2 d = IN.texcoord.xy - float2( 0.5, 0.5 );
float l = length( d );
fixed4 col = lerp( _Color, _OuterColor, l );
return pow( col,_Falloff )* _Radius ;
}
ENDCG
}
}
FallBack Off
}