Sign in to follow this  
akira32

cartoon shadering in NVIDIA FX Compoer

Recommended Posts

The Shader text file toon.fx comes from the sample of the Book "Introduction to 3D Game Programming with DirectX9.0"'s chapter17. Its' result is rendering a teapot with cartoon shader. So I Installed the NVIDIA FX Composer,and load toon.fx and create a teapot. When I click the toon.fx and then "Apply to selection", the Composer appears two error message as below: toon.fx : ID3DXEffectCompiler: There were no techniques toon.fx : ID3DXEffectCompiler: Compilation failed Does the statements of toon.fx have problem? Or the Shader file in the Composer must correspond to some rule? //////////////////////////////////////////////////////////////////////////// // // File: toon.txt // // Author: Frank Luna (C) All Rights Reserved // // System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0 // // Desc: Vertex shader that lights geometry such it appears to be // drawn in a cartoon style. // //////////////////////////////////////////////////////////////////////////// // // Globals // extern matrix WorldViewMatrix; extern matrix WorldViewProjMatrix; extern vector Color; extern vector LightDirection; // // Structures // struct VS_INPUT { vector position : POSITION; vector normal : NORMAL; }; struct VS_OUTPUT { vector position : POSITION; float2 uvCoords : TEXCOORD; vector diffuse : COLOR; }; // // Main // VS_OUTPUT Main(VS_INPUT input) { // zero out each member in output VS_OUTPUT output = (VS_OUTPUT)0; // transform vertex position to homogenous clip space output.position = mul(input.position, WorldViewProjMatrix); // // Transform lights and normals to view space. Set w // components to zero since we're transforming vectors. // Assume there are no scalings in the world // matrix as well. // LightDirection.w = 0.0f; input.normal.w = 0.0f; LightDirection = mul(LightDirection, WorldViewMatrix); input.normal = mul(input.normal, WorldViewMatrix); // // Compute the 1D texture coordinate for toon rendering. // float u = dot(LightDirection, input.normal); // // Clamp to zero if u is negative because u // negative implies the angle between the light // and normal is greater than 90 degrees. And // if that is true then the surface receives // no light. // if( u < 0.0f ) u = 0.0f; // // Set other tex coord to middle. // float v = 0.5f; output.uvCoords.x = u; output.uvCoords.y = v; // save color output.diffuse = Color; return output; }

Share this post


Link to post
Share on other sites
Hi,

the file you have there is a Cg shader and not a CgFX file. There is a difference between the two. Just open some of the files that come with fx composer and you will see that they are fairly similar, but (as the error message indicates) a .fx file consists of techniques and passes that in turn consist of shader code.

Hope this helps you

Bart

Share this post


Link to post
Share on other sites
Ok I try CgFx file again.

I Installed the Composer and tried to run a cartoon shader file called "tooneffect.fx"(it should be CgFX file)
(tooneffect.fx come from a book called "Introduction to 3D Game Programming with Directx 9.0"'s chapter 19 sample "CartoonEffect")
I tried to load "tooneffect.fx" to Composer and set the Shadertex to be "toonshade.bmp"(at Properties Panel), and then "Apply to Selection".
At last,the object I had selected disappeared.
I use Composer to compile the shader file "tooneffect.fx". Get the message as below:
Building...
Created HLSL EffectCompiler: C:\Documents and Settings\user\My Documents\00CartoonEffect\00CartoonEffect\tooneffect.fx
Creating Material: _25
Reloading Material due to change: tooneffect, Effect: C:\Documents and Settings\user\My Documents\00CartoonEffect\00CartoonEffect\tooneffect.fx
Build Complete - Updated: 2 materials associated with Effect: C:\Documents and Settings\user\My Documents\00CartoonEffect\00CartoonEffect\tooneffect.fx
Errors: 0, Warnings: 0
Created HLSL Effect from EffectCompiler: C:\Documents and Settings\user\My Documents\00CartoonEffect\00CartoonEffect\tooneffect.fx
Found valid technique: Toon
Technique: Toon Validated for this device

////////////////////////////////////////////////////////////////////////////
//
// File: tooneffect.txt
//
// Author: Frank Luna (C) All Rights Reserved
//
// System: AMD Athlon 1800+ XP, 512 DDR, Geforce 3, Windows XP, MSVC++ 7.0
//
// Desc: Cartoon shader in an effect file.
//
////////////////////////////////////////////////////////////////////////////

//
// Globals
//

extern matrix WorldViewMatrix;
extern matrix WorldViewProjMatrix;

extern vector Color;
extern vector LightDirection;
extern texture ShadeTex;

//
// Structures
//

struct VS_INPUT
{
vector position : POSITION;
vector normal : NORMAL;
};

struct VS_OUTPUT
{
vector position : POSITION;
float2 uvCoords : TEXCOORD;
vector diffuse : COLOR;
};
//
// Main
//

VS_OUTPUT Main(VS_INPUT input)
{
// zero out each member in output
VS_OUTPUT output = (VS_OUTPUT)0;


// transform vertex position to homogenous clip space
output.position = mul(input.position, WorldViewProjMatrix);

//
// Transform lights and normals to view space. Set w
// components to zero since we're transforming vectors.
// Assume there are no scalings in the world
// matrix as well.
//
LightDirection.w = 0.0f;
input.normal.w = 0.0f;
LightDirection = mul(LightDirection, WorldViewMatrix);
input.normal = mul(input.normal, WorldViewMatrix);

//
// Compute the 1D texture coordinate for toon rendering.
//
float u = dot(LightDirection, input.normal);

//
// Clamp to zero if u is negative because u
// negative implies the angle between the light
// and normal is greater than 90 degrees. And
// if that is true then the surface receives
// no light.
//
if( u < 0.0f )
u = 0.0f;

//
// Set other tex coord to middle.
//
float v = 0.5f;


output.uvCoords.x = u;
output.uvCoords.y = v;

// save color
output.diffuse = Color;

return output;
}

//
// Sampler
//

sampler ShadeSampler = sampler_state
{
Texture = (ShadeTex);
MinFilter = POINT; // no filtering for cartoon shading
MagFilter = POINT;
MipFilter = NONE;
};


//
// Effect
//

technique Toon
{
pass P0
{
vertexShader = compile vs_1_1 Main();

Sampler[0] = (ShadeSampler);
}
}

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