# Moving pixel shader from 2.0 to 1.4 ???

This topic is 4746 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I've been working on a simulating a water model with shaders (waves/fresnel/reflection/refractions and simple normal mapping) for a little bit now and have started trying to move my pixel shader from version 2.0 to 1.4. I know that its possible to create the same type off effects using ps 1.4 (ati's Ocean screen saver), but I've run into some errors trying to compile my .fx file now. The error that I'm getting is : "error X4507: maximum constant register index exceeded - Try reducing number of constants referenced..." and afterwards it has the line number (and path) for this error (I think the one after is for this error). The line number points to:(took out the 10 varaibles for ease of reading) PixelShader = compile ps_1_4 RenderScenePS(...); What exactly does that error mean (or where can I look up these type of errors?). Is this saying that I have to many constant variables for the entire shader? or am I passing to many to my pixel shader. Also, I was wondering where I might find a good reference to help determine what I'll need to change to get my shader running on ps 1.4. thanks Aaron

##### Share on other sites
Quote:
 error X4507: maximum constant register index exceeded

Shader model 1.1/1.4 only have 96 constant registers whereas shader model 2.0 has 196+ constant registers. You are most likely setting too many constants for 1.4 as per the error message.

##### Share on other sites
Maybe I don't understand exactly how the constant registers are used in graphics cards. Does that mean that in my shaders(vertex and pixel combined), when I am creating local variables to hold calculations, that I'm making to many variables and exceeding what can be held in the 96 constant registers? Global variables are probably included into this count as well, I would assume?
I'm new to shaders, so I'm still learning.

thanks for your input

##### Share on other sites
Constant registers are not used to hold variables [grin]

It's usually down to two things:

* Too many numbers - numbers can't be stored directly in shader code, they have to be put in constant registers and referenced.
* Too many parameters or globals - if you've got a big lookup table for a water function or something (e.g. you're using a sine lookup table) then it'll burn through your constants quite quickly.

If you write to it, it isn't constant.

##### Share on other sites
Quote:
 Original post by gamerxrHey, I've been working on a simulating a water model with shaders (waves/fresnel/reflection/refractions and simple normal mapping) for a little bit now and have started trying to move my pixel shader from version 2.0 to 1.4. I know that its possible to create the same type off effects using ps 1.4 (ati's Ocean screen saver), but I've run into some errors trying to compile my .fx file now. The error that I'm getting is : "error X4507: maximum constant register index exceeded - Try reducing number of constants referenced..." and afterwards it has the line number (and path) for this error (I think the one after is for this error). The line number points to:(took out the 10 varaibles for ease of reading)PixelShader = compile ps_1_4 RenderScenePS(...);What exactly does that error mean (or where can I look up these type of errors?). Is this saying that I have to many constant variables for the entire shader? or am I passing to many to my pixel shader. Also, I was wondering where I might find a good reference to help determine what I'll need to change to get my shader running on ps 1.4. thanks Aaron

Sorry, there isn't a list of error codes. Generally, when you see some kind of error like this the line # isn't terribly helpful becuase its not any one particular line of code which is causing a problem, but the total program itself.

This error means that you are referencing too many constants. ps_1_4 can only access 8 constants.

I actually think you have other - more pressing issues. A ps_1_4 shader can only be at most 16 instructions (in 2 phases), thus it is rare to blow the number of constants and not also be vastly exceeding instruction counts.

Can you post the shader?

##### Share on other sites
Quote:
 Original post by EvilDecl81This error means that you are referencing too many constants. ps_1_4 can only access 8 constants.

Ahh .. ok, that would probably explain part of my problem, although I'm not 100% sure how ps_1_4 can only access 8 constants (but can hold 96?). I'm using around 16 global variables, (most that I never modify) and 2 textures at the moment.

I would have to agree that I'm also very likely to be over the limit on instruction count as well, so I'll see where I am once I fix my current problem.

Heres my pixel shader... or did you mean both post both pixel and vertex shaders?
thanks
float4 RenderScenePS(VS_OUTPUT IN,					uniform sampler2D NormalMap,					uniform samplerCUBE EnvironmentMap,					uniform half4 deepColor,					uniform half4 shallowColor,					uniform half4 reflectionColor,					uniform half4 reflectionAmount,					uniform half4 waterAmount,					uniform half fresnelPower,					uniform half fresnelBias,					uniform half hdrMultiplier				 ) : COLOR{    // sample up the normal maps    half4 bumpSample0 = tex2D(NormalMap, IN.bumpCoord0.xy)*2.0-1.0;    half3 normalSum = bumpSample0.xyz;    // Rebuild our matrix    half3x3 mat;    mat[0]		= IN.TexCoord1;    mat[1]		= IN.TexCoord2;    mat[2]		= IN.TexCoord3;     half3 objectSpaceNormal = mul(mat, normalSum);      objectSpaceNormal		= normalize(objectSpaceNormal);	// reflection/refraction    float3 eyeVec	  = normalize(IN.eyeVector);    half3  reflectVec = reflect(-eyeVec, objectSpaceNormal);    half3  refractVec = refract(-eyeVec, objectSpaceNormal, 1/1.5);	// Look up the reflection and refractions in our cube map    half4 reflection = texCUBE(EnvironmentMap, reflectVec);    half4 refraction = texCUBE(EnvironmentMap, refractVec);   	    half  facing = 1.0 - max(dot(eyeVec, objectSpaceNormal), fresnelBias);		    float fresnelTerm	=  (1.0-fresnelBias)* pow(  facing, fresnelPower );		    half4 waterColor = lerp(deepColor, shallowColor, fresnelScale*fresnelTerm);	    // Return the final color.    return waterColor*waterAmount +	reflection * reflectionColor * reflectionAmount * fresnelTerm +			refraction * (1.0 - fresnelTerm);			}

##### Share on other sites
Quote:
 Original post by gamerxrAhh .. ok, that would probably explain part of my problem, although I'm not 100% sure how ps_1_4 can only access 8 constants (but can hold 96?). I'm using around 16 global variables, (most that I never modify) and 2 textures at the moment.

You're confusing vertex shaders with pixel shaders. VS 1.4 can store/access 96 constants, but PS 1.4 can only store/access 8.

##### Share on other sites
Quote:
Original post by superpig
Quote:
 Original post by gamerxrAhh .. ok, that would probably explain part of my problem, although I'm not 100% sure how ps_1_4 can only access 8 constants (but can hold 96?). I'm using around 16 global variables, (most that I never modify) and 2 textures at the moment.

You're confusing vertex shaders with pixel shaders. VS 1.4 can store/access 96 constants, but PS 1.4 can only store/access 8.

heh I made that same mistake above as well by not paying attention :)

##### Share on other sites
Quote:
 Original post by superpigYou're confusing vertex shaders with pixel shaders. VS 1.4 can store/access 96 constants, but PS 1.4 can only store/access 8.

hah, I didn't catch that. That makes sense now.

##### Share on other sites
That pixel shader will never compile for 1.4 as is...

You are doing a normalize() and a pow() and tons of other stuff. You'll need to use a normalizing cube map, and a power lookup texture instead, as well as minimize your pixel level math (move some of it to the vertex shader).

You should reduce stuff to half3/float3 (or half/float) where posible instead of using half4/float4 for almost everything.

Really, for 1.4 or 1.1 you should consider just using ASM unless you are really familiar with tweaking HLSL code to get what you want on 1.x targets.

• 19
• 10
• 19
• 14
• 19