Fx Problem

Topics: Developer Forum, Project Management Forum, User Forum
Mar 29, 2007 at 8:39 AM
I got this error :

The effects on the model for a ModelAnimator were changed without calling ModelAnimator.InitializeEffectParams().

when trying to use a fx file i generated using NVidia FX Composer. is there any way to fix this?
Mar 29, 2007 at 8:48 AM
Edited Mar 29, 2007 at 8:56 AM
btw the file content is like this :


************************************************

#include <vnoise-table.fxh>

float Script : STANDARDSGLOBAL <
string UIWidget = "none";
string ScriptClass = "object";
string ScriptOrder = "standard";
string ScriptOutput = "color";
string Script = "Technique=vBomb;";
> = 0.8;

//////////////////////////////////////////////////////////////
// UNTWEAKABLES //////////////////////////////////////////////
//////////////////////////////////////////////////////////////

float timer : TIME <string UIWidget="None";>;
float4x4 WorldViewProj : WORLDVIEWPROJECTION <string UIWidget="None";>;

//////////////////////////////////////////////////////////////
// TWEAKABLES ////////////////////////////////////////////////
//////////////////////////////////////////////////////////////

float Displacement <
string UIWidget = "slider";
float UIMin = 0.0;
float UIMax = 2.0;
float UIStep = 0.01;
> = 1.6f;

float Sharpness <
string UIWidget = "slider";
float UIMin = 0.1;
float UIMax = 5.0;
float UIStep = 0.1;
> = 1.90f;

float ColorSharpness <
string UIWidget = "slider";
float UIMin = 0.1;
float UIMax = 5.0;
float UIStep = 0.1;
> = 3.0f;

float Speed <
string UIWidget = "slider";
float UIMin = 0.01;
float UIMax = 1.0;
float UIStep = 0.001;
> = 0.3f;

float TurbDensity <
string UIWidget = "slider";
float UIMin = 0.01;
float UIMax = 8.0;
float UIStep = 0.001;
> = 2.27f;

float ColorRange <
string UIWidget = "slider";
float UIMin = -6.0;
float UIMax = 6.0;
float UIStep = 0.01;
> = -2.0f;

float4x4 NoiseMatrix = {1,0,0,0, 0,1,0,0, 0,0,1,0, 0,0,0,1};

//float4 dd5 = {
// 0,2,3,1, 2,2,2,2, 3,3,3,3, 4,4,4,4, 5,5,5,5 };

//////////////////////////// texture ///////////////////////

texture GradeTex
<
string ResourceName = "FireGrade.bmp";
string ResourceType = "2D";
string UIName = "Fire Gradient";
>;

sampler2D GradeSampler = sampler_state
{
Texture = <GradeTex>;
MinFilter = Linear;
MagFilter = Linear;
MipFilter = Linear;
AddressU = clamp;
};

///////////// functions

// this is the smoothstep function f(t) = 3t^2 - 2t^3, without the normalization
float3 s_curve(float3 t) { return t * t * ( float3(3,3,3) - float3(2,2,2) * t); }
float2 s_curve(float2 t) { return t * t * ( float2(3,3) - float2(2,2) *t); }
float s_curve(float t) { return t * t * (3.0-2.0 * t); }

// 3D version
float noise(float3 v,
const uniform float4 pgFULLSIZE)
{
v = v + float3(10000.0f, 10000.0f, 10000.0f); // hack to avoid negative numbers

float3 i = frac(v * NOISEFRAC) * BSIZE; // index between 0 and BSIZE-1
float3 f = frac(v); // fractional position

// lookup in permutation table
float2 p;
p.x = pg i[0] .w;
p.y = pg i[0] + 1 .w;
p = p + i1;

float4 b;
b.x = pg p[0] .w;
b.y = pg p[1] .w;
b.z = pg p[0] + 1 .w;
b.w = pg p[1] + 1 .w;
b = b + i2;

// compute dot products between gradients and vectors
float4 r;
r0 = dot( pg b[0] .xyz, f );
r1 = dot( pg b[1] .xyz, f - float3(1.0f, 0.0f, 0.0f) );
r2 = dot( pg b[2] .xyz, f - float3(0.0f, 1.0f, 0.0f) );
r3 = dot( pg b[3] .xyz, f - float3(1.0f, 1.0f, 0.0f) );

float4 r1;
r10 = dot( pg b[0] + 1 .xyz, f - float3(0.0f, 0.0f, 1.0f) );
r11 = dot( pg b[1] + 1 .xyz, f - float3(1.0f, 0.0f, 1.0f) );
r12 = dot( pg b[2] + 1 .xyz, f - float3(0.0f, 1.0f, 1.0f) );
r13 = dot( pg b[3] + 1 .xyz, f - float3(1.0f, 1.0f, 1.0f) );

// interpolate
f = s_curve(f);
r = lerp( r, r1, f2 );
r = lerp( r.xyyy, r.zwww, f1 );
return lerp( r.x, r.y, f0 );
}

