Smooth xfade between geometries

Hello!
Does anyone here know to ‘morph’ between two geometries?, my idea is to have two different models and then being able to go from one to another by interpolating their geometries. Is that possible?

thanks!

Two approaches, one slow but easy to integrate with other techniques, and one fast but harder to integrate.

Good Luck!

Hey, thanks for the link
i have been trying to make this work but i am getting an error on the vertex shader:
variable Out without having been completely initialized.

I also tried to change the name of the Texcoord0 on the struct declaration but the problem is persisting.
The error is spotted on both the vertex shader return and on the technique compilation. What am I missing here?

///////////////////////////////
float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (EX9)
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;

float MorphFactor;
float4 Color1: COLOR;
float4 Color2: COLOR;

//texture
texture Tex <string uiname=“Texture”;>;
sampler Samp = sampler_state //sampler for doing the texture-lookup
{
Texture = (Tex); //apply a texture to the sampler
MipFilter = LINEAR; //sampler states
MinFilter = LINEAR;
MagFilter = LINEAR;
};

//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX <string uiname=“Texture Transform”;>;

struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};

// --------------------------------------------------------------------------------------------------
// VERTEXSHADERS
// --------------------------------------------------------------------------------------------------
vs2ps VS(
float4 PosO : POSITION,
float4 PosO2 : TEXCOORD0)
{
//declare output struct
vs2ps Out;

//transform position
//Out.Pos = mul(PosO, tWVP);
//Out.Pos = mul(MorphFactor * PosO + (1-MorphFactor) * PosO2, tWVP);
Out.Pos = mul(lerp(PosO, PosO2, MorphFactor), tWVP);



//transform texturecoordinates
//Out.TexCd = mul(TexCd, tTex);

return Out;

}

// --------------------------------------------------------------------------------------------------
// PIXELSHADERS:
// --------------------------------------------------------------------------------------------------

float4 PS(vs2ps In): COLOR
{
return lerp(Color1, Color2, MorphFactor);
}

// --------------------------------------------------------------------------------------------------
// TECHNIQUES:
// --------------------------------------------------------------------------------------------------

technique TSimpleShader
{
pass P0
{
//Wrap0 = U; // useful when mesh is round like a sphere
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_0 PS();
}
}

technique TFixedFunction
{
pass P0
{
//transforms
WorldTransform0 = (tW);
ViewTransform = (tV);
ProjectionTransform = (tP);

    //texturing
    Sampler[0](0) = (Samp);
    TextureTransform[0](0) = (tTex);
    TexCoordIndex[0](0) = 0;
    TextureTransformFlags[0](0) = COUNT2;
    //Wrap0 = U;  // useful when mesh is round like a sphere
    
    Lighting       = FALSE;

    //shaders
    VertexShader = NULL;
    PixelShader  = NULL;
}

}

change your first line in the vertexshader to

vs2ps Out = (vs2ps)0;

should work

ao,

your outputstruct is defined as:

code(lang=hlsl):
struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};

so it has 2 fields. in the vertexshader though you only write to the .Pos field. the line setting the .TexCd is commented out. if you uncomment this line it should work.

hey, thanks joreg!

herewith the fixed shader, it might be useful for some other people:

float4x4 tW: WORLD; //the models world matrix
float4x4 tV: VIEW; //view matrix as set via Renderer (EX9)
float4x4 tP: PROJECTION;
float4x4 tWVP: WORLDVIEWPROJECTION;

float MorphFactor;
float4 Color1: COLOR;
float4 Color2: COLOR;

//texture
texture Tex <string uiname=“Texture”;>;
sampler Samp = sampler_state //sampler for doing the texture-lookup
{
Texture = (Tex); //apply a texture to the sampler
MipFilter = LINEAR; //sampler states
MinFilter = LINEAR;
MagFilter = LINEAR;
};

//texture transformation marked with semantic TEXTUREMATRIX to achieve symmetric transformations
float4x4 tTex: TEXTUREMATRIX <string uiname=“Texture Transform”;>;

struct vs2ps
{
float4 Pos : POSITION;
float2 TexCd : TEXCOORD0;
};

// --------------------------------------------------------------------------------------------------
// VERTEXSHADERS
// --------------------------------------------------------------------------------------------------
vs2ps VS(
float4 PosO : POSITION,
float4 PosO2 : TEXCOORD0)
{
//declare output struct
vs2ps Out = (vs2ps)0;

//transform position
//Out.Pos = mul(PosO, tWVP);
//Out.Pos = mul(MorphFactor * PosO + (1-MorphFactor) * PosO2, tWVP);
Out.Pos = mul(lerp(PosO, PosO2, MorphFactor), tWVP);



//transform texturecoordinates
//Out.TexCd = mul(TexCd, tTex);

return Out;

}

// --------------------------------------------------------------------------------------------------
// PIXELSHADERS:
// --------------------------------------------------------------------------------------------------

float4 PS(vs2ps In): COLOR
{
return lerp(Color1, Color2, MorphFactor);
}

// --------------------------------------------------------------------------------------------------
// TECHNIQUES:
// --------------------------------------------------------------------------------------------------

technique TSimpleShader
{
pass P0
{
//Wrap0 = U; // useful when mesh is round like a sphere
VertexShader = compile vs_1_1 VS();
PixelShader = compile ps_1_0 PS();
}
}

technique TFixedFunction
{
pass P0
{
//transforms
WorldTransform0 = (tW);
ViewTransform = (tV);
ProjectionTransform = (tP);

    //texturing
    Sampler[0](0) = (Samp);
    TextureTransform[0](0) = (tTex);
    TexCoordIndex[0](0) = 0;
    TextureTransformFlags[0](0) = COUNT2;
    //Wrap0 = U;  // useful when mesh is round like a sphere
    
    Lighting       = FALSE;

    //shaders
    VertexShader = NULL;
    PixelShader  = NULL;
}

}

on more question(rather new to HLSL):
what is the difference between declaring :
vs2ps Out and

vs2ps Out = (vs2ps)0;

isn’t that declaration the same as to say in GLSL:
gl_Position = ftransform();

thanks!

don’t know about glsl, but:

vs2ps Out = (vs2ps)0;

is simply initializing the structure named Out of type vs2ps to all zeros. i.e. both fields of the struct will be initialized to be 0 and therefore no longer be un-initialized which the compiler complained about.

roger that!
thanks a lot!

Would be very kind of you if you can just upload this shader, with a nice help patch and add it to the contributions.

:)