Jump to content

  • Log In with Google      Sign In   
  • Create Account


Calneon

Member Since 01 Dec 2010
Offline Last Active Nov 10 2012 10:50 AM

Topics I've Started

Drawing a path on a grid

15 June 2012 - 12:07 PM

I'm making a game where people can design their own castles, and I'm not sure how to go about making the walls connect up properly. I have different tiles such as crosses, t-junctions, corners, straight lines, diagonals, straight to diagonal, etc, and I need to know which one to use based on each tile's adjacent tiles. I was thinking some sort of lookup table but I don't have any experience using them and wouldn't know where to start. Another option would be to have 8 different wall sections compromising the 8 directions, that meet in the middle, and use them according to which tiles are adjacent. However, they wouldn't meet perfectly in the center so I want to avoid this option if I can.

Need urgent help with shadow mapping!

14 May 2012 - 02:43 PM

I've been spending the best part of two full days trying to implement shadow mapping in a Metro app I'm making at uni, but I've hit a brick wall and I want this done by tomorrow. I have the depth texture rendering to a 2D texture fine, and I send it to the shader along with the view and projection matrices of the light. However, when I project the depth texture onto the scene it doesn't work properly! Here's what it looks like:

Depth map (1024x1024, ignore the crappy UI being rendered over the top)

Posted Image

And here it is projected:

Posted Image

Might be a bit hard to see but it looks like it's projecting the whole texture onto a few models, seemingly randomly.

The shader can obviously access the texture fine. The light's view and projection matrices are both fine because I tested them by swapping them with the camera view and projection matrices. I'm really stumped because I haven't made progress for at least 5 hours. Here's the shader code:

Vertex:

cbuffer SimpleConstantBuffer : register( b0 )
{
	float4x4 model;
float4x4 view;
float4x4 projection;
float4 lightPosition;
float4x4 lightView;
float4x4 lightProjection;
int ObjectObstruction;
float UnitHealth;
int Buffer1;
int Buffer2;
};
struct sVSInput
{
	float3 position : POSITION;
	float3 normal : NORMAL;
	float2 tex : TEXCOORD0;
};
struct sPSInput
{
	float4 position : SV_POSITION;
	float3 normal : NORMAL;
	float2 tex : TEXCOORD0;
float4 lightViewPosition : TEXCOORD1;
float3 lightPos : TEXCOORD2;
};
sPSInput SimpleVertexShader(sVSInput input)
{
	sPSInput output;
float4 worldPosition;
// Calculate the position of the vertex against the world, view, and projection matrices.
	float4 temp = float4(input.position, 1.0f);
	temp = mul(temp, model);
	temp = mul(temp, view);
	temp = mul(temp, projection);
	output.position = temp;
// Calculate the position of the vertice as viewed by the light source.
	output.lightViewPosition = mul(input.position, model);
	output.lightViewPosition = mul(output.lightViewPosition, lightView);
	output.lightViewPosition = mul(output.lightViewPosition, lightProjection);
// Store the texture coordinates for the pixel shader.
	output.tex = input.tex;
// Calculate the normal vector against the world matrix only.
	output.normal = mul(float4(input.normal, 1.0f), (float3x3)model);
// Normalize the normal vector.
	output.normal = normalize(output.normal);
// Calculate the position of the vertex in the world.
	worldPosition = mul(input.position, model);
	// Determine the light position based on the position of the light and the position of the vertex in the world.
	output.lightPos = lightPosition.xyz - worldPosition.xyz;
	// Normalize the light position vector.
	output.lightPos = normalize(output.lightPos);
	return output;
}

Pixel:

