• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Plerion

Problem rendering Mesh

1 post in this topic

Hey everyone

Im currently having some problems rendering my meshes. Im coming from D3D9 and this is my first project with D3D11. I have my custom mesh class with the meshgeometry and vertex elements. Current i have this simple test:
[source lang="csharp"]
Rendering.Geometry.MeshGeometry<uint> geom = Rendering.Geometry.MeshGeometry<uint>.Create(device);
var elem = Rendering.Geometry.VertexElement.CreatePosition3D(device);
float[] vertices = new float[9]
{
0, 0, -3,
0, 0, 3,
0, 5, 0,
};

elem.DataStream.WriteRange(vertices);
geom.AddVertexElement(elem);

var triangle = geom.Triangles.AddFace();
triangle.P1 = 0;
triangle.P2 = 1;
triangle.P3 = 2;

geom.LoadBuffers();
Rendering.Scene.Mesh mesh = new Rendering.Scene.Mesh();
mesh.AttachGeometry(geom);

device.Scene.SceneRoot.AttachChild(mesh);
Rendering.Effects.Common.BasicEffect basicEffect = new Rendering.Effects.Common.BasicEffect(device);
basicEffect.WorldMatrix = SlimDX.Matrix.Identity;
basicEffect.ViewMatrix = SlimDX.Matrix.LookAtLH(new SlimDX.Vector3(50, 5, 0), new SlimDX.Vector3(0, 5, 0), new SlimDX.Vector3(0, 1, 0));
basicEffect.ProjectionMatrix = SlimDX.Matrix.PerspectiveFovLH((45.0f * (float)Math.PI) / 180.0f, ((float)f.ClientSize.Width / f.ClientSize.Height), 0.1f, 1000.0f);
[/source]

The basic effect looks like that:
Vertexshader:
[source lang="cpp"]
cbuffer MatrixBuffer
{
matrix worldMatrix;
matrix viewMatrix;
matrix projectionMatrix;
};

struct VertexInputType
{
float4 position : POSITION;
};

struct PixelInputType
{
float4 position : SV_POSITION;
};

PixelInputType BasicEffectVS(VertexInputType input)
{
PixelInputType output = (PixelInputType)0;

input.position.w = 1.0f;
output.position = mul(input.position, worldMatrix);
output.position = mul(output.position, viewMatrix);
output.position = mul(output.position, projectionMatrix);

return output;
}
[/source]

Pixelshader:
[source lang="cpp"]
struct PixelInputType
{
float4 position : SV_POSITION;
};
float4 BasicEffectPS(PixelInputType input) : SV_Target
{
return float4(1, 1, 1, 1);
}[/source]
Rendering is done the following way:
[source lang="csharp"] var ctx = mDevice.ImmediateContext;
ctx.InputAssembler.InputLayout = inpLayout;

shader.PerformRender((dev) =>
{
ctx.InputAssembler.SetVertexBuffers(0, mVBinding);
ctx.InputAssembler.SetIndexBuffer(mIndexBuffer, SlimDX.DXGI.Format.R32_UInt, 0);
ctx.InputAssembler.PrimitiveTopology = PrimitiveTopology.TriangleList;
ctx.DrawIndexed(Triangles.getTriangleCount() * 3, 0, 0);
}
);
[/source]
Now the problem is that nothing is rendered on the screen. Im using PIX to debug my shaders and draw calls.

The results:
As Pre-VS data i get the values from my triangle:
(Vertex, Index, Position)
0, 0, (0.0, 0.0, -3.0, 1.0)
1, 1, (0.0, 0.0, 3.0, 1.0)
2, 2, (0.0, 5.0, 0.0, 1.0)

But then at PostVS i have the following:
0, 0, (5.274, 0.0, -149.0, 0)
1, 1, (-5.274, 0.0, 151.0, 0)
2, 2, (0.0, 12.071, -24.0, 0)

While the first two position values make sense if i translate them on the screen the depth (id say z is depth) is weird. From my vertices depth should be equal for all the 3, or am i wrong? Also the images are not showing what i expect when i have a triangle aligned on the z-axis with a camera looking from the x-axis onto it:
[img]http://imagr.eu/up/50575518a8b682_PIX.jpg[/img]

Hopefully someone can help me and point me out what im doing wrong!

Thanks in advance
Plerion Edited by Plerion
0

Share this post


Link to post
Share on other sites
Here are some updates:
1. I forgot to transpose the matrices, i changed that!
2. I realized in PIX that my matrices are not the same as the values i set for the shader! They are completely different (1 instead of -1, -0.01 instead of 5, ...) but i have no clue why. Everything i was able to debug in the application has the correct matrix values until it comes to mapping and writing the subresource! For debugging purposes i added another variable of type uint to my VertexShaders MatrixBuffer and set its value to 200. The matrices have invalid values, the additional parameter has its correct value 200. If i add a matrix that was created "by hand" with all the values it also gets transmitted to the vertex shader without problems. Only if there is any Matrix.XXXX operation involved afterwards the matrix in the shader is completely messed up.

Here is the code i use to set a variable:
[source lang="csharp"]public void SetValue<T>(string name, T value)
{
if (mVariables.ContainsKey(name) == false)
#if DEBUG
throw new ArgumentException("Variable '" + name + "' not present in any constant buffer!");
#else
return;
#endif

var desc = mVariables[name];
var wrapper = mDevice.ImmediateContext.VertexShader;
var oldShader = wrapper.Get();
wrapper.Set(mShader);
var constBuffer = mConstantBuffers[desc.cBufferIndex];

GCHandle handle = GCHandle.Alloc(value, GCHandleType.Pinned);
var pinPtr = handle.AddrOfPinnedObject();

byte[] tmpBuffer = new byte[Marshal.SizeOf(typeof(T))];
Marshal.Copy(pinPtr, tmpBuffer, 0, tmpBuffer.Length);
handle.Free();

var dataBox = mDevice.ImmediateContext.MapSubresource(constBuffer.buffer, MapMode.WriteDiscard, MapFlags.None);

// constBuffer.dataStream is a stream holding all the data in memory so you can read from it
// and you can overwrite its contents without losing the old content (not like in MapSubresource with
// MapMode.WriteDiscard)
var existingStream = constBuffer.dataStream;
existingStream.Position = desc.byteOffset;

existingStream.Write(tmpBuffer, 0, desc.byteSize);
existingStream.Position = 0;

// Write the complete content of the constant buffer to the databox of the subresource
dataBox.Data.WriteRange(existingStream.DataPointer, existingStream.Length);

mDevice.ImmediateContext.UnmapSubresource(constBuffer.buffer, 0);

wrapper.SetConstantBuffer(constBuffer.buffer, desc.cBufferIndex);
wrapper.Set(oldShader);
}[/source]

So my problem changed from strange calculations in the shader to the fact that my parameters are not correctly ported to the shader!
0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0