Sign in to follow this  
Filousov

Shader debugging and constant setting problem

Recommended Posts

Hi, I have following structure defined in my shader: struct SPOT_LIGHT { float4 Ambient; float4 Diffuse; float4 Specular; float3 Position; float3 Direction; float3 Atten; //1, D, D^2; float3 Angles; //cos(theta/2), cos(phi/2), falloff float Range; }; And following constant variable defined in shader: SPOT_LIGHT SpotLights[9]; My question is, how to set this constant variable SpotLights from my program using ID3DXConstantTable? (Not effect framework) When debugging will debugger show correctly, what is in SpotLights variable?? I'm asking these two questions, because I tried couple of things to set this variable and when I debugged the vertex shader (compiled on vs_2_sw). Debugger always showed me different data than I actually set. List of methods I tried in order to set SpotLights variable: 1) C++ Structure: // Spot light shader structure struct SpotLightShaderStruct { D3DXVECTOR4 Ambient; D3DXVECTOR4 Diffuse; D3DXVECTOR4 Specular; D3DXVECTOR3 Position; D3DXVECTOR3 Direction; D3DXVECTOR3 Atten; // 1, D, D^2 D3DXVECTOR3 Angles; // cos(theta/2), cos(phi/2), falloff float Range; // Range }; SpotLightShaderStruct CPPSpotLights[9] Fill in this structure and set using: ID3DXConstantTable::SetValue(D3DDevice, Handle, CPPSpotLights, sizeof(SpotLightShaderStruct) * 9 ) (Thats example) 2) C++ Structure // Spot light shader structure struct SpotLightShaderStruct { D3DXVECTOR4 Ambient; D3DXVECTOR4 Diffuse; D3DXVECTOR4 Specular; D3DXVECTOR4 Position; D3DXVECTOR4 Direction; D3DXVECTOR4 Atten; // 1, D, D^2 D3DXVECTOR4 Angles; // cos(theta/2), cos(phi/2), falloff D3DXVECTOR4 Range; // Range }; Fill in this structure and set using ID3DXConstantTable::SetValue 3) Obtaining handle for every SpotLight member and setting it separately like this: for (i = 0; i < 9; i++) { Shader->SetVSValue(ExtendedTable->at(i * 8), &SpotLightsIdea.Ambient, 16); Shader->SetVSValue(ExtendedTable->at(i * 8 + 1), &SpotLightsIdea.Diffuse, 16); Shader->SetVSValue(ExtendedTable->at(i * 8 + 2), &SpotLightsIdea.Specular, 16); Shader->SetVSValue(ExtendedTable->at(i * 8 + 3), &SpotLightsIdea.Position, 12); Shader->SetVSValue(ExtendedTable->at(i * 8 + 4), &SpotLightsIdea.Direction, 12); Shader->SetVSValue(ExtendedTable->at(i * 8 + 5), &SpotLightsIdea.Atten, 12); Shader->SetVSValue(ExtendedTable->at(i * 8 + 6), &SpotLightsIdea.Angles, 12); Shader->SetVSValue(ExtendedTable->at(i * 8 + 7), &SpotLightsIdea.Range, 4); } Shader is my class and for every member ID3DXConstantTeble::SetValue is called I'm totally stuck with this array structure setting. Thank you for your help.

Share this post


Link to post
Share on other sites
Dave, I tried with no actual result:

Shader->SetVSFloatArray(SpotLightsHandle, (FLOAT *) SpotLights, 9 * 25);

with
// Spot light shader structure
struct SpotLightShaderStruct
{
D3DXVECTOR4 Ambient;
D3DXVECTOR4 Diffuse;
D3DXVECTOR4 Specular;
D3DXVECTOR3 Position;
D3DXVECTOR3 Direction;
D3DXVECTOR3 Atten; // 1, D, D^2
D3DXVECTOR3 Angles; // cos(theta/2), cos(phi/2), falloff
float Range; // Range
};

With no result.
This is copy from shader debugger of first two entries:

- SpotLights ... array
- [0] ... struct
+ Ambient { 0, 0, 0, 0 } float4
+ Angles { 0, 0, 0 } float3
+ Atten { 0, 0, 0 } float3
+ Diffuse { 0, 0, 0, 0 } float4
+ Direction { 0, 0, 0 } float3
+ Position { 0, 0, 0 } float3
Range 0 float
+ Specular { 0, 0, 0, 0 } float4
- [1] ... struct
+ Ambient { 0, 0, 0, 0 } float4
+ Angles { 0.1, 0.1, 0.7 } float3
+ Atten { 0.5, 0.5, 0.7 } float3
+ Diffuse { 0, 0, 0, 0 } float4
+ Direction { 0.5, 0.5, 0.7 } float3
+ Position { 0, 0, 0 } float3
Range 0 float
+ Specular { 0, -1, 0, 0 } float4

And this is what I'm actually settings:

- SpotLights 0x0012f628
- [0]
+ Ambient {0, 0, 0, 0} D3DXVECTOR4
+ Diffuse {1, 1, 1, 1} D3DXVECTOR4
+ Specular {0, 0, 0, 0} D3DXVECTOR4
+ Position {25000, 99.9722, 25000} D3DXVECTOR3
+ Direction {2.77957e-012, 1.34077e-006, 1} D3DXVECTOR3
+ Atten {0, 0.002, 0} D3DXVECTOR3
+ Angles {0.953847, 0.924909, 1} D3DXVECTOR3
Range 5000.0000 float
- [1]
+ Ambient {0, 0, 0, 0} D3DXVECTOR4
+ Diffuse {0, 0, 0, 0} D3DXVECTOR4
+ Specular {0, 0, 0, 0} D3DXVECTOR4
+ Position {0, 0, 0} D3DXVECTOR3
+ Direction {0, 0, 0} D3DXVECTOR3
+ Atten {0, 0, 0} D3DXVECTOR3
+ Angles {0, 0, 0} D3DXVECTOR3
Range 0.00000000 float

As you can see, in shader, it's total mismatch. Shader was compiled on vs_2_sw.


Share this post


Link to post
Share on other sites

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