Hi.
I’m currently trying to learn CG shader programming and I achieved some minor successes. But now I’m stuck at some point with my simple distortion effect and I don’t understand why. Now I have some questions, I hope could help me with, to understand why my shader isn’t working.
First question: I have the “_Color” property added to my shader, but I actually don’t want to change the color of my vertices. If I remove the color property, nothing is rendered at all. I don’t understand exactly why I need it, other than the color may be by default no color and completely transparent. Am I correct? I’ve not found an answer to this, but maybe this is so trivial that no one asks this
Second question: I’m trying to move the vertices in the ‘vert’ function with a sinus time function. I expect to see a movement of the vertices, but nothing happens. All vertices are still at the same place (at least from what I can see in the editor). Also I tried to see a color change in the frag function, but this also doesn’t change anything.
I’m a bit helpless, so I’m thankful for every help!
Shader "DistortionTest"
{
Properties
{
_MainTex ("Texture", 2D) = "white" { }
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader
{
Tags
{
"Queue" = "Opaque"
}
Pass
{
CULL Off
CGPROGRAM
#pragma target 4.0
#pragma exclude_renderers ps3 xbox360
#pragma fragmentoption ARB_precision_hint_fastest
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
//uniform fixed4 _Color;
uniform sampler2D _MainTex;
struct vertexInput
{
float4 vertex : POSITION;
float4 texcoord : TEXCOORD0;
};
struct fragmentInput
{
float4 pos: SV_POSITION;
float3 color : COLOR0;
};
fragmentInput vert (appdata_base v)
{
fragmentInput o;
o.pos.w = v.vertex.w;
o.pos.x = _SinTime.x * v.vertex.x;
o.pos.y = v.vertex.y;
o.pos.z = v.vertex.z;
o.color = float3 (1.0, 1.0, 1.0);
return o;
}
half4 frag(fragmentInput i) : COLOR
{
return float4(_SinTime.x, 1.0, 1.0, 1.0);
}
ENDCG
}
}
Fallback "Transparent/Cutout/VertexLit"
}