Sign in to follow this  
skyfire360

CgFX: Effect-SetMatrix does nothing?

Recommended Posts

Heya! I'm trying to splice Cg into an existing fixed-function framework, but I'm getting some weird behavior. I know the vertex program runs correctly because if I just set the VS_OUTPUT : POSITION semantic to the literal position and the COLOR0 register to the model's coordinate (the model is smaller than the 2x2x2 homogeneous screen-space cube), it displays the model. However, when I try to pass in a matrix to the shader, the matrix doesn't appear to be set. I guess some example code would be in order: My shader:
//------------------------------------
uniform float4x4 matWVP : WorldViewProjection;

//------------------------------------
struct vertexInput {
    float3 Position	: POSITION;
};

struct vertexOutput {
    float4 HPosition : POSITION;
    float4 Diffuse : COLOR0;
};

//------------------------------------
vertexOutput VS_TransformDiffuse(vertexInput IN) 
{
    vertexOutput OUT;
    //OUT.HPosition = mul( float4(IN.Position.xyz , 1.0) , matWVP);
    OUT.HPosition.x = max(-1, IN.Position.x);
    OUT.HPosition.y = max(-1, IN.Position.y);
    OUT.HPosition.z = max(-1, IN.Position.z);
    OUT.HPosition.w = 1;
    OUT.Diffuse = float4(matWVP[0][0],0.0,0.0,1.0f);
    return OUT;
}

float4 PS_TransformDiffuse(vertexOutput IN) : COLOR0 {
	return IN.Diffuse;
}

//-----------------------------------
technique SolidOrange
{
    pass p0 
    {		
		VertexShader = compile vs_1_1 VS_TransformDiffuse();
		PixelShader = compile ps_1_1 PS_TransformDiffuse();
    }
}

And in my source code:
float matrixT[4][4] = {
	{1,0,0,0},
	{0,1,0,0},
	{0,0,1,0},
	{0,0,0,1}
};
cgEffect->SetMatrix(cgEffect->GetParameterBySemantic(NULL, "WorldViewProjection"), &matrixT[0][0], 4, 4);

..snip..

HRESULT result = cgEffect->Begin(&numPassesL, 0);
if(FAILED(result)) {
	cgError("Error beginning shader: ");
}

HRESULT result = cgEffect->Pass(pPass);
if(FAILED(result)) {
	cgError("Error starting pass: ");
}

..draw mesh..

HRESULT result = cgEffect->End();
if(FAILED(result)) {
	cgError("Error ending pass: ");
}

The output of this program should be a solid red mesh. However, the mesh appears as solid black. There are no errors returned by the resulting HRESULTs. Any ideas why the matrix is being destroyed between passing it in and the vertex shader?

Share this post


Link to post
Share on other sites
*Update*

After doing a ton of testing, I've discovered that no matter what I'm initializing and where I'm setting it, I can't seem to set any global variables. Otherwise, the effect is rendered perfectly. Any ideas on why I can't access/set global variables in my FX file, even though Cg does not return any errors and FXComposer accepts and works great with the file?

Share this post


Link to post
Share on other sites
erm... don´t know exactly, but I set matrices in the shader simply by
effect->SetMatrix("WorldViewProjection", &mat_wvp);

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