Game Development Community

Varying variable causeing error

by Anthony Rosenbaum · in Torque Game Engine Advanced · 06/24/2004 (9:22 am) · 1 replies

In hopes of understanding TSE and correcting some errors I am getting let me try to clarify what each part of the shading system there is, hopefully Brian or Ben will also bring some clarity

Vertex Shader

The Vertex shader takes in Attribute variables as incoming data structures. The structures contain all the information which could be changing at every vertex, such as vertex's position, color, normal and texcoord#.(see shaderGen/shaderComp.h/.cc)
struct VertData
{
	float4 position        : POSITION;
            float4 texCoord        : TEXCOORD0;
};

Alternatively, Uniform variables are variable that will be changing less often, they pertain to the whole shape like the modelview matrix or a lights' position. You must bring them in as augments in the main function

Conn main( VertData In, uniform float4x4 modelview : register(VC_WORLD_PROJ),
			     uniform float4x4 texMat        : register(VC_TEX_TRANS1)
)

note the syntax semantic variableType variableName : register(define#)

The define# can be found in the shdrConsts.h file.

Finally you might note the return type is Conn, this is another structure designed to hold the Varying variables, which are variable that are passed from the vertex shader to the pixel shader.

struct Conn
{
   float4 HPOS               : POSITION;
   float2 outTexCoord    : TEXCOORD0;
  };


Ok Great
So in its most basic form the Vertex shader is only responsible for placing the vertex's position.
{
   Conn Out;
   //take vert and get coord by transforming by modelviewmatrix
   Out.HPOS = mul(modelview, In.position);
   //set base texture coord
   Out.outTexCoord = mul(texMat, In.texCoord);
   return Out;
}

So lets look at the
Pixel Shader

As we just said varying variables are passed from the Vertex shader to the Pixel shader, so we will make a similar structure to receive the data being transferred. Notice there is no Position variable because the vertex shader already has set it.
struct ConnectData
{
   float2 texCoord          : TEXCOORD0;
};

We will also need an outgoing structure for the pixel's color
struct Fragout
{
   float4 col : COLOR0;
};

As before uniform variables can be pulled in as an augment to the main function
Fragout main(ConnectData IN,  uniform sampler2D baseTex      : register(S0)
)

The Pixel shader is responsible for deciding what color the pixel will be
{
   Fragout OUT;
    OUT.col = tex2D( baseTex, IN.texCoord );
}

Alright Great. After reading several examples I am under the impression if you want to send other varying variable across that are shader specific one would pass them in a TexCoord#

However when I do I get the error

warning X4707: texcoord inputs used directly (that is, other than sampling from textures) in shader body in ps_1_1 are always clamped from 0 to 1
(1): error X5088: Too many arithmetic instruction slots used: 14. Max. allowed (counting any co-issued pairs as 1) is 8.
(1): error X5089: Total number of instruction slots used too high: 16. Max. allowed (counting any co-issued pairs as 1) is 12.

Why?

#1
06/24/2004 (11:52 am)
You've mostly got it right, kind of a long post so I can't address it all. The errors you are getting in your pixel shader are because the shader is too long - too many instructions. PS 1.1 shaders are very limited in length, try and keep it down to a bare minimum.

It's tempting to write long shaders in HLSL for PS 1.1 hardware, but you have to be somewhat aware of what's going on underneath to know its limitations. See the DirectX documentation that came with the SDK for info on PS 1.1 level hardware on an assembly instruction level.