Jump to content

  • Log In with Google      Sign In   
  • Create Account

HLSL array problems


Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1   Members   

122
Like
0Likes
Like

Posted 09 August 2006 - 03:25 AM

I'm working on a per-pixel lighting system that can add and remove lights in real time. However I have 2 problems with arrays in HLSL at the moment. Problem 1: Despite having found a few websites that say otherwise, I can't seem to use a variable to define the size of an array. This is what I'm trying to do: uniform extern int gNumLights; uniform extern float4 gAmbientLight[gNumLights]; //etc etc for all the light properties When I try to run it I get an error saying: array dimensions must be literal scalar expressions. If I hard set it to a value like 3 it runs fine. So is it possible for me to use another variable to define the size of global arrays and if so, how? Problem 2: I'm passing the data for the light property arrays above from my C++ code as std::vectors which I assumed would work as essentially they are just fancy arrays. Although it compiles and runs fine, it doesn't seem to make the pixel shader actually do its job. Is there anything special I need to do to make this vector to array setup work? I've done some tests and it all points to the arrays being the problem, at this point I'm trying to determine if it's this conversion that is causing the problem. Thanks.

#2   Members   

1178
Like
0Likes
Like

Posted 09 August 2006 - 06:05 AM

Quote:
Original post by Citizen Erased
uniform extern int gNumLights;

uniform extern float4 gAmbientLight[gNumLights];
//etc etc for all the light properties

If you use 'const static int gNumLights = value;', it works. However, this means you can't set it after compilation. HLSL arrays cannot be dynamically allocated, so if you want to change the size, you have to recompile the shader. Personally, I just use a define (which I can setup from the app) instead of a constant.

Quote:

I'm passing the data for the light property arrays above from my C++ code as std::vectors which I assumed would work as essentially they are just fancy arrays. Although it compiles and runs fine, it doesn't seem to make the pixel shader actually do its job. Is there anything special I need to do to make this vector to array setup work? I've done some tests and it all points to the arrays being the problem, at this point I'm trying to determine if it's this conversion that is causing the problem.

Have you tried extracting the data into a linear array first? Perhaps vector is doing something different. You could also try debugging the shader, to see exactly which values are getting thrown in there.

Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )

#3   Members   

262
Like
0Likes
Like

Posted 09 August 2006 - 10:05 AM

I am doing something very similar in my shaders, but have the maximum number of lights set to 2. There are plenty of constant registers for more than that, but when you do per pixel lighting in the shader, and are targeting PS_2_0, you can only access 15 constant registers in the PS versus 255 in the VS. I found that I can not do more than 2 lights because of this. If you are targeting PS_3_0 you will not be limited by that.


I also found that it is easy to exceed the 64 instruction slot available in PS_2_0 (much less in PS_1_1). So if you add other features, like bump mapping you will apprach that limit as well.






Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.