• Create Account

Awesome job so far everyone! Please give us your feedback on how our article efforts are going. We still need more finished articles for our May contest theme: Remake the Classics

# Medo3337

Member Since 24 Apr 2012
Online Last Active Today, 05:09 PM

### #5064503Sparks Effect

Posted by on Yesterday, 09:16 AM

To anyone who could have this problem, the question was resolved here:

http://www.gamedev.net/topic/643414-drawing-multiple-lines-with-one-draw-call/

### #5062649Setting Color and Alpha Channel

Posted by on 17 May 2013 - 02:06 PM

I'm trying to set the color and alpha channel for volumetric lines.

How do I set the lines diffuse color and alpha channel?

I tried adding DWORD color; to the vertex structure and setting the FVF to:
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_DIFFUSE | D3DFVF_NORMAL |
D3DFVF_TEX2 | // D3DFVF_TEX2 specifies we have two sets of texture coordinates.
D3DFVF_TEXCOORDSIZE4(0) | // This specifies that the first (0th) tex coord set has size 4 floats.
D3DFVF_TEXCOORDSIZE3(1); // Specifies that second tex coord set has size 2 floats.

But, not working.

Vertex structure:
```struct TVertex
{
D3DXVECTOR3 pos;
D3DXVECTOR3 otherPos;
D3DXVECTOR4 texOffset;
D3DXVECTOR3 thickness;
static const DWORD FVF = D3DFVF_XYZ | D3DFVF_NORMAL |
D3DFVF_TEX2 | // D3DFVF_TEX2 specifies we have two sets of texture coordinates.
D3DFVF_TEXCOORDSIZE4(0) | // This specifies that the first (0th) tex coord set has size 4 floats.
D3DFVF_TEXCOORDSIZE3(1); // Specifies that second tex coord set has size 2 floats.
};
```

Effect file:

```//////////////////////
// Volume line shader. Based on the CG Volume Lines sample from NVidia.

float4x4 mWVP : WorldViewProjection;
float4x4 mWV : WorldView;

texture lineTexture;

sampler textureSampler = sampler_state
{
Texture = (lineTexture);
MipFilter = LINEAR;
MinFilter = LINEAR;
MagFilter = LINEAR;
};

struct TInputVertex
{
float4 pos : POSITION; // Position of this vertex
float4 otherPos : NORMAL; // Position of the other vertex at the other end of the line.
float4 texOffset : TEXCOORD0; // Tex coord offset.
float3 thickness : TEXCOORD1; // Thickness info.
};

struct TOutputVertex
{
float4 hPos : POSITION;
float blend : COLOR0;
float4 tex0 : TEXCOORD0;
float4 tex1 : TEXCOORD1;
};

TOutputVertex VolumeLineVS( TInputVertex IN )
{
TOutputVertex OUT = (TOutputVertex)0;

// World*View transformation.
float4 posStart = mul( IN.pos, mWV );
float4 posEnd = mul( IN.otherPos, mWV );

// Unit vector between eye and center of the line.
float3 middlePoint = normalize( (posStart.xyz + posEnd.xyz) / 2.0 );

// Unit vector of the line direction.
float3 lineOffset = posEnd.xyz - posStart.xyz;
float3 lineDir = normalize( lineOffset );
float lineLenSq = dot( lineOffset, lineOffset );

// Dot product to compute texture coef
float texCoef = abs( dot( lineDir, middlePoint ) );

// Change texture coef depending on line length: y=(Sz/(l^2))(x-1)+1
texCoef = max( ( (texCoef - 1) * (lineLenSq / IN.thickness.z ) ) + 1, 0 );

posStart = mul( IN.pos, mWVP );
posEnd = mul( IN.otherPos, mWVP );

// Project these points in screen space.
float2 startPos2D = posStart.xy / posStart.w;
float2 endPos2D = posEnd.xy / posEnd.w;

// Calculate 2D line direction.
float2 lineDir2D = normalize( startPos2D - endPos2D );

// Shift vertices along 2D projected line
posStart.xy += ((texCoef * IN.texOffset.x) * lineDir2D.xy);

// Shift vertex for thickness perpendicular to line direction.
lineDir2D *= IN.thickness.x;
posStart.x += lineDir2D.y;
posStart.y -= lineDir2D.x;

OUT.hPos = posStart;

// Compute tex coords depending on texCoef.
float4 tex;
tex.zw = float2(0,1);
tex.y = min(15.0/16.f, texCoef);
tex.x = modf(tex.y * 4.0, tex.y);
OUT.blend = modf(tex.x * 4.0, tex.x);
tex.xy = (tex.xy / 4.0) + (IN.texOffset).zw;
tex.y = 1-tex.y;
OUT.tex0 = tex;

// Now get the second texture coord : increment.
tex.y = min(texCoef + (1.0/16.f), 15.0/16.0 );
tex.x = modf(tex.y * 4.0, tex.y);
tex.x = floor(tex.x * 4.0);
tex.xy = (tex.xy / 4) + (IN.texOffset).zw;
tex.y = 1-tex.y;
OUT.tex1 = tex;

return OUT;
}

float4 VolumeLinePS( TOutputVertex IN ) : COLOR
{
float4 blendFactor = IN.blend;
float4 c0 = tex2D( textureSampler, IN.tex0 );
float4 c1 = tex2D( textureSampler, IN.tex1 );
return lerp( c0, c1, blendFactor );
}

technique VolumeLine
{
pass p0
{
CullMode = none;
AlphaBlendEnable = true;
SrcBlend = one;
DestBlend = one;
alpharef = 0.9;
alphafunc = GreaterEqual;
ZEnable = false;
}
}
```

