- Home /
Simple shader Parse error: syntax error problem
First time trying to write a cg shader. I am not sure why the following simple shader gives me some error that I don't understand. Any help is appreciated.
Shader "Sprite/UVShader" {
Properties {
_MainTex ("Base Texture)", 2D) = "white" {}
}
SubShader {
Pass{
CGPROGRAM
#pragma vertex vert
// this specifies the vert function as the vertex shader
#pragma fragment frag
// this specifies the frag function as the fragment shader
#include "UnityCG.cginc"
// User-specified properties
uniform sampler2D _MainTex;
uniform float4 _MainTex_ST; // Needed for TRANSFORM_TEX(v.texcoord, _MainTex)
struct VertexInput {
float4 vertex : POSITION;
float4 uv : TEXCOORD0;
};
struct VertexOutput {
float4 pos : SV_POSITION;
float4 uv : TEXCOORD0;
};
VertexOutput vert(VertexInput input)
{
VertexOutput output;
output.uv = input.uv;
output.pos = mul(UNITY_MATRIX_MVP, input.vertex);
// Texture offset - GOOD
// output.tex = TRANSFORM_TEX(input.texcoord.xy, _MainTex);
// output.tex = float2(input.texcoord);
return output;
}
float4 frag(VertexOutput input) : COLOR
{
return tex2D(_MainTex, float2(input.uv.xy));
}
ENDCG
}
//FallBack "Diffuse"
}
Also, any idea how I can further modify this to adjust the shader like the renderer.material.mainTextureOffset var? I am trying to make the above code for Sprites since the command mainTextureOffset can't work on Sprites. I am extremely new to this so do ELI5 please!
Comment