Jump to content

  • Log In with Google      Sign In   
  • Create Account

-Tau-

Member Since 13 Jul 2011
Offline Last Active Sep 14 2014 12:14 PM

Topics I've Started

Unsigned int in vertex shader

14 September 2014 - 10:49 AM

I'm trying to pass unsigned int number to vertex shader, but the shader acts like it gets only the first byte of that number.

 

Vertex structure:

struct HMMULTITEX
{
    D3DXVECTOR3 pos;
    D3DXVECTOR3 norm;
    D3DXVECTOR2 tex;
    UINT texID;
};

Vertex declaration

D3DVERTEXELEMENT9 aVertDecl[] =

{
    { 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },
    { 0, 12, D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_NORMAL,   0 },
    { 0, 24, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },
    { 0, 32, D3DDECLTYPE_UBYTE4, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 1 },
    D3DDECL_END()
};

 

HLSL code:

unsigned int vTexHeight : TEXCOORD1
out float oTH[8] : TEXCOORD3

unsigned int retnum=vTexHeight % 0x10;
oTH[0]=(retnum/15.0f);
	
retnum=vTexHeight/0x10;
retnum=retnum % 0x10;
oTH[1]=(retnum/15.0f);

retnum=vTexHeight/0x100;
retnum=retnum % 0x10;
oTH[2]=(retnum/15.0f);

retnum=vTexHeight/0x1000;
retnum=retnum % 0x10;
oTH[3]=(retnum/15.0f);

...oTH[7]

Problem: Only oTH[0] and oTH[1] works, all other ale allways 0. It looks like vertex shader gets only the first byte of vTexHeight.
Everything above 0xff is ignored.
How can i pass unsigned int to vertex shader? Why is current vertex shader ignoring anything above the first byte?


XAudio2 Exception 80000003

31 January 2014 - 01:55 AM

First, idon't know where i should post this, so i post it here.

I'm using XAudio2 in my game for sound. Playing unmodified sound works well but when i use SetOutputMatrix program crashes with Exception 80000003.

void AUDIO_STATE::UpdateAudio(simpleSound *in_ss)
{
	X3DAudioCalculate( x3DInstance, &listener, &in_ss->emitter, dwCalcFlags, &dspSettings );

	if (in_ss->p_SV)
	{
		in_ss->p_SV->SetFrequencyRatio( dspSettings.DopplerFactor );
		in_ss->p_SV->SetOutputMatrix( pMasteringVoice, INPUTCHANNELS, nChannels, matrixCoefficients );
		in_ss->p_SV->SetOutputMatrix( pSubmixVoice, 1, 1, &dspSettings.ReverbLevel );

		XAUDIO2_FILTER_PARAMETERS FilterParametersDirect = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * dspSettings.LPFDirectCoefficient), 1.0f };
		in_ss->p_SV->SetOutputFilterParameters(pMasteringVoice, &FilterParametersDirect);
		XAUDIO2_FILTER_PARAMETERS FilterParametersReverb = { LowPassFilter, 2.0f * sinf(X3DAUDIO_PI/6.0f * dspSettings.LPFReverbCoefficient), 1.0f };
		in_ss->p_SV->SetOutputFilterParameters(pSubmixVoice, &FilterParametersReverb);
	}
}

When i remove lines in_ss->p_SV->SetOutputMatrix, there are no problems, the sound plays.

Did someone ever had similar problem? Do you know what could cause this?

 

Also most of initialization of my sound engine is a modification to DX sdk XAudio2Sound3D.


Texture colors, debug/release

19 September 2013 - 02:29 AM

Everything works fine in debug version, but when i switch to release shadows and reflection above water are somehow weird. Some objects wont cast shadows at all, and some doesn't seem to work properly. Problems with reflection are only above water. Below water works both relfection and refraction, but above water is only refraction ok, reflection is diplayed with wrong colors.

I include images, also UI textures are darker in release version. Some aren't aven visible, no idea why.

 

Does anyone know the possible reasons for such errors?

 

debug reflection

http://img.pictureup.cz/19092013/1b316d7bb5b2a3834edcb9f95d131c3e4858b906.png

release reflection

http://img.pictureup.cz/19092013/658e95aa048d149cf5687bac130f8daf2878dc91.png

debug shadows

http://img.pictureup.cz/19092013/7f865425919898796061b76a9b3d90849ca386f1.png

release shadows

http://img.pictureup.cz/19092013/8c30b92c80259e75887593cd465149eb412e4996.png

 

Edit:

Refraction is wrong too when rendering below water, which means rendering geometry above water to texture doesn't work as it should.


Animation blending

18 May 2013 - 11:31 AM

Hi everyone,

I have model of a 1-persone submarine with 3 animations. ATM i'm working only with 2 of them: first for back elevator up/down turning and second for side turbine up/down turning. (they are independent)

I'm trying to blend animations with ID3DXAnimationController-s SetTrackPriority, SetTrackEnable and SetTrackWeight. When i have only one enabled it plays correctly, but when i try to blend them, they run only to middle. If i try to play them with double speed they still run only to middle but 2-times. I tried to set SetTrackWeight for both to 0.5 and then both to 1.0 but it didn't work.