### #5062520Sparks Animation

Posted by on 17 May 2013 - 02:41 AM

I'm confused.

emission is a Vector3, emission.z is a float.

If I do the following, the program will not compile:

D3DXVec3Normalize(emission.z+offset*emission.randomness);

However, I tried doing it using the way I have in my engine, it could be the same way as your way:

```void generateNewParticle()
{
// Code to generate a new particle here...
D3DXVECTOR3 randVec = GetRandomVec();
particle.velocity += randVec * 4.0f;
}```

```D3DXVECTOR3 GetRandomVec()
{
D3DXVECTOR3 vVector;
vVector.z = getRandMinMax( -1.0f, 1.0f );
float radius = (float)sqrt(1 - vVector.z * vVector.z);
float t = getRandMinMax( -D3DX_PI, D3DX_PI );
return vVector;
}
```

Althought it works, I have slight problems at the particles generation point, the particles are not looking at the moving direction when generated:

### #5062340Sparks Effect

Posted by on 16 May 2013 - 12:11 PM

Great!

The transformation issue is now resolved, now I'm trying to draw all the lines with only a single draw call, so I tried changing the following code:

```// The following code draw line per draw call (I don't want that)
TVertex vrts[4];
vrts[0].pos = v0; vrts[0].otherPos = v1;
vrts[1].pos = v1; vrts[1].otherPos = v0;
vrts[2].pos = v0; vrts[2].otherPos = v1;
vrts[3].pos = v1; vrts[3].otherPos = v0;

vrts[0].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[1].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[2].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[3].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );

vrts[0].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[1].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[2].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[3].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

d3ddev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 2, vrts, sizeof( TVertex ) );```

To:

```// In this code, I'm trying to draw multiple lines with one single draw call
TVertex vrts[8]; // 8 instead of 4 (8 = 2 lines)

// Line 1
D3DXVECTOR3 v0(0.0f, 0.0f, 0.0f);
D3DXVECTOR3 v1(0.0f, 100.0f, 0.0f);

vrts[0].pos = v0; vrts[0].otherPos = v1;
vrts[1].pos = v1; vrts[1].otherPos = v0;
vrts[2].pos = v0; vrts[2].otherPos = v1;
vrts[3].pos = v1; vrts[3].otherPos = v0;
vrts[0].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[1].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[2].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[3].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[0].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[1].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[2].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[3].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

// Line 2
D3DXVECTOR3 pV0(200.0f, 0.0f, 0.0f);
D3DXVECTOR3 pV1(200.0f, 100.0f, 0.0f);

vrts[4].pos = pV0; vrts[4].otherPos = pV1;
vrts[5].pos = pV1; vrts[5].otherPos = pV0;
vrts[6].pos = pV0; vrts[6].otherPos = pV1;
vrts[7].pos = pV1; vrts[7].otherPos = pV0;
vrts[4].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[5].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[6].thickness = D3DXVECTOR3(  g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[7].thickness = D3DXVECTOR3( -g_fThickness, 0.f, g_fThickness * 0.5f );
vrts[4].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.f );
vrts[5].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.f );
vrts[6].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.f, 0.25f );
vrts[7].texOffset = D3DXVECTOR4( g_fThickness, g_fThickness, 0.25f, 0.25f );

// Draw all lines
d3ddev->DrawPrimitiveUP( D3DPT_TRIANGLESTRIP, 4, vrts, sizeof( TVertex ) );
```

Now, the two lines are connected with each others, which of course undesired since I want to draw multiple separate lines with one draw call.

Do I have to set index buffer to draw multiple lines with one draw call? If yes, how do I fill the index buffer?

### #5061644Sparks Effect

Posted by on 13 May 2013 - 07:12 PM

