More Planets, more artificial suns

More planets & more artificial suns..

I've been fighting with the shadows for so long I just had to put it away; made more planets and a function to add more artificial suns to the game instead of the shadows.

The graphics are made with hardware instancing so that all the entities/vehicles will be drawn from the GPU (graphic card) all at once instead of being sent one by one from the application, this makes faster drawings when using hundreds of objects or even more.

I've been dabbing around with this for a couple of days because I needed to add a Matrix for the Light projections to the vertex buffer stream sent to the GPU, so that I could add more lights to the game. It took a long time because I didn't find a bug that was hiding away from me, I found it though, it was in the following lines of Shader code..

    VertexShaderOutput HardwareInstancingVertexShader(VertexShaderInput input,
float4x4 instanceTransform : TEXCOORD1, float4x4 lightMatrices : TEXCOORD5, float3 lightPosition : TEXCOORD9)
{
VertexShaderOutput output = (VertexShaderOutput)0;

// To the world we go!
instanceTransform = mul(World, transpose(instanceTransform));

// Apply the objects translation in the world
// to the input.Position that contain the
// X and Y values of the screen coordinate of the current pixel
float4 worldPosition = mul(input.Position, instanceTransform);

// Apply the camera view to it
float4 viewPosition = mul(worldPosition, View);

// And the projection frustum to become the camera screen position
output.Position = mul(viewPosition, Projection);

// And do the same for the light screen pixels
output.LightPosition = lightPosition;
output.Position2DInLight = mul(worldPosition, lightMatrices);
        
        ............... AND SO ON

One single little line that was missing one single little command, I didn't focus enough on the actual problem so I didn't see it until a couple of days later!

The problem was that a Matrix in the Application (CPU) are stored in row-major ordering, so the order in memory there goes x[0][0][0][0], x[0][0][0][1] and so forth, but In HLSL a matrix defaults to column-major ordering so the order is instead x[0][0][0][0], x[1][0][0][0].

The command 'transpose' fixes this so that the CPU based Matrix will be read like it should be read in the HLSL too.

I was missing the transpose command which made my light Matrices what I then thought 'empty' and therefore made me search for the problem elsewhere in my code. Because of me focusing on the wrong part of code it took me until today to find it.. but finally.

The last line should have been:

    output.Position2DInLight = mul(worldPosition, transpose(lightMatrices));

And for more detailed information about the problem I've had; here is the call for help that I wrote on the Monogame community: http://community.monogame.net/t/hardware-instance-adding-an-extra-matrix-to-the-custom-vertexdeclaration/10078



Here's a new animated gif image, showing the two planets, artificial suns and the entities/vehicles that I've made functionality for today.



Now I'm going to take a short break, breathing for awhile.
I'll be back soon with more adventures on this.

Kommentarer