CG rather than raw GLSL

Originally posted by knackered:
What about materials? Do I have to store the materials in a light structure repeatedly for each light, or is there a way of writing into a global set of uniforms?
im not quite sure if i understood the question correctly, but what about writing a material structure which can be passed as parameter to the lighting function of the light structure like this:

struct Material
{
 
  float4 diffuse;
};

interface Light
{
  float4 performLighting(Material m);
};

struct DirLight: Light
{
  
  float4 performLighting(Material m)
  {
    return m.diffuse;
  }
};

furthermore it is possible to declare global variables (just like in c).

What you posted is a partial solution to the situation I described. It works only if there is no overlap in required attributes. What if I have two independant interfaces, and both of them might need some particular attribute in one of their implementations?

The other situation that is not covered in your example is adding additional varying variables. For example, some light models might require the view vector, while others require just the light vector…

This is all a bit confusing. I’ll stick with GLSL for now, I’m comfortable with its compile/link stages and I didn’t have to read a manual to understand it.

i guess in the end it comes down to personal preference and familiarity when deciding which high level language should be chosen.

and yep i guess there are cases where cg just isnt as flexible as glsl. (it was the first language i tried and well… i got used to it :slight_smile: ). still i think it does have its merits.

This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.