I have found very useful resource on the Swiftless website on OpenGL.
Unfortunately, I cannot manage to adapt a GLSL fragment shader to my project, which uses Cg. Here it is:
uniform sampler2D color_texture;
uniform sampler2D normal_texture;
void main() {
// Extract the normal from the normal map
vec3 normal = normalize(texture2D(normal_texture, gl_TexCoord[0].st).rgb * 2.0 - 1.0);
// Determine where the light is positioned (this can be set however you like)
vec3 light_pos = normalize(vec3(1.0, 1.0, 1.5));
// Calculate the lighting diffuse value
float diffuse = max(dot(normal, light_pos), 0.0);
vec3 color = diffuse * texture2D(color_texture, gl_TexCoord[0].st).rgb;
// Set the output color of our current pixel
gl_FragColor = vec4(color, 1.0);
}
I have tried something:
struct fsOutput {
vec4 color : COLOR;
};
uniform sampler2D detailTexture : TEXUNIT0;
uniform sampler2D bumpTexture : TEXUNIT1;
fsOutput FS_Main(float2 detailCoords : TEXCOORD0,
float2 bumpCoords: TEXCOORD1)
{
fsOutput fragm;
float4 anorm = tex2D(bumpTexture, bumpCoords);
vec3 normal = normalize(anorm.rgb * 2.0f - 1.0f);
vec3 light_pos = normalize(vec3(1.0f, 1.0f, 1.5f));
float diffuse = max(dot(normal, light_pos), 0.0);
vec3 color = diffuse * texture2D(detailTexture, detailCoords).rgb;
fragm.color = vec4(color, 1.0f);
return fragm;
}
But it doesn't work. To debug, I have a function that catches Cg errors, and my program breaks at this point. I have identified the two texture IDs in the main program. Can you suggest any improvement for this Cg shader?