//////////////
// TEXTURES //
//////////////
Texture2D SimpleTexture : register(t0);
Texture2D DepthTexture : register(t1);
///////////////////
// SAMPLE STATES //
///////////////////
SamplerState SampleTypeClamp: register(s0);
SamplerState SampleTypeWrap: register(s1);
cbuffer SimpleConstantBuffer : register( b0 )
{
float4x4 model;
float4x4 view;
float4x4 projection;
float4 lightPosition;
float4x4 lightView;
float4x4 lightProjection;
int ObjectObstruction;
float UnitHealth;
int Buffer1;
int Buffer2;
};
struct sPSInput
{
	float4 position : SV_POSITION;
	float3 normal : NORMAL;
	float2 tex : TEXCOORD0;
float4 lightViewPosition : TEXCOORD1;
float3 lightPos : TEXCOORD2;
};
float4 SimplePixelShader(sPSInput input) : SV_TARGET
{
float bias;
float2 projectTexCoord;
float depthValue;
float lightDepthValue;
float lightIntensity;
	float3 lightDirection = float3(0.5, -1, -0.5);
float4 lightColour = float4(0.8f, 0.8f, 0.8f, 1.0f);
float4 ambientColour = float4(0.2f, 0.2f, 0.2f, 1.0f);
float4 diffuseColour = float4(1.0f, 1.0f, 1.0f, 1.0f);
	float4 colour = ambientColour;
float3 lightPos = float3(lightPosition.x, lightPosition.y, lightPosition.z);
// Set the bias value for fixing the floating point precision issues.
bias = 0.001f;
// Calculate the projected texture coordinates.
projectTexCoord.x =  input.lightViewPosition.x / input.lightViewPosition.w / 2.0f + 0.5f;
projectTexCoord.y = -input.lightViewPosition.y / input.lightViewPosition.w / 2.0f + 0.5f;
// Determine if the projected coordinates are in the 0 to 1 range.  If so then this pixel is in the view of the light.
if((saturate(projectTexCoord.x) == projectTexCoord.x) && (saturate(projectTexCoord.y) == projectTexCoord.y))
{
  // Sample the shadow map depth value from the depth texture using the sampler at the projected texture coordinate location.
  depthValue = DepthTexture.Sample(SampleTypeClamp, projectTexCoord).r;
  // Calculate the depth of the light.
  lightDepthValue = input.lightViewPosition.z / input.lightViewPosition.w;
  // Project the texture.
  return float4(depthValue, depthValue, depthValue, 1.0f);
}
// Calculate the amount of light on this pixel.
lightIntensity = saturate(dot(input.normal, input.lightPos));
if(lightIntensity > 0.0f)
{
  // Determine the final diffuse color based on the diffuse color and the amount of light intensity.
  colour += (diffuseColour * lightIntensity);
  // Saturate the final light color.
  colour = saturate(colour);
}
// Get the texture colour.
float4 texColour = SimpleTexture.Sample(SampleTypeWrap, input.tex);
return colour * texColour;
}

The code is from here. Any help is very appreciated.

Definition of Perlin Noise

25 March 2012 - 08:19 AM

I'm a bit confused about what the definition of Perlin Noise actually is.

This article suggests that the Perlin Noise function refers to how different octaves of noise are added together, but it does not matter what method is used to generate the random number,

However the wikipedia page suggests that Perlin Noise refers to the actual noise function, while adding different octaves of noise creates fractal noise.

It seems to me that the first article is using the term Perlin Noise in the wrong way, I just wanted to check before I use it as a source for some work I'm doing. Thanks.

Integrating Wwise in a VS2010 project

07 March 2012 - 10:47 AM

Eventually I want to be able to integrate Wwise into a Windows 8 Metro project but first I'm attempting to integrate it into a simple console application on Windows 7. I'm following the documentation, but as soon as I add this function:

bool InitSoundEngine()
{
    //
    // Create and initialize an instance of the default memory manager. Note
    // that you can override the default memory manager with your own. Refer
    // to the SDK documentation for more information.
    //
    AkMemSettings memSettings;
    memSettings.uMaxNumPools = 20;
    if ( AK::MemoryMgr::Init( &memSettings ) != AK_Success )
    {
	    assert( ! "Could not create the memory manager." );
	    return false;
    }
}

I get this error:

Error 1 error LNK2019: unresolved external symbol "enum AKRESULT __cdecl AK::MemoryMgr::Init(struct AkMemSettings *)" (?Init@MemoryMgr@AK@@YA?AW4AKRESULT@@PAUAkMemSettings@@@Z) referenced in function "bool __cdecl InitSoundEngine(void)" (?InitSoundEngine@@YA_NXZ) c:\Users\Sam\documents\visual studio 2010\Projects\Wwise Test\Wwise Test\Wwise Test.obj Wwise Test


From experience I know it's most likely an error with the library, but I'm sure I have the correct libraries included in the project. The Wwise SDK has .lib files for VS2010 on Windows 7 64-bit, and those are the ones I'm including. It finds the libraries fine. I don't know what to do and I can't find anybody else with the same issue. I've tried this on three different computers, two running Windows 7, and one Windows 8, all three get the same error.

Any help greatly appreciated.

Using A* in an RTS game

02 February 2012 - 11:22 AM

I've implemented a working A* algorithm in an RTS game I'm making, but I have a few queries on improving it.

Firstly, to fix the jagged movement I'm going to iterate between tiles to create straight lines between tiles which can see each other. This would involve drawing a line between two tiles and using Bresenham's algorithm to determine which tiles are on the line and if any of them are impassable. Is this the best way to smooth out the A* path?

Secondly, I'm unsure how to actually implement the pathfinding into the gameplay. Currently, if a unit is given a move order, I will generate the path every frame and move towards the first cell in the path, though of course this is very costly if you're moving lots of units at once. However, if I was to only generate the path when the move order is given, any changes in the game world (such as adding new structures) would be ignored by the units and they would path through them. What is the best way to solve this?

Thirdly, if I have a bunch of units selected and I ask them to move towards a point, they will all collapse on top of each other. A way I could solve this is by using flocking AI, but I don't know how well it would integrate with A*. This video is an example of what I want to achieve.

I'm asking quite a lot, so thanks for any answers you can give!

PARTNERS