How do I create realistic sparks effect?

I used different textures but I couldn't get it to look like realistic sparks.

Can someone show me a simple texture for sparks? I'm not sure how the texture should look like (1 spark texture, few sparks texture, etc...)

I'm trying to accomplish something like this:

### #5059303Bullet Impact Billboard Disappearing

Posted by on 04 May 2013 - 04:56 PM

Up.

Still unresolved.

### #5020876Need help with DirectInput

Posted by on 12 January 2013 - 04:48 PM

DirectInput is depreciated, you should handle input through Windows message loop or GetAsyncKeyState() instead.

### #5020560Increasing Line Length

Posted by on 11 January 2013 - 07:11 PM

@eppo: Thanks.

### #5018094Which DirectX to Pick

Posted by on 06 January 2013 - 12:40 AM

DX 1? That would be pretty old, DX 1.0 appeared in 1995 (since about 18 years) it's not a good idea to use a very old version, a very old version will definitely not supported bunches of important features and a well noticed graphics improvement, plus it might be not compatible with recent versions of OS since it's very old and deprecated.

If you want to create something compatible with most machines, I would say DX 9 will be fine and can give you almost the same result you get from DX 10 and DX 11.

### #5015329Restricting Camera

Posted by on 28 December 2012 - 11:29 PM

@MisterFuzzy: You really need to show some respect to other members, the problem was resolved weeks ago and I have reported your reply and yes I tried L. Spiro solution and it didn't work as expected.

### #5013346Collision detection

Posted by on 21 December 2012 - 11:58 PM

I would recommend you to consider using a physics library, there are alot of physics libraries out there that support collision detection as well as body dynamics.

Since you will be working on First-Person Shooter game, you don't need collision only but you also need to implement physics to the game.

You can consider using one of the following physics engines:
- Havok
- Bullet
- PhysX

Here you can find a list of physics engines (Most of them support collision detection):
http://www.gamedev.net/topic/475753-list-of-physics-engines-and-reference-material-updated-7-march-2011/

### #5012527Restricting Camera

Posted by on 19 December 2012 - 12:19 PM

Just to let you know, I started programming since I was around 10-11 years old, right now I'm 20, have been focusing on software and web development much more than mathematics, I know 3D games programming has alot of math involved and physics as well, I'm in hurry to complete the 3D Game Engine that I'm working on.

Thanks everyone,

### #5012442Restricting Camera

Posted by on 19 December 2012 - 08:13 AM

This is exactly what almost every book is going to give you, so if you can only handle to be spoon-fed I am not sure how far you will be able to go as a programmer.

@L. Spiro:
I don't appreciate your reply, I have been programming for 10 years in around 12 different programming/scripting languages and I'm completely new to DirectX and 3D games programming.

You seriously need to never judge other people.

Anyway, Thanks for trying to help, the question was resolved by simply decreasing max_pitch value.

### #5012411Restricting Camera

Posted by on 19 December 2012 - 06:31 AM

I want to mention that the my camera update code is probably different than what you expect, please take a look over here:
```void updateCamera()
{
if ( D3DXVec3Length( &m_velocity ) > m_maxVelocity )
{
m_velocity = *(D3DXVec3Normalize( &m_velocity, &m_velocity )) * m_maxVelocity;
}

m_position += m_velocity;
m_velocity = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );
m_lookAt = m_position + m_look;

// Calculate the new view matrix
D3DXVECTOR3 up = D3DXVECTOR3( 0.0f, 1.0f, 0.0f );
D3DXMatrixLookAtLH( &m_view, &m_position, &m_lookAt, &up );

// Set the camera axes from the view matrix
m_right.x = m_view._11;
m_right.y = m_view._21;
m_right.z = m_view._31;
m_up.x = m_view._12;
m_up.y = m_view._22;
m_up.z = m_view._32;
m_look.x = m_view._13;
m_look.y = m_view._23;
m_look.z = m_view._33;

// Calculate yaw and pitch
float lookLengthOnXZ = sqrtf( m_look.z * m_look.z + m_look.x * m_look.x );
m_pitch = atan2f( m_look.y, lookLengthOnXZ );
}
```

The FPS camera is working perfectly, except the little problem that I mentioned (When the up angle is 90 degree and the player try to rotate the mouse up more, right/left start to work which show that the player is rotating around himself).

I have uploaded a video to explain the problem better:

### #5012348Restricting Camera

Posted by on 19 December 2012 - 12:22 AM

@L. Spiro: The code I'm using to change "Pitch":
```void Camera::pitch(float radians)
{
if (m_pitch > m_maxPitch)
{
}
else if (m_pitch < -m_maxPitch)
{
}

D3DXMATRIX matRotation;