Port of my city renderer

You probably shouldn't implement it now even if you finish the updater! I still have to make the CityRenderer request housing data from a dummy server.

The CityRenderer should be fed an array of the following data type:

class LotTileEntry
{
public int lotid;
public short x;
public short y;
public byte flags; //bit 0 = online, bit 1 = spotlight, bit 2 = locked, other bits free for whatever use
}

This should be enough for the CityRenderer to draw all lots fine. When it needs more info, it can request the lot metadata (name etc) using the lotid. The data type for lot metadata will probably be a ton more complicated and implementation reliant.
 
houses.png

housesr.png

Houses are now working, obviously the city data is currently coming from a hard coded LotTileEntry array.

I'll post this update when I've set up my simple shader for 2d triangles. (to use for tile hightlight + spotlights)
 
Interesting progress, will use same city rendering that tso or new one??? Becuase the old was lack of details...
 
It's a custom city rendering engine. It will be in the same style as TSO, however I can add support for some really cool things like real time of day lighting with shadows (sunsets etc) that wouldn't be possible with the original to add some more character to it.
 
I've got a weird bug where my new shader for the 2D filled polys won't draw anything at all... I don't know if I'm missing anything, as I'm using the except same process as I do for the 3d mesh (Set technique, set parameters, commit changes, begin shader, begin technique, draw primitives, end technique, end shader)
 
RHY3756547 said:
I've got a weird bug where my new shader for the 2D filled polys won't draw anything at all... I don't know if I'm missing anything, as I'm using the except same process as I do for the 3d mesh (Set technique, set parameters, commit changes, begin shader, begin technique, draw primitives, end technique, end shader)

Rhys, try putting your 3D drawing call(s) before your 2D drawing calls in the rendering loop. I did this with Darren's city renderer, and it fixed an issue where the 2D GUI wasn't being drawn (it was hidden behind the 3D terrain).

Edit: Xezno, please stop spamming topics with irrelevant comments. This is the second time I've had to delete comments from you and Rhys now, the first time being when you followed up on Rhys' comment on my spelling in the Bugfixe(s) thread. Granted, his comment wasn't on topic, but there was no need to follow it up!
As for this thread, wtf does Ghost have to do with anything? If that was his house, there's no need to comment on it. Even if that had been a relevant comment, it would still be fucking stupid, because Ghost was/is a scamming asshole who should be forgotten and not mentioned.
 
I am drawing it the 2D afterwards, and I'm even setting DepthBufferEnable to false before drawing! It doesn't even draw when I comment out the 3D code... I've checked over the data format, put a breakpoint after it generates the vertex array from the ArrayList and it has the correct data, and checked over the shaders. They should all be producing results, especially the 1024*768 triangle I'm trying to draw over the top right hand side of the screen for testing.

Shader code:
Code:
float4x4 Projection;

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;
    output.Position = mul(input.Position, Projection);
    output.Color = input.Color;

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return input.Color;
}

technique DrawStuff
{
    pass Pass1
    {
        VertexShader = compile vs_1_1 VertexShaderFunction();
        PixelShader = compile ps_1_1 PixelShaderFunction();
    }
}

note: returning float4(1, 1, 1, 1) as the colour still displays nothing.

Test Poly:
Code:
            m_2DVerts.Add(new VertexPositionColor(new Vector3(0, 0, 1), new Color(1, 1, 1, 1)));
            m_2DVerts.Add(new VertexPositionColor(new Vector3(1024, 0, 1), new Color(1, 1, 1, 1)));
            m_2DVerts.Add(new VertexPositionColor(new Vector3(1024, 768, 1), new Color(1, 1, 1, 1)));

            Draw2DPoly();

Draw2DPoly:
Code:
        public void Draw2DPoly()
        {
            m_GraphicsDevice.RenderState.DepthBufferEnable = false;

            VertexPositionColor[] Vert2D = new VertexPositionColor[m_2DVerts.Count];
            m_2DVerts.CopyTo(Vert2D);
            int size = VertexPositionColor.SizeInBytes * Vert2D.Length;

            Matrix ProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, m_GraphicsDevice.Viewport.Width, m_GraphicsDevice.Viewport.Height, 0, 0.1f, 100);

            Shader2D.CurrentTechnique = Shader2D.Techniques[0];
            Shader2D.Parameters["Projection"].SetValue(ProjectionMatrix);
            Shader2D.CommitChanges();

            Shader2D.Begin();
            Shader2D.CurrentTechnique.Passes[0].Begin();

            m_GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, Vert2D, 0, Vert2D.Length/3);

            Shader2D.CurrentTechnique.Passes[0].End();
            Shader2D.End();

            m_GraphicsDevice.RenderState.DepthBufferEnable = true;
        }
 
Afr0 said:
RHY3756547 said:
I've got a weird bug where my new shader for the 2D filled polys won't draw anything at all... I don't know if I'm missing anything, as I'm using the except same process as I do for the 3d mesh (Set technique, set parameters, commit changes, begin shader, begin technique, draw primitives, end technique, end shader)

Rhys, try putting your 3D drawing call(s) before your 2D drawing calls in the rendering loop. I did this with Darren's city renderer, and it fixed an issue where the 2D GUI wasn't being drawn (it was hidden behind the 3D terrain).

