   Easy Cg pixel shader example?
  Hi!I have searched the internet for a tutorial / example showing how to write a simple pixel shader using Cg in OpenGL. Unfortunately, I didn't find anything useful.Thus, I'd like to know, if you could give me any links where I can find that?Thanks, Nico.   
  well, firstly greets from Uni Dortmund ;)Here are some examples. I post them as vertex/pixel shader bundels, coz of the -vertex output = pixel input - fact.COLOR VERTEXstruct appin{    float4 position: POSITION;    float3 vertexColor: COLOR0;};struct vertout{    float4 HPosition: POSITION;    float4 color: COLOR0;};vertout main(appin IN,  uniform float4 kd,  uniform float4x4 WorldViewProj){    vertout OUT;    OUT.HPosition = mul(WorldViewProj, IN.position);    OUT.color.xyz = kd.xyz * IN.vertexColor.xyz;    OUT.color.w = 1.0;    return OUT;} // mainCOLOR PIXELstruct vertout{    float4 HPosition: POSITION;    float4 color: COLOR0;};struct pixelout{float4 pixel: COLOR;};pixelout main(vertout IN){    pixelout OUT;    OUT.pixel = IN.color;    return OUT;}PHONG VERTEXstruct vertexIn {float3  Position: POSITION;float4  UV: TEXCOORD0;float4  Normal: NORMAL;};struct vertexOut {float4  HPosition: POSITION;float4  TexCoord: TEXCOORD0;float3  LightVec: TEXCOORD1;float3  WorldNormal : TEXCOORD2;float3  WorldPos: TEXCOORD3;float3  WorldView: TEXCOORD4;};vertexOut main(vertexIn IN,  uniform  float4x4  WorldViewProj, uniform  float4x4  WorldIT, uniform  float4x4  World, uniform  float4x4  ViewIT, uniform  float3  LightPos){vertexOut OUT;OUT.WorldNormal = mul(WorldIT, IN.Normal).xyz;  float4  Po = float4(IN.Position.x,IN.Position.y, IN.Position.z,1.0);float3  Pw = mul(World, Po).xyz; // pos in world coordsOUT.WorldPos=  Pw;OUT.LightVec =  LightPos;// - Pw;OUT.TexCoord =  IN.UV;OUT.WorldView =  normalize(ViewIT[3].xyz - Pw); OUT.HPosition =  mul(WorldViewProj, Po);return  OUT;} PHONG PIXELstruct vertexOut {float4  HPosition: POSITION;float4  TexCoord: TEXCOORD0;float3  LightVec: TEXCOORD1;float3  WorldNormal : TEXCOORD2;float3  WorldPos: TEXCOORD3;float3  WorldView: TEXCOORD4;};struct pixelOut {float4  col : COLOR;};pixelOut main(vertexOut IN,  uniform floatSpecExpon,  uniform float4  AmbiColor,  uniform float4  SurfColor,  uniform float4  LightColor) {pixelOut OUT;float3 Ln = normalize(IN.LightVec);float3 Nn = normalize(IN.WorldNormal);float3 Vn = normalize(IN.WorldView);float3 Hn = normalize(Vn + Ln); float ldn = dot(Ln,Nn); float hdn = dot(Hn,Nn); float4 litV = lit(ldn,hdn,SpecExpon);float4 diffContrib = SurfColor * ( litV.y * LightColor + AmbiColor); // float4 specContrib =  litV.y * litV.z * LightColor; // float4 result = diffContrib + specContrib;  //OUT.col = result;return OUT;}TEXTURE VERTEXstruct myVertex {float4 position  : POSITION;float4 color0    : COLOR0;float2 texcoord0 : TEXCOORD0;float3 normal : NORMAL;};struct fragment{float4 position  : POSITION;float4 color0    : COLOR0;float2 texcoord0 : TEXCOORD0;float3 normal : TEXCOORD1;};fragment main( myVertex IN, uniform float4x4 WorldViewProj, uniform float4x4 World ){fragment OUT;float4 v = float4( IN.position.x,IN.position.y,   IN.position.z,   1.0f );OUT.position  = mul( WorldViewProj, v );OUT.color0    = IN.color0;OUT.texcoord0 = IN.texcoord0;float4 normal;normal.xyz = IN.normal;normal.w = 0;float4 newnormal = mul( World, normal);OUT.normal = newnormal.xyz;return OUT;}TEXTURE PIXELstruct fragment{float4 position  : POSITION;float4 color0    : COLOR0;float2 texcoord0 : TEXCOORD0;float3 normal : TEXCOORD1;};struct pixel{float4 color : COLOR;};pixel main( fragment IN,uniform sampler2D testTexture, uniform float4 light ){pixel OUT;float4 mynormal;float4 mylight;float4 mycolor;float4 color1 = tex2D( testTexture, IN.texcoord0.xy );mynormal.xyz = IN.normal;mynormal.w = 0;normalize(mynormal);mylight = light;mylight.w = 0;normalize(mylight);mycolor = (color1) * abs(dot(mylight,mynormal));    OUT.color = mycolor;return OUT;}A BUMP-MAPPING VERSION OF THE TEXTURE PIXEL SHADERstruct fragment{float4 position  : POSITION;float4 color0    : COLOR0;float2 texcoord0 : TEXCOORD0;float3 normal : TEXCOORD1;};struct pixel{float4 color : COLOR;};pixel main( fragment IN,uniform sampler2D testTexture, uniform float4 light ){pixel OUT;float4 mynormal;float4 mylight;float4 mycolor;float4 color1 = tex2D( testTexture, IN.texcoord0.xy );float u = IN.texcoord0.x;float v= IN.texcoord0.y;float4 normaladd;normaladd.x = sin(2400*u) + sin(800*v); // 0.001 * u + 0.003 * v;normaladd.y = sin(2800*(u+v)) + cos (1800*v);normaladd.z = cos(1800 * u) + sin(800*(u+v));normaladd.w = 0;//normalize(normaladd);normaladd = normaladd * 0.1;mynormal.xyz = IN.normal;mynormal = mynormal + normaladd;mynormal.w = 0;normalize(mynormal);mylight = light;mylight.w = 0;normalize(mylight);mycolor = color1 * abs(dot(mylight,mynormal));    OUT.color = mycolor;return OUT;}Hope I could help ;)cu[Edited by - phantom on December 7, 2005 8:43:58 AM];  Hi!Thanks you for your examples. I was actually looking for the OpenGL code I need to include and get the pixel shader to work. I've written an example where I got a vertex shader running, but an easy pixel shader didn't work.This morning I had an idea: the problem was that I was using the same profile I used for the vertex shader also for the pixel shader. After having created a separate profile for the pixel shader, it worked!NOW, I can try some of the examples you sent me!Thanks & Gruss nach Dortmund!Nico.   