// 2D version
float noise(float2 v,
const uniform float4 pgFULLSIZE)
{
v = v + float2(10000.0f, 10000.0f);

float2 i = frac(v * NOISEFRAC) * BSIZE; // index between 0 and BSIZE-1
float2 f = frac(v); // fractional position

// lookup in permutation table
float2 p;
p0 = pg i[0] .w;
p1 = pg i[0]+1 .w;
p = p + i1;

// compute dot products between gradients and vectors
float4 r;
r0 = dot( pg p[0] .xy, f);
r1 = dot( pg p[1] .xy, f - float2(1.0f, 0.0f) );
r2 = dot( pg p[0]+1 .xy, f - float2(0.0f, 1.0f) );
r3 = dot( pg p[1]+1 .xy, f - float2(1.0f, 1.0f) );

// interpolate
f = s_curve(f);
r = lerp( r.xyyy, r.zwww, f1 );
return lerp( r.x, r.y, f0 );
}

// 1D version
float noise(float v,
const uniform float4 pgFULLSIZE)
{
v = v + 10000.0f;

float i = frac(v * NOISEFRAC) * BSIZE; // index between 0 and BSIZE-1
float f = frac(v); // fractional position

// compute dot products between gradients and vectors
float2 r;
r0 = pgi.x * f;
r1 = pgi + 1.x * (f - 1.0f);

// interpolate
f = s_curve(f);
return lerp( r0, r1, f);
}

/////////////////////////////

struct appData
{
float4 Position : POSITION;
float4 Normal : NORMAL;
float4 TexCoord0 : TEXCOORD0;
};

// define outputs from vertex shader
struct vertexOutData
{
float4 HPosition : POSITION;
float4 Color0 : COLOR0;
};

////////

vertexOutData mainVS(appData IN) {
vertexOutData OUT;
float4 noisePos = TurbDensity * mul(IN.Position+(Speed * timer),NoiseMatrix);
float i = (noise(noisePos.xyz, NTab) + 1.0f) * 0.5f;
float cr = 1.0-(0.5+ColorRange * (i-0.5));
cr = pow(cr,ColorSharpness);
OUT.Color0 = float4((cr).xxx, 1.0f);
// displacement along normal
float ni = pow(abs(i),Sharpness);
i -= 0.5;
//i = sign(i) * pow(i,Sharpness);
// we will use our own "normal" vector because the default geom is a sphere
float4 Nn = float4(normalize(IN.Position).xyz,0);
float4 NewPos = IN.Position - (Nn * (ni-0.5) * Displacement);
//position.w = 1.0f;
OUT.HPosition = mul(NewPos,WorldViewProj);
return OUT;
}

float4 hotPS(vertexOutData IN) : COLOR {
float2 nuv = float2(IN.Color0.x,0);
float4 nc = tex2D(GradeSampler,nuv);
return nc;
}

//////////////////////

technique vBomb <
string Script = "Pass=p0;";
> {
pass p0 <
string Script = "Draw=geometry;";
> {
VertexShader = compile vs20 mainVS();
ZEnable = true;
ZWriteEnable = true;
CullMode = None;
AlphaBlendEnable = false;
PixelShader = compile ps2a hotPS();
}
}

************************************************

and since i thought the parameters are supplied from inside the file, i only do this on setting the effect :

foreach (ModelMesh mesh in myModel.Meshes)
{
for (int i = 0; i < mesh.MeshParts.Count; i++)
{
ModelMeshPart part = mesh.MeshPartsi;

BasicPaletteEffect palette = (BasicPaletteEffect)part.Effect;
part.Effect = myEffect.Clone(graphics.GraphicsDevice);
palette.Dispose();
}
}
Coordinator
Mar 29, 2007 at 10:20 PM
You need to call the InitializeEffectParams on the animator after you change the effects because there is no way for the animator to know you did it automatically. (Technically, it already does most of the time, but that is sort of a hack so I'd like to keep it the way it is)
Mar 30, 2007 at 2:01 AM
Edited Mar 30, 2007 at 2:02 AM
Okay, so I called the InitializeEffectParams after

foreach (ModelMesh mesh in myModel.Meshes)

is done.. and the error is still the same.. I try to call it after

myAnimator = new ModelAnimator(this, myModel);

and now the error is at

base.Draw(gameTime);

on

method Draw(GameTime gameTime)

with the error message :

The method call is invalid.

confusing..
Coordinator
Mar 30, 2007 at 8:14 AM
Sorry, I didn't fully read the code. To use a custom effect, it has to support hardware skinning by having/using a world param and MatrixPalette param. The animation is done on the hardware through the vertex shader. Your shader doesn't use a matrix palette, but if you read up on matrix palette skinning or go through the custom effect tutorial you may be able to figure out how to modify it.
Apr 2, 2007 at 3:30 AM
I'll see to it then. anyway, sometimes I get this error :

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

is it dangerous?
Coordinator
Apr 2, 2007 at 5:45 AM

EricGunawan wrote:
I'll see to it then. anyway, sometimes I get this error :

Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

is it dangerous?


I remember getting that back in beta1 (I think). For me, it wasn't related to the content pipeline, just something that happened every now and then, and I could fix it by restarting GSE. In most cases it shouldn't be dangerous.. but I don't know for sure.

Did you install the Visual C# Express service pack before installing XNA game studio express? Other than that, I don't know what could cause it.
Apr 2, 2007 at 7:24 AM
yeah i did. first the C# Express then the XNA game studio. well most of the time i'd also just restart the GSE. i just wondered wether this could be an issue in the near future.