Jump to content
  • Advertisement
Sign in to follow this  
Patrick Polzin

[Cg] Setting a parameter will be ignored

This topic is 3406 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

Hello, I'm new to Cg Shaders from nVidia and have developed a small wrapper to handle these shaders. All will be apply as I want but there is one thing that let me not sleep: Setting a parameter. So first here's the history how the working with parameters will done: I'm using Cg Effects (cgfx) and load them with their techniques. So first I get my parameter handle after creating the context, effect and assigning techniques, this works sucessfull and the handle is valid:
// Get effect data
if(!ShaderContext.Create(Device)) return 0;
cgSetErrorCallback(CgErrorCallback); // temporary
if(!Shader.Create("Shader.cgfx", ShaderContext)) return 0;
if(!Shader.AssignTechnique("Render")) return 0;

// example:
if(!Shader.GetParameter("color", Color, false)) return 0;
The Color instance of the parameter class safes a CGparameter handle whoose valid. Next for rendering before I apply a technique I'm setting the values I want:
…
Color.Set4(1.0f, 0.0f, 0.0f, 1.0f);
	
Shader.BeginPass(0 /* technique index */, 0 /* pass index */);
Device.DrawIndexed(30);
Shader.EndPass(0);
…
Setting the parameter will done like this:
void Set4(const float x, const float y, const float z, const float w)
{
	cgSetParameter4f(_Parameter, x, y, z, w);
}
The technique will applied with this code:
const bool BeginPass(const UINT PassNr)
{
	if(PassNr >= _Pass.size()) return false;

	cgUpdatePassParameters(_Pass[PassNr]);
	cgSetPassState(_Pass[PassNr]);
					
	_LastActive = PassNr;
	return true;
}
So when I want to assign the value to this test shader:
float4 color : Color;

struct VS_OUT
{
	float4 Pos : POSITION;
	float4 Col : COLOR0;
};

VS_OUT vs_main(float3 pos : POSITION, float3 nor : NORMAL)
{
	VS_OUT Out = (VS_OUT)0;
	Out.Pos = float4(pos.xyz, 1.0);
	Out.Col = color;
	return Out;
}

float4 ps_main(VS_OUT Out) : COLOR
{
	return Out.Col;
}

technique Render
{
	pass p0
    {
		VertexProgram = compile vs_4_0 vs_main();
		FragmentProgram = compile ps_4_0 ps_main();
	}
}
The parameter wouldn't apply. Has anybody an idea why this doesn't work? Thanks for help!

Share this post


Link to post
Share on other sites
Advertisement
Can't see anything obviously wrong with what you've posted...

Some obvious things to check though:

Does anything render at all? Try outputting a colour defined in teh shader.
Have you run the program through pix?
Have you checked for any cg errors?
Have you double checked the parameter is 100% valid.

My guess is theres something in your wrapper thats causing the problems (been writing on myself recently so i know how easy it is to bork it :P)

Share this post


Link to post
Share on other sites
Hi,

Yes it is still rendering the triangles. Yeah, running with none errors, DirectX debug output is also applied. Cg Errors don't come. Watching to the parameter is showing none invalid addresses. But I'm think that I'm nearer to the problem:

// The parameter address is valid. So I set the value, like this:
cgSetParameter4f(_Parameter, 1.0f, 0.0f, 0.0f, 1.0f); for uniform float4 Color;

// Then, before applying the pass, I update the pass parameters:
cgUpdatePassParameters(_Pass[PassNr]);

// Next I'm setting the vertex data and binding the pass to DirectX and draw the shape, after it I unbind the pass:
Device.SetVertices(VertexBuffer);
cgSetPassState(_Pass[PassNr]);
Device.Draw(3);
cgResetPassState(_Pass[PassNr]);


I see it is also that what the manual says - but it doesn't still work. I also applying following:

cgSetParameterSettingMode(ShaderContext.Get(), CG_DEFERRED_PARAMETER_SETTING);
cgSetSemanticCasePolicy(CG_UNCHANGED_CASE_POLICY);


But that doesn't work and no errors will come.

Additionally you can see here the (wrapper) code for all implementation detail:
bscgeffect.h: The effect framework
main.cpp: The test implementation
SphereShader.cgfx: The Cg Shader

Thanks for help!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!