Flame.fx (FIRE animation) - - SOLVED

Started by
41 comments, last by circlesoft 19 years, 4 months ago
I've used the oeriginal FX file and a modified one with all original textures:

flame.png
noiseL8_32x32x32.dds

I've seen that in FX composer it works well, but in the EffectEdit doesn't...

I've also tried to change XFile parameter in the FX file, but results are the same...

I can't get out!!!

THANKS ^__^
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Advertisement
Have you got a working appz using this FLAME.fx effect?!

Could someone send me or post here a working version of using this effect file?! [gents@email.it]

THANKS!!!
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Hi,

I've used this effect to render the flames and burning coals inside the flame (with a simple change of texture). I cant send the code as render portions are inside of my engine.

FXComposer effects wont work in Effect Edit. Effects arent universal. Any app that tres to use an effect must understand the effect parameters. Thats why the semantics are used, to give a hint to the host app about how to use it. But if the app doesn't understand the semntics, the effect can't be used.

I'd suggest you try other simpler effects before trying this one. Maybe one that deforms the objects using time. Then try some time moving texture coordinates. After that you can try loading the flame effect.

Luck!
Guimo

OK...
You've make me happy helping me, but please don't leave me alone now ^__^

I've added my ticks and I've tested, the increment is regular, but I can't see anything new on my screen...

I'm trying any type of solution, but I can't understand why it doesn't work for me... I've changed mesh reference, I've tried a lot of parameters, I've debugged my application, everything seems ok but my screen is always the same...

I've tried with tons of other simpler effects, but seems that this one doesn't works... In FX Composer it's ok, works well with original textures, other ones, or with original parameters or changed...

In my appz I could always watch at a white or transparent quad without any effect on it...

But code seems ok...

Where am I wrong?! Where is the bug to fix in my code?!

Should I not use an .X file to render effect on?! Should I use a VertexBuffer filled in a strange way?!

I could not understand...

Please help me! ^__^

----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Hi,

I'd suggest:

a. Leave the effect default values. Those value are set the moment the effect is compiled and will never change so no need to set them, that is, delete this lines.

g_pEffect->SetFloat( "ticks", (float)QuantoVeloce );
g_pEffect->SetFloat( "noiseFreq", 0.1f );
g_pEffect->SetFloat( "noiseStrength", 1.0f );
g_pEffect->SetFloat( "timeScale", 1.0f );

g_pEffect->SetValue( "noiseScale", D3DXVECTOR3(0.5, 0.5, 0.5), sizeof(D3DXVECTOR3) );
g_pEffect->SetValue( "noiseAnim", D3DXVECTOR3(0.4, -1.9, 0.8), sizeof(D3DXVECTOR3) );

g_pEffect->SetValue( "flameColor", D3DXVECTOR4(0.3, 0.2, 0.2, 1.0), sizeof(D3DXVECTOR4) );
g_pEffect->SetValue( "flameScale", D3DXVECTOR3(0.25, -0.18, 0.12), sizeof(D3DXVECTOR3) );
g_pEffect->SetValue( "flameTrans", D3DXVECTOR3(0.0, -0.1, 0.0), sizeof(D3DXVECTOR3) );


b. Notice that the only parameters without a default value are:
texture noiseTexture;
texture flameTexture;

float ticks : Time
<
string units = "sec";
>;

float4x4 wvp : WorldViewProjection;
float4x4 world : World;

From those, the first two can be set only once when you load the effect (as you already do). The other three must change each frame. Also, the time parameter has an annotation that tells you that this parameter should receive seconds (not milliseconds... forgot that before). But if you check this line in the VS:
OUT.NoisePos = worldPos*noiseScale*noiseFreq + time*timeScale*noiseAnim;

You can see that the time parameter is multiplied by the timeScale parameter. So you can send milliseconds but change the time scale appropiately when you load the effect. In case you send millisecond, timeScale probably should be set to 0.001f. Your choice.

The matrices should be changes each frame before you render the effect. And it should be fine or you wouldnt be seeing the quad at all.

c. Third. Check the required input:
vertexOutput flameVS(appdata IN,
uniform float4x4 WorldViewProj,
uniform float4x4 World,
uniform float3 noiseScale,
uniform float noiseFreq,
uniform float3 noiseAnim,
uniform float3 flameScale,
uniform float3 flameTrans,
uniform float timeScale
)

If you are using default values, and you have set time and matrices, then all the uniform parameters are already set. In fact, you may just simplify this line to:
vertexOutput flameVS(appdata IN)

So, you should check the required input here:
struct appdata {
float3 Position : POSITION;
float4 UV : TEXCOORD0;
float4 Tangent : TANGENT0;
float4 Binormal : BINORMAL0;
float4 Normal : NORMAL;
};

So, you must seee that your vertices should have all this information (OR MORE) but no less. In case od a quad it is really simple to set this values in your mesh at creation time. Position ad UV values are simple (set UV as the usual 0,1 values). The Tangent, binormal and normal are vectors that define the space over you triangle. So just compute the normal to the plane (easy math), the tangent to the plane (easier math) and the binormal (the cross vector from the other two), and set those values. As your plane is flat, just set the same values to all your points. Thats all.

