Jump to content
  • Advertisement
Sign in to follow this  
Chamu256

Please Help ! (CgFx)

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

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
Advertisement
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
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!