Edit: Xezno, please stop spamming topics with irrelevant comments. This is the second time I've had to delete comments from you and Rhys now, the first time being when you followed up on Rhys' comment on my spelling in the Bugfixe(s) thread. Granted, his comment wasn't on topic, but there was no need to follow it up!
As for this thread, wtf does Ghost have to do with anything? If that was his house, there's no need to comment on it. Even if that had been a relevant comment, it would still be fucking stupid, because Ghost was/is a scamming asshole who should be forgotten and not mentioned.
Calm down, bro. Calm down.
RHY3756547 said:
I am drawing it afterwards, and I'm even setting DepthBufferEnable to false before drawing! It doesn't even draw when I comment out the 3D code... I've checked over the data format, put a breakpoint after it generates the vertex array from the ArrayList and it has the correct data, and checked over the shaders. They should all be producing results, especially the 1024*768 triangle I'm trying to draw over the top right hand side of the screen for testing.

Shader code:
Code:
float4x4 Projection;

struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float4 Color : COLOR0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output = (VertexShaderOutput)0;
    output.Position = mul(input.Position, Projection);
    output.Color = input.Color;

    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    return input.Color;
}

technique DrawStuff
{
    pass Pass1
    {
        VertexShader = compile vs_1_1 VertexShaderFunction();
        PixelShader = compile ps_1_1 PixelShaderFunction();
    }
}

note: returning float4(1, 1, 1, 1) as the colour still displays nothing.

Test Poly:
Code:
            m_2DVerts.Add(new VertexPositionColor(new Vector3(0, 0, 1), new Color(1, 1, 1, 1)));
            m_2DVerts.Add(new VertexPositionColor(new Vector3(1024, 0, 1), new Color(1, 1, 1, 1)));
            m_2DVerts.Add(new VertexPositionColor(new Vector3(1024, 768, 1), new Color(1, 1, 1, 1)));

            Draw2DPoly();

Draw2DPoly:
Code:
        public void Draw2DPoly()
        {
            m_GraphicsDevice.RenderState.DepthBufferEnable = false;

            VertexPositionColor[] Vert2D = new VertexPositionColor[m_2DVerts.Count];
            m_2DVerts.CopyTo(Vert2D);
            int size = VertexPositionColor.SizeInBytes * Vert2D.Length;

            Matrix ProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, m_GraphicsDevice.Viewport.Width, m_GraphicsDevice.Viewport.Height, 0, 0.1f, 100);

            Shader2D.CurrentTechnique = Shader2D.Techniques[0];
            Shader2D.Parameters["Projection"].SetValue(ProjectionMatrix);
            Shader2D.CommitChanges();

            Shader2D.Begin();
            Shader2D.CurrentTechnique.Passes[0].Begin();

            m_GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleList, Vert2D, 0, Vert2D.Length/3);

            Shader2D.CurrentTechnique.Passes[0].End();
            Shader2D.End();

            m_GraphicsDevice.RenderState.DepthBufferEnable = true;
        }
Why not return float4(0,1,0,1); then? It should work...
 
That would return green... Currently I'm trying to return white, but it's not drawing anything. Returning green wouldn't change anything.
 
Your not setting the vertex declaration? GD.VertexDeclaration = new VertexDeclaration(GD, VertexPositionColor.VertexElements)
 
I don't think DrawUserPrimitives requires that, as you feed it the type as well as the data. I just uncommented that part there and I still get the same result.

I also get the same result when generating VertexBuffers instead of using DrawUserPrimitives.
 
I think in XNA 3.1 you have to set VertexDeclaration but not in XNA 4.0.

Your projection looks wrong to me, In XNA the units go from -1,-1 (bottom left) to 1, 1 (top right).
 
The CreateOrthographicOffCenter Matrix Method states the parameters as:

float left,
float right,
float bottom,
float top,

I want the left to be 0, the right to be the width, the bottom to be the the height, and the top to be 0 for a 1:1 map with position to pixel. Shouldn't this alter the co-ordinate system to be right-down positive? I tried flipping top and bottom in case it was getting confused, but still nothing is drawing.
 
Oh sorry, this is for 2D rendering. Try something like this;

View = new Matrix(1.0f, 0.0f, 0.0f, 0.0f,
0.0f, -1.0f, 0.0f, 0.0f,
0.0f, 0.0f, -1.0f, 0.0f,
0.0f, 0.0f, 0.0f, 1.0f);

Projection = Matrix.CreateOrthographicOffCenter(0, width, -height, 0, 0, 1);

And set your shader variable to View * Projection.

On another note, have you tried disabling culling?
 
Wow, that worked great! Still not sure why it didn't initially work, but here's a screenshot with spotlights displaying:

spot.png
 
RHY3756547 said:
That would return green... Currently I'm trying to return white, but it's not drawing anything. Returning green wouldn't change anything.
Ah, ok then lol
I thought it would be OK for debugging and all that lol ;)
 
City Renderer with spotlights, time of day cycle, flashing online lots:

CityRenderer%202014-01-18%2019-29-26-82.gif


https://dl.dropboxusercontent.com/u/122 ... erSpot.zip

This is the base functionality done, though it would be cool to throw a shadowmap in there for sun and moon shadows.

Note: Minimizing and restoring still crashes! I don't know if it's nuking my Texture2D resources on reset as well, but if it is then I have no idea how to keep a non-VRAM cache of them.
 
Not sure if you are aware of this, but the program still reads mouse input when it is not the active window and responds to it.
 
zephyr2 said:
Not sure if you are aware of this, but the program still reads mouse input when it is not the active window and responds to it.

I noticed same on two days ago but I didn't make alert of that yet because it wasn't combined to Project Doll House yet.
 
Back
Top