I have nothing else to comment. But if you manage to do it, it is the same basic configuration to create bump, waves, water and many of the special effects in FXComposer.

Luck!
Guimo

Only one last thing...

How do you think that must be FLAME_FVF ?!?!

THANKS
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
I've tried also creating a VertexBuffer filled with data as Guimo said, but it still doesn't works...

I've seen that an essential part that I don't know how fill is the FVF, so I've arranged with getFVF() from my g_FlameMesh...

But it doesn't work...

Where is the problem?!

THANKS for help!!!!
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Quote:Original post by GENTS
I've seen that an essential part that I don't know how fill is the FVF, so I've arranged with getFVF() from my g_FlameMesh...


(1) You need to create a Vertex Declaration. FVF's are a thing of the past, and were used for the fixed-function-pipeline. Now, we use the IDirect3DVertexDeclaration9 to describe to the vertex shader what the structure of our vertex buffer looks like. Read my post here to see how this is commonly done. Remember, the structure of your vertex buffer needs to match your vertex declaration, and your vertex declaration needs to match the input of your vertex shader.

(2) I'm not so sure this effect was meant to be applied to a 3D mesh. It might have been designed to be rendered to a flat plane, not complex geometry. This makes sense, because it is simply drawing flames on the object dynamically. Most shaders that have post-processing effects like this were meant for 2D sprites.

(3) If you keep encountering problems, try debugging this shader (this is an extremely useful tool). Read this SDK page to find out how to use it.
Dustin Franklin ( circlesoft :: KBase :: Mystic GD :: ApolloNL )
Ok I'll try with your suggests and then I'll tell you results

^__^

If I can't use my .X file mesh I'll create a single Vertex Buffer for my quad and then I'll re-try...

Thanks for hel an stay on-line for results...

^__^

----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -
Ok that's my new code:

Declarations:
// Vertex shader declarationD3DVERTEXELEMENT9 g_FlameMeshDecl[] ={  { 0,  0, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },  { 0, 12, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },  { 0, 28, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TANGENT, 0 },  { 0, 44, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_BINORMAL, 0 },  { 0, 60, D3DDECLTYPE_FLOAT4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL, 0 },  D3DDECL_END()};// the struct for flame vertsstruct FLAMEVERT{    D3DXVECTOR3 p;    D3DXVECTOR4 tex;	D3DXVECTOR4 t;	D3DXVECTOR4 b;	D3DXVECTOR4 n;};IDirect3DVertexDeclaration9 *g_FlameDecl = NULL;


