Sign in to follow this  

HLSL PS loop and indexing

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I'm trying to make per-pixel lighting in HLSL with pixel shader 3.0, but my code refuse to compile. I use DirectX 9 (April 2006) and I have a Geforce 6800GT. Here is part of my pixel shader:
float4 kDLightDir[3] : register(c3);
float4 kDLightAmbient : register(c6);
float4 kDLightDiffuse[3] : register(c7);
float4 kDLightSpecular[3] : register(c10);

int4 kiNbDirLight : register(i0);

for ( int i = 0; i < kiNbDirLight.x; i++ )
{
	float LdotN = dot(kDLightDir[i], inNormal);
	Diffuse += saturate(kDLightDiffuse[i] * LdotN);
}
It gives me this error: "error X4556: Error: invalid register 'i0' in register binding." If I remplace the 2 constants I'm indexing in the loop, kDLightDir[i] and kDLightDiffuse[i], by kDLightDir[0], and kDLightDiffuse[0] It compiles alright. Is constant indexing supported in pixel shader 3.0? I checked on google and I saw it is. I'm clueless, can somebody helps me? Thank

Share this post


Link to post
Share on other sites
Quote:
Original post by NouseHLSL
Hi,

I'm trying to make per-pixel lighting in HLSL with pixel shader 3.0, but my code refuse to compile. I use DirectX 9 (April 2006) and I have a Geforce 6800GT.

Here is part of my pixel shader:


float4 kDLightDir[3] : register(c3);
float4 kDLightAmbient : register(c6);
float4 kDLightDiffuse[3] : register(c7);
float4 kDLightSpecular[3] : register(c10);

int4 kiNbDirLight : register(i0);

for ( int i = 0; i < kiNbDirLight.x; i++ )
{
float LdotN = dot(kDLightDir[i], inNormal);
Diffuse += saturate(kDLightDiffuse[i] * LdotN);
}



It gives me this error:
"error X4556: Error: invalid register 'i0' in register binding."

If I remplace the 2 constants I'm indexing in the loop, kDLightDir[i] and kDLightDiffuse[i], by kDLightDir[0], and kDLightDiffuse[0] It compiles alright.

Is constant indexing supported in pixel shader 3.0? I checked on google and I saw it is.

I'm clueless, can somebody helps me?
Thank


No, you can't index constants in ps_3_0. you can only index t registers, looping is basically useless in pixel shaders.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this