3

This tutorial uses explicit OUT structures, e.g:

struct C3E1v_Output {
  float4 position : POSITION;
  float4 color    : COLOR;
};

C3E1v_Output C3E1v_anyColor(float2 position : POSITION,
                            uniform float4 constantColor)
{
  C3E1v_Output OUT;
  OUT.position = float4(position, 0, 1);
  OUT.color = constantColor;  // Some RGBA color
  return OUT;
}

But looking at one of my shaders I have explicit in/out parameters:

float4 slice_vp(
        // Vertex Inputs
        in float4 position        : POSITION,    // Vertex position in model space
      out float4 oposition : POSITION,
        // Model Level Inputs
        uniform float4x4 worldViewProj) : TEXCOORD6
{
    // Calculate output position
    float4 p = mul(worldViewProj, position);
    oposition=p;
    return p;
}

I'm having some problems using HLSL2GLSL with this and wondered if my Cg format is to blame (even though it works fine as a Cg script). Is there a 'right' way or are the two simply different ways to the same end?

Mr. Boy
  • 60,845
  • 93
  • 320
  • 589

1 Answers1

1

As you've seen, both ways work. However, I strongly endorse using structs -- especially for the output of vertex shaders (input of fragment shaders). The reasons are less to do with what the machine likes (it doesn't care), and more to do with creating code that can be safely re-used and shared between projects and people. The last thing you want to have to find and debug is a case where one programmer has assigned a value to TEXCOORD1 in some cases and is trying to read it from TEXCOORD2 in (some) other cases. Or any permutation of register mis-match. Use structs, your life will be better.

bjorke
  • 3,295
  • 1
  • 16
  • 20