Init()
	// Create a big square for rendering flames    g_pD3DDevice->CreateVertexBuffer( 4*sizeof(FLAMEVERT),                                       D3DUSAGE_WRITEONLY, NULL,                                       D3DPOOL_MANAGED, &g_FlameVB, NULL );    // Set the size of the big square and fill its fields    FLAMEVERT* fv;    FLOAT fx = (FLOAT)200;    g_FlameVB->Lock( 0, 0, (void**)&fv, 0 );	 fv[0].p = D3DXVECTOR3(  -2*fx, fx, -fx );    fv[1].p = D3DXVECTOR3(  -2*fx,  0, 0 );    fv[2].p = D3DXVECTOR3( -fx, fx, -fx );    fv[3].p = D3DXVECTOR3( -fx,  0, 0 );	 fv[0].tex = D3DXVECTOR4( 0, 0, 0, 0 );    fv[1].tex = D3DXVECTOR4( 0, 1, 0, 1 );    fv[2].tex = D3DXVECTOR4( 1, 0, 1, 0 );    fv[3].tex = D3DXVECTOR4( 1, 1, 1, 1 );	 fv[0].t = D3DXVECTOR4( 0, 1, 0, 0 );    fv[1].t = D3DXVECTOR4( 0, 1, 0, 0 );    fv[2].t = D3DXVECTOR4( 0, 1, 0, 0 );    fv[3].t = D3DXVECTOR4( 0, 1, 0, 0 );	 fv[0].b = D3DXVECTOR4( 1, 0, 0, 0 );    fv[1].b = D3DXVECTOR4( 1, 0, 0, 0 );    fv[2].b = D3DXVECTOR4( 1, 0, 0, 0 );    fv[3].b = D3DXVECTOR4( 1, 0, 0, 0 );	 fv[0].n = D3DXVECTOR4( 0, 0, 1, 0 );    fv[1].n = D3DXVECTOR4( 0, 0, 1, 0 );    fv[2].n = D3DXVECTOR4( 0, 0, 1, 0 );    fv[3].n = D3DXVECTOR4( 0, 0, 1, 0 );    g_FlameVB->Unlock();         // create effect file	LPD3DXBUFFER pBufferErrors = NULL;	if( FAILED( D3DXCreateEffectFromFile( g_pD3DDevice, PathFlameEffect, 					NULL, // CONST D3DXMACRO* pDefines,					NULL, // LPD3DXINCLUDE pInclude,					dwShaderFlags, NULL, &g_pEffect, &pBufferErrors  ))){			OutputDebugString( "Errore nel caricamento del file Flame.fx\n" );			LPVOID pCompilErrors = pBufferErrors->GetBufferPointer();			MessageBox(NULL, (const char*)pCompilErrors, "Fx Compile Error", MB_OK|MB_ICONEXCLAMATION);		}        //Set Technique, parameters, etc.		D3DXHANDLE Tecn = g_pEffect->GetTechnique( 0 );		if (FAILED(g_pEffect->SetTechnique(Tecn)))			OutputDebugString( "Impossibile settare la Technique ps20\n" );		if( FAILED( g_pEffect->SetFloat( "noiseFreq", 0.1f ) ))			OutputDebugString( "Impossibile assegnare noiseFreq\n" );		if( FAILED( g_pEffect->SetFloat( "noiseStrength", 1.0f ) ))			OutputDebugString( "Impossibile assegnare noiseStrength\n" );		if( FAILED( g_pEffect->SetFloat( "timeScale", 1.0f ) ))			OutputDebugString( "Impossibile assegnare timeScale\n" );		D3DXVECTOR3 noiseScale = D3DXVECTOR3(0.5, 0.5, 0.5);		D3DXVECTOR3 noiseAnim = D3DXVECTOR3(0.4, -1.9, 0.8);		if( FAILED( g_pEffect->SetValue( "noiseScale", noiseScale, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare noiseScale\n" );		if( FAILED( g_pEffect->SetValue( "noiseAnim", noiseAnim, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare noiseAnim\n" );		D3DXCOLOR flameColor = D3DXCOLOR(0.3, 0.2, 0.2, 1.0);		D3DXVECTOR3 flameScale = D3DXVECTOR3(0.25, -0.18, 0.12);		D3DXVECTOR3 flameTrans = D3DXVECTOR3(0.0, -0.1, 0.0);		if( FAILED( g_pEffect->SetValue( "flameColor", &flameColor, sizeof(D3DXCOLOR) ) ))			OutputDebugString( "Impossibile assegnare flameColor\n" );		if( FAILED( g_pEffect->SetValue( "flameScale", flameScale, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare flameScale\n" );		if( FAILED( g_pEffect->SetValue( "flameTrans", flameTrans, sizeof(D3DXVECTOR3) ) ))			OutputDebugString( "Impossibile assegnare flameTrans\n" );		if( FAILED( g_pEffect->SetTexture( "noiseTexture", g_FlameTexture1 ) ))			OutputDebugString( "Impossibile assegnare noiseTexture\n" );		if( FAILED( g_pEffect->SetTexture( "flameTexture", g_FlameTexture2 ) ))			OutputDebugString( "Impossibile assegnare flameTexture\n" );


Render()
    UINT cPasses=0; 	// Apply the technique contained in the effect 		if( SUCCEEDED( g_pEffect->SetTechnique("ps20") ) ){					ticks = (float)GetTickCount()/1000;			g_pEffect->SetFloat( "ticks", ticks );			g_pD3DDevice->GetTransform( D3DTS_WORLD, &mWorld );			g_pD3DDevice->GetTransform( D3DTS_VIEW, &mView );			g_pD3DDevice->GetTransform( D3DTS_PROJECTION, &mProj );			mWorldViewProjection = mWorld * mView * mProj;			g_pEffect->SetMatrix( "wvp", &mWorldViewProjection );			g_pEffect->SetMatrix( "world", &mWorld );			g_pEffect->Begin(&cPasses, 0);					for (iPass = 0; iPass < cPasses; iPass++)			{					    g_pEffect->BeginPass(iPass);							    // Render the mesh with the applied technique				g_pEffect->GetVertexShader( "VertexShader", &g_FlameVS );				g_pD3DDevice->SetFVF(NULL);				g_pD3DDevice->SetVertexShader(g_FlameVS);				g_pD3DDevice->SetVertexDeclaration(g_FlameDecl);				g_pD3DDevice->SetStreamSource( 0, g_FlameVB, 0, sizeof(FLAMEVERT) );				g_pD3DDevice->DrawPrimitive( D3DPT_TRIANGLESTRIP, 0, 2 );						    g_pEffect->EndPass();			}			g_pEffect->End();		}


BUT IT STILL DOESN'T WORK!!!

Where is the new error/problem?!


This is the screen withOUT this code:
			    // Render the mesh with the applied technique				g_pEffect->GetVertexShader( "VertexShader", &g_FlameVS );				g_pD3DDevice->SetFVF(NULL);				g_pD3DDevice->SetVertexShader(g_FlameVS);				g_pD3DDevice->SetVertexDeclaration(g_FlameDecl);




and this is with:



Thanks for help!

[Edited by - GENTS on January 6, 2005 4:14:57 PM]
----------------------------------------------- - GENTS -"Every man dies, not every man really lives"[William Wallace] - visit my website: GENTS.it -- Using Effect files with DirectX 9 Basics Tutorial -- MilkShape 3D models and OpenGL ES Tutorial -

This topic is closed to new replies.

Advertisement