@belfegor: That means I will have to draw most meshes twice? That will not be a good idea for performance, drawing everything twice?
- Viewing Profile: Reputation: Medo3337
Community Stats
- Group Members
- Active Posts 672
- Profile Views 4,235
- Member Title Member
- Age Age Unknown
- Birthday Birthday Unknown
-
Gender
Male
User Tools
Contacts
Medo3337 hasn't added any contacts yet.
Latest Visitors
#5064691 Light Shader
Posted by Medo3337
on 24 May 2013 - 11:01 PM
#5064503 Sparks Effect
Posted by Medo3337
on 24 May 2013 - 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/
#5063897 Light Shader
Posted by Medo3337
on 22 May 2013 - 11:14 AM
I don't even know how to write shader for lights, so I'm looking for any example out that can be used with FFP to create any type of light anywhere in the scene.
#5063870 Light Shader
Posted by Medo3337
on 22 May 2013 - 10:07 AM
I'm looking for a shader example that I can use to setup any type of light in any position in the scene.
#5062649 Setting Color and Alpha Channel
Posted by Medo3337
on 17 May 2013 - 02:06 PM
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.
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;
VertexShader = compile vs_2_0 VolumeLineVS();
PixelShader = compile ps_2_0 VolumeLinePS();
}
}
#5062520 Sparks Animation
Posted by Medo3337
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 );
vVector.x = (float)cosf(t) * radius;
vVector.y = (float)sinf(t) * radius;
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:
#5062340 Sparks Effect
Posted by Medo3337
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?
#5061644 Sparks Effect
Posted by Medo3337
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:
#5059303 Bullet Impact Billboard Disappearing
Posted by Medo3337
on 04 May 2013 - 04:56 PM
Up.
Still unresolved.
#5020876 Need help with DirectInput
Posted by Medo3337
on 12 January 2013 - 04:48 PM
DirectInput is depreciated, you should handle input through Windows message loop or GetAsyncKeyState() instead.
#5020560 Increasing Line Length
Posted by Medo3337
on 11 January 2013 - 07:11 PM
@eppo: Thanks.
#5018094 Which DirectX to Pick
Posted by Medo3337
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.
#5015329 Restricting Camera
Posted by Medo3337
on 28 December 2012 - 11:29 PM
#5013346 Collision detection
Posted by Medo3337
on 21 December 2012 - 11:58 PM
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/
#5012527 Restricting Camera
Posted by Medo3337
on 19 December 2012 - 12:19 PM
Thanks everyone,
- Home
- » Viewing Profile: Reputation: Medo3337


Find content