Is it possible to blend such animations with ID3DXAnimationController or are there different ways?


Particle rendering problem

21 September 2012 - 03:19 AM

Hi all,
I need som advice for vertex declaration / FVF with particles. Main issue is the texture on particles.
When i first created particle class and class to manipulate with particles, particle vertex had position normal and texcoord. After a while i understood that particle do not need a normal so i removed it. After that particle were either not drawn or drawn with only 1 color. First i used FVF, then i changed to vertex declaration in hope it will solve this problem.


struct PARTICLEVERTEX

{

	D3DXVECTOR3 pos;

	float tu, tv;

};



#define D3DFVF_PARTICLEVERTEX (D3DFVF_XYZ|D3DFVF_TEX1)



void ParticleSystem::OnCreate(IDirect3DDevice9* pd3dDevice)

{

	PARTICLEVERTEX *_Vertices = new PARTICLEVERTEX[4];

	VOID *_pVertices;

	pd3dDevice->CreateVertexBuffer( 4* sizeof( PARTICLEVERTEX ),

									0, 0,

									D3DPOOL_MANAGED, &m_pVB, NULL );

	m_pVB->Lock( 0, 0, ( void** )&_pVertices, 0 );

	{

		_Vertices[0].pos=D3DXVECTOR3(-0.5 , -0.5, 0);

		_Vertices[0].tu=0;

		_Vertices[0].tv=1;

		_Vertices[1].pos=D3DXVECTOR3(-0.5 , 0.5, 0);

		_Vertices[1].tu=0;

		_Vertices[1].tu=0;

		_Vertices[2].pos=D3DXVECTOR3(0.5 , -0.5, 0);

		_Vertices[2].tu=1;

		_Vertices[2].tv=1;

		_Vertices[3].pos=D3DXVECTOR3(0.5 , 0.5, 0);

		_Vertices[3].tu=1;

		_Vertices[3].tv=0;

	}

	memcpy( _pVertices, _Vertices, sizeof(PARTICLEVERTEX)*4 );

	m_pVB->Unlock();

	delete []_Vertices;



	D3DVERTEXELEMENT9 f_par_VDecl[] =

	{

		{ 0, 0,  D3DDECLTYPE_FLOAT3, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_POSITION, 0 },

		{ 0, 12, D3DDECLTYPE_FLOAT2, D3DDECLMETHOD_DEFAULT, D3DDECLUSAGE_TEXCOORD, 0 },

		D3DDECL_END()

	};



	pd3dDevice->CreateVertexDeclaration( f_par_VDecl, &m_pDecl );

}



void ParticleSystem::draw(ID3DXEffect* pEffect, IDirect3DDevice9* pd3dDevice, double fTime, float fElapsedTime)

{

	if (!pfpar)

		return;



	if (pfpar->time_to_die<fTime)

	{

		particle *tdelete=pfpar;

		pfpar=pfpar->pnext;

		delete tdelete;

	}



	particle *akt=pfpar;



	UINT iP,cP;

	HRESULT hr;

	D3DXMATRIXA16 mWorld;

	pd3dDevice->SetStreamSource( 0, m_pVB, 0, sizeof( PARTICLEVERTEX ) );

	pd3dDevice->SetVertexDeclaration( m_pDecl );



	while (akt)

	{

		if (akt->pnext)

			if (akt->pnext->time_to_die<(float)fTime)

			{

				particle *tdelete=akt->pnext;

				akt->pnext=akt->pnext->pnext;

				delete tdelete;

			}



		akt->move(fTime, fElapsedTime);

		D3DXMatrixTranslation(&mWorld, akt->pos.x, akt->pos.y, akt->pos.z);



		V( pEffect->SetTexture( g_efn->g_txScene, v_ints_tex[akt->i_tex].v_tex[akt->akt_texture] ) );

		

		V( pEffect->SetFloat( g_efn->particleScale, akt->scale) );

		V( pEffect->SetVector( g_efn->g_MaterialColor, &akt->color) );

		V( pEffect->SetMatrix( g_efn->g_mWorld, &mWorld ) );

		V( pEffect->Begin( &cP, 0 ) );

		for( iP = 0; iP < cP; iP++ )

		{

			V( pEffect->BeginPass( iP ) );

			pd3dDevice->DrawPrimitive(	D3DPT_TRIANGLESTRIP, 0, 2);

			pEffect->EndPass();

		}

		pEffect->End();



		akt=akt->pnext;

	}

}



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

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

void ParticleVS(float4 iPos : POSITION,

				float2 iTex : TEXCOORD0,

				out float4 oPos : POSITION,

				out float2 oTex : TEXCOORD0)

{

	float4x4 wv = mul(g_mWorld, g_mView);

	oPos = iPos*float4(particleScale, particleScale, particleScale, 1.0) + float4(wv._41, wv._42, wv._43, 0.0);

	oPos = mul( oPos, g_mProj );

	oTex = iTex;

}



float4 ParticlePS(float2 iTex : TEXCOORD0) : COLOR0

{

	return tex2D(g_samScene, iTex)*g_MaterialColor;

}

PARTNERS