Jump to content

  • Log In with Google      Sign In   
  • Create Account


FX Composer issues with cgfx


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Nanook   Members   -  Reputation: 468

Like
0Likes
Like

Posted 18 March 2012 - 07:00 PM

I got a basic CgFX shader working in FX composer that has transformation and texturing, but I'm having some issues.. If I render it in OpenGL mode It renders fine in the perspective view, but in the material view the sample sphere doesnt show, the whole thing is black..

If I change to DirectX9 or 10 only a red wireframe mesh shows up, both in the material preview and in the perspective view.. CG is cross platform, but what about CgFX? Do I need a .fx file for rendering cg shaders in directx? If so, would I need that in my application aswell?

void mainVS(float4 position : POSITION,
   float3 normal  : NORMAL,
   float2 texCoord : TEXCOORD0,
   out float4 oPosition : POSITION,
   out float2 oTexCoord : TEXCOORD0,
   uniform float4x4 viewProjection,
   uniform float4x4 world)
{
	 oPosition = mul(world, position);
	 oPosition = mul(viewProjection, oPosition);
	 oTexCoord = texCoord;
}
void mainFS(float2 texCoord : TEXCOORD0,
   out float4 color  : COLOR,
   uniform sampler2D colorSampler)
{
	 color = tex2D(colorSampler, texCoord);
}

float4x4 world : World;
float4x4 viewProjection : ViewProjection;

texture colorTexture  <
    string ResourceName = "default_color.dds";
    string UIName =  "Diffuse Texture";
    string ResourceType = "2D";
>;
sampler2D colorSampler = sampler_state {
    Texture = <colorTexture>;
	 generateMipMap = true;
    MinFilter = LinearMipMapLinear;
    MagFilter = Linear;
    WrapS = Repeat;
    WrapT = Repeat;
};

technique basic_textured_dx_40
{
	 pass
	 {
  		  FragmentProgram = compile ps_2_0 mainFS(colorSampler);
  		  VertexProgram = compile vs_2_0 mainVS(viewProjection, world);
  		  DepthTestEnable = true;
  		  DepthMask = true;
     }
}

technique basic_textured_ogl_40
{
pass
	 {
  		  FragmentProgram = compile fp40 mainFS(colorSampler);
  		  VertexProgram = compile vp40 mainVS(viewProjection, world);
  		  DepthTestEnable = true;
  		  DepthMask = true;
     }
}


Sponsor:

#2 amirabiri   Members   -  Reputation: 163

Like
0Likes
Like

Posted 07 May 2012 - 06:58 AM

I've just come across the exact same problem myself... did you solve it?

#3 madRenEGadE   Members   -  Reputation: 190

Like
0Likes
Like

Posted 09 May 2012 - 10:48 AM

Maybe this is because DX and OpenGL use different coordinate systems? If this is the case try to change

