Some one can tell me why the Simplest Vertex and Fragment program con the CG Tutorial doesn't work with Unity ? I keep getting errors like: - Undefined channel 'POSITION' - 'POSITION' is not visible in the profile - etc. The shader i'm trying is: Code (csharp): Shader "New Shader" { Properties { _Color ("Main Color", Color) = (1,1,1,0.5) _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Pass { CGPROGRAM // profiles arbfp1 // vertex vert // fragment frag struct VOut { float4 position : POSITION; float4 color : COLOR; }; struct FOut { float4 color : COLOR; }; VOut vert (float2 position : POSITION) { VOut output; output.position = float4 (position, 0, 1); output.color = float4 (0, 1, 0, 1); return output; } FOut frag (float4 color : COLOR) { FOut output; output.color = color; return output; } ENDCG } } } Thanks in advance, i will check for it tomorrow morning. Omar Rojo
On quick scan, one problem is that it's missing: Code (csharp): #include "UnityCG.cginc" before the struct VOut { line. There could be more problems, but hopefully this helps. Might want to start with the tutorials in the ShaderLab documentation instead/also. -Jon
I should depend on the UnityCG library ? I don't wan't to, that is why i omitted, and i have already read an re-read the ShaderLab documentation. I want my shaders to be 100% mine. I'll check it though. Omar Rojo
Currently vertex shader inputs are not based on semantics; instead they must use predefined names (vertex, color, normal, texcoord, texcoord1, tangent). So in your case you should change vertex shader prototype to: Code (csharp): VOut vert (float2 vertex) and later in the shader use "vertex" as the variable name: Code (csharp): output.position = float4 (vertex, 0, 1); Using UnityCG.cginc is nothing magic, it just brings some parameters that are exposed by the engine into the shaders, and has some commonly used functions. You can always check out the contents of that file in Unity.app/Contents/CGIncludes/UnityCG.cginc
Is a Unity limitation not to specify semantics for the vertex program's input ? because, according to the book, there should be semantics in CG. I have already show the sphere with the shader without using UnityCG.cginc Thanks both, im learning so much , expect to hear more from me Omar Rojo
Vertex shader input semantics are there only for a single reason: so that the engine would know what data to pass where. If the engine can figure that out by some other means, it's fine as well. Currently Unity figures that out based on the names (not semantics). In the future this will be changed, so you can either use names (like it's done now), or use whatever names you like and pass Unity-understandable semantics. If semantics are not indicated, Cg compiler assigns them automatically "somehow". For OpenGL, all vertex components get mapped to "generic vertex attributes", and that's fine.
Yes Aras, I understand perfectly, and i can assume how it can automagically pass the data too (based on the data types and the order of the parameters can be a type), as long as it's logical. It's just i want to learn CG as it should be according to the book, but i understand perfectly what you mean. Omar Rojo