Sign in to follow this  
Chamu256

Please Help ! (CgFx)

Recommended Posts

Hy all I have a big problem with nvidia CgFx. I wrote the following effect file: float4x4 World; float4x4 View; float4x4 Projection; technique Tech { pass p01 { VertexProgram = compile vs_2_0 Red(World,View,Projection); //ever vertex will have red color } //draw wireframed mesh pass p02 { VertexProgram = NULL; ZEnable = false; LightingEnable = false; PolygonMode = Line; } } In the main loop i have something like this: Pass = cgGetFirstPass(technique2); while (Pass) { cgSetPassState(Pass); Box->Draw(RenderSystem); cgResetPassState(Pass); Pass = cgGetNextPass(Pass); } I should see a red box and on top of it a wireframed box.But the only thing i see is a red box. But when i correct the code following way: Pass = cgGetFirstPass(technique2); while (Pass) { cgSetPassState(Pass); Box->Draw(RenderSystem); cgResetPassState(Pass); D3DDevice->SetVertexShader(NULL); Pass = cgGetNextPass(Pass); } Everything works fine. I hope you understand what i mean becasue my english is very bad.

Share this post


Link to post
Share on other sites
I'm not an expert on cgFX, but I think it's because you aren't using a vertex shader or pixel shader at all. I don't see any code to transform the positions into homogeneous clip space etc... So when you write D3DDevice->SetVertexShader(NULL); you just fall back to the Fixed Function Pipeline and everything renders like normal.

You should try to write a vertex shader that takes the positions of your boxes and transforms them into homogeneous clip space and passes them to the pixel shader.

Example of a basic vertex shader:
struct VertexIn
{
float4 position : POSITION;
float4 color : COLOR;
};

struct VertexOut
{
float4 position : POSITION;
float4 color : COLOR;
};

VertexOut main(VertexIn In,
uniform float4x4 modelViewProj,
{
VertexOut Out;
Out.position = mul(modelViewProj, In.position);

return Out;
}

Example of a basic pixel shader:
struct FragmentIn
{
float4 pos : POSITION;
float4 color : COLOR;
};

struct FragmentOut
{
float4 color : COLOR;
};

FragmentOut main(FragmentIn In)
{
FragmentOut Out;

Out.color = In.color;

return Out;
}

Ofcourse with such a simple effect, you could always keep using the FFP, and everything will be fine. Just one tip: I wouldn't compile this for ShaderModel 2.0, as that would rule out a lot of older cards...

Hope I've been able to help,
Jeroen

Share this post


Link to post
Share on other sites
I definetely agree with godmodder, implement at least the vertex program and check whether it works, if not implement the fragment program as well, then it should definetely work.

Share this post


Link to post
Share on other sites
First i would like to thank you for trying to answer my stupid question. I think
you don`t realy understand what i want to say.I didn`t explain it very well.(I`m so stupid :(

So the vertex program called 'Red' does perform the transformation and works, i
tested it. It looks like this:

struct Output {
float4 Pos: POSITION;
float3 Color: COLOR;
};

Output Red(float4 Position: POSITION,
uniform float4x4 World,
uniform float4x4 View,
uniform float4x4 Projection)
{
Output OUT;

float4x4 WorldView = mul(View,World);
float4x4 WorldViewProjection = mul(Projection,WorldView);

OUT.Pos = mul(WorldViewProjection,Position);

OUT.Color = float3(1,0,0);

return OUT;
}

But the problem is that i can`t deactivate it. It seems to me that
VertexProgram = NULL in the second pass has no effect. The vertex shader remains
active. The only why i can deactivate it is D3DDevice->SetVertexShader(NULL).
Can this be a bug in CgFx or there is a problem with me? :(


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