So what is the ShaderLabish
equivalent of gl_FragColor and gl_TexCoord. For example, how to express something very basic like the following in CG:
uniform float time;
uniform sampler2D originalTexture;
uniform sampler2D secTexture;
void main( void )
{
vec4 uvLayer = texture2D( secTexture, gl_TexCoord[0].xy );
vec4 colorLayer = texture2D( originalTexture, uvLayer.xy + vec2(time) );
gl_FragColor = colorLayer;
}
So far I’ve been playing with a frag function and types like tex2D, half4… But without success.
Thanks in advance…
Jessy
2
Cg is no more ShaderLabby than GLSL. ShaderLab can only do fixed function texturing.
Thanks Jessy.
But what would the CG code equivalent to the above GLSL look like?
Shader "Test/Simple" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0.5)
_MainTex ("Texture", 2D) = "white" { }
}
SubShader {
Pass {
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
float4 _Color;
sampler2D _MainTex;
struct v2f {
float4 pos : SV_POSITION;
float2 uv : TEXCOORD0;
};
float4 _MainTex_ST;
v2f vert (appdata_base v)
{
?????
}
half4 frag (v2f i) : COLOR
{
??????
}
ENDCG
}
}
}
Any hints will be appreciated.
Jessy
4
Cg is actually called Cg, not CG, but unfortunately, I don’t know (or like ;)) Cg; otherwise I would have helped you.
Cool, I got it working now…
So turns out that gl_FragColor corresponds to the return value of frag function. And gl_TexCoord[0].xy corresponds to i.uv