[color=#000000][size=2][left]oPosition [/left][/size][/color][color=#666600][size=2][left]=[/left][/size][/color][color=#000000][size=2][left] mul[/left][/size][/color][color=#666600][size=2][left]([/left][/size][/color][color=#000000][size=2][left]world[/left][/size][/color][color=#666600][size=2][left],[/left][/size][/color][color=#000000][size=2][left] position[/left][/size][/color][color=#666600][size=2][left]);[/left][/size][/color]
[color=#000000][size=2][left]oPosition [/left][/size][/color][color=#666600][size=2][left]=[/left][/size][/color][color=#000000][size=2][left] mul[/left][/size][/color][color=#666600][size=2][left]([/left][/size][/color][color=#000000][size=2][left]viewProjection[/left][/size][/color][color=#666600][size=2][left],[/left][/size][/color][color=#000000][size=2][left] oPosition[/left][/size][/color][color=#666600][size=2][left]);[/left][/size][/color]


to

[color=#000000][size=2][left]oPosition [/left][/size][/color][color=#666600][size=2][left]=[/left][/size][/color][color=#000000][size=2][left] mul[/left][/size][/color][color=#666600][size=2][left]([/left][/size][/color][color=#000000][size=2][left]position[/left][/size][/color][color=#666600][size=2][left],[/left][/size][/color][color=#000000][size=2][left] world[/left][/size][/color][color=#666600][size=2][left]);[/left][/size][/color]
[color=#000000][size=2][left]oPosition [/left][/size][/color][color=#666600][size=2][left]=[/left][/size][/color][color=#000000][size=2][left] mul[/left][/size][/color][color=#666600][size=2][left]([/left][/size][/color][color=#000000][size=2][left]oPosition[/left][/size][/color][color=#666600][size=2][left],[/left][/size][/color][color=#000000][size=2][left] viewProjection[/left][/size][/color][color=#666600][size=2][left]);[/left][/size][/color]


#4 madRenEGadE   Members   -  Reputation: 190

Like
0Likes
Like

Posted 09 May 2012 - 10:50 AM

Sry for that... just tried to copy the code from the shader code.
In short:

change the order of the parameters in the calls to "mul"

#5 amirabiri   Members   -  Reputation: 163

Like
0Likes
Like

Posted 09 May 2012 - 01:53 PM

I posted the question on Stack Overflow and it doesn't seem like anyone has an answer for it there either.

I've done a lot of investigations and tried many different things, and the bottom line I think is that our hardware doesn't support certain profiles.

For example for Direct3D 10 you need shader model 4 it seems. However when I tried changing the profiles of the effect from vs_3_0/ps_3_0 to vs_4_0/ps_4_0, I got an error that my hardware doesn't support it.

I also found a forum thread on nvidia's site where a member of nvidia's staff mentioned something along the lines of FX Composer not supporting cgfx with Direct3D. I've also come across multiple forum posts all over the web (very old mostly) talking about cg dead/dying/will die, nvidia not supporting it and so on.

Also note the FX Composer FAQ, scroll down and you'll find

Q: "Does FX Composer work with Cg or GLSL?"

A: "We are always evaluating opportunites to provide powerful tools for developers, but have no plans to add support for other languages to FX Composer. FX Composer was built to support the large number of developers using HLSL in their applications."


So basically, I think the bottom line is this:
  • Some of the problems we are seeing are related to the hardware capabilities (or lack of them).
  • Some of the problems are related to restrictions of FX Composer.
For me since my objective is purely to learn shaders in general, the solution was to stick to HLSL and Direct3D 9. I will verify my suspicion about DirectX 10 when I have access to a newer card on another machine that I have.

There is also an interesting (old) forum thread here on gamedev: http://www.gamedev.net/topic/281349-hlsl-vs-cg-any-significant-difference/

#6 amirabiri   Members   -  Reputation: 163

Like
0Likes
Like

Posted 09 May 2012 - 05:03 PM

OK I take it back in regards to DirectX 10, I managed to get it to work on the HLSL/.fx side (not Cg/.cgfx).

It seems that the .fx templates that FX Composer generates by default only provide a DirectX 9 technique. With DirectX 10, you need to use the technique10 keyword instead of technique. The technique10 keyword has different syntax. Where previously it looked like this:
technique technique1 {
pass p0 {
  VertexShader = compile vs_3_0 mainVS();
  PixelShader = compile ps_3_0 mainPS();
}
}

With DirectX 10 it should look like this:
technique10 technique_dx10 {
pass p0 {
  SetVertexShader( CompileShader( vs_4_0, mainVS() ) );
  SetPixelShader( CompileShader( ps_4_0, mainPS() ) );
}
}

With this your effect will work both on DirectX 9 and DirectX 10. It's a shame nVidia didn't make FX Composer generate both to begin with.

You can find the various bits and pieces of the technique10 syntax online (mainly on microsoft's website).

Edited by amirabiri, 09 May 2012 - 05:05 PM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS