Sign in to follow this  
16bit_port

[D3D10] Issue setting variables in shader

Recommended Posts

I'm currently doing something along the lines of this :

///////////.cpp

union EffectVector
{
D3DXHANDLE ptr9;
ID3D10EffectVectorVariable *ptr10;
void *pAddress;
};

struct Shader
{
...
EffectVector CustomColors[3];
};

...

pShader->CustomColors[0].ptr10 = Effect->GetVariableByName( "CustomColor1" )->AsVector();

...

for( /*blah blah blah*/ )
{
...
D3DXVECTOR4 v( .969f, .765f, .605f, 1.f );
pShader->CustomColors[0].ptr10->SetFloatVector( (float*)&v );
}

...

//render









///////////.fx

cbuffer cbPerObject
{
float4 CustomColor1;
...
};

...

void func1()
{
float3 test = CustomColor1.rgb;
}

float4 mainPS( ... ) : SV_TARGET
{
func1();
...
}








As you can see, I set CustomColor1 vector in the shader file to ".969f, .765f, .605f, 1.f", but then when I step through the shader with PIX, I see that "test" has instead "1.811, 0, 0".

What the heck is going on?

This call
Effect->GetVariableByName( "CustomColor1" )->AsVector();
returned a valid pointer (not NULL).

I have also tried ID3D10EffectVariable instead of ID3D10EffectVectorVariable and setting it with
pShader->CustomColors.ptr10->SetRawValue( &v, 0, sizeof(D3DXVECTOR4) );
but to no success.

[Edited by - 16bit_port on October 1, 2010 9:13:07 AM]

Share this post


Link to post
Share on other sites
I don't see something wrong in the code you provided. Because I can't see complete source code and fx file, it is difficult to tell what is wrong. Here I give you some suggestions to help you figure it out.

1. Check if you defined at least one Technique and one Pass in your fx file?
=================================================================

In a fx file, not only does it contain some constant buffers, shaders, but also need at least one Technique and One pass like this

//=============================================================================
// color.fx by Frank Luna (C) 2008 All Rights Reserved.
//
// Transforms and colors geometry.
//=============================================================================

cbuffer cbPerObject
{
float4x4 gWVP;
};

void VS(float3 iPosL : POSITION,
float4 iColor : COLOR,
out float4 oPosH : SV_POSITION,
out float4 oColor : COLOR)
{
// Transform to homogeneous clip space.
oPosH = mul(float4(iPosL, 1.0f), gWVP);

// Just pass vertex color into the pixel shader.
oColor = iColor;
}

float4 PS(float4 posH : SV_POSITION,
float4 color : COLOR) : SV_Target
{
return color;
}

technique10 ColorTech
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );
}
}


2. Check if you called ID3D10EffectPass::Apply(0) method?
=================================================================

This method updates the constant buffers stored in GPU memory, binding the shader programs to the pipeline, and applies any render states the pass sets.

Here is some code to explain this, and error hadling code omitted.

// set constants
ID3D10EffectTechnique* pTech = NULL;
pTech = Effect->GetTechniqueByName("YourTechniqueName");

D3D10_TECHNIQUE_DESC techDesc;
pTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
{
D3DXVECTOR4 v( .969f, .765f, .605f, 1.f );
pShader->CustomColors.ptr10->SetFloatVector( (float*)&v );

pTech->GetPassByIndex( p )->Apply(0);
...
}

[Edited by - standby01 on October 1, 2010 12:03:34 AM]

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