• 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
Yura

How to fill triangle with different colors on front and back sides?

12 posts in this topic

I have primitive triangles (triangle list) and have back culling off
[source lang="csharp"] d3dDevice.SetRenderState(RenderState.CullMode, Cull.None);[/source]

And now I want to fill this triangle with colour in such way, so front side had one colour and when I rotate it to back side, it had another colour.
Is it possible to do that?
Each point of triangle can have it's colour
0

Share this post


Link to post
Share on other sites
[quote name='unbird' timestamp='1355943130' post='5012544']
For shader model 3 there's also the [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb509647(v=vs.85).aspx#PS"]VFACE semantic[/url], automatically available in the pixel shader (just define a [font=courier, courier new, serif] float face : VFACE[/font] parameter in your shader function).

Or are you using the fixed function pipeline ?

@Gavin: Hmmm, does this really work ? E.g. normals don't need to coincide with the face normals.
[/quote]

I do not use any shaders, so can you explain in details, what and where shoud I fix in my code

[source lang="csharp"][StructLayout(LayoutKind.Sequential)]
struct Vertex
{
public Vector4 Position;
public Color Color;
//public Vector3 Normal;
}


private void InitGeometryTriangles()
{
FormList();

List<Vertex> points = new List<Vertex>();
for (int i = 0; i < elements.Length; i++)
{
List<Node> list = elements[i].Nodes;

int listCount = list.Count;
for (int j = 0; j < listCount; j++)
{

points.Add(new Vertex() { Color = SharpDX.Color.Gray, Position = new Vector4(list[j].X, list[j].Y, list[j].Z, 1.0f) });

if (j == 2)
{
points.Add(new Vertex() { Color = SharpDX.Color.Gray, Position = new Vector4(list[j].X, list[j].Y, list[j].Z, 1.0f) });
}
}

points.Add(new Vertex() { Color = SharpDX.Color.Gray, Position = new Vector4(list[0].X, list[0].Y, list[0].Z, 1.0f) });
}

totalPointsCount = points.Count;
vertices = new VertexBuffer(d3dDevice, Marshal.SizeOf(typeof(Vertex)) * totalPointsCount, SharpDX.Direct3D9.Usage.WriteOnly,
myVertexFormat, Pool.Managed);

vertices.Lock(0, 0, LockFlags.None).WriteRange(points.ToArray());
vertices.Unlock();

var vertexElems = new[] {
new VertexElement(0, 0, DeclarationType.Float4, DeclarationMethod.Default, DeclarationUsage.Position, 0),
new VertexElement(0, 16, DeclarationType.Color, DeclarationMethod.Default, DeclarationUsage.Color, 0),
VertexElement.VertexDeclarationEnd
};
vertexDecl = new VertexDeclaration(d3dDevice, vertexElems);
}

private void RedrawPrimitives()
{
d3dDevice.VertexFormat = myVertexFormat;
d3dDevice.VertexDeclaration = vertexDecl;

d3dDevice.Clear(ClearFlags.Target, SharpDX.Color.White, 1.0f, 0);
d3dDevice.BeginScene();

d3dDevice.SetStreamSource(0, vertices, 0, Marshal.SizeOf(typeof(Vertex)));
d3dDevice.DrawPrimitives(PrimitiveType.TriangleList, 0, totalPointsCount / 3);

d3dDevice.EndScene();
d3dDevice.Present();
}[/source]

Thanks for reply!
0

Share this post


Link to post
Share on other sites
If you're not using shaders then neither of our suggestions are going to be of any use. Instead you will have to provide two triangles, one for each side, and turn back-face culling on, so that they don't interfere with each other when rendering.
2

Share this post


Link to post
Share on other sites
[quote name='Gavin Williams' timestamp='1356010809' post='5012789']
If you're not using shaders then neither of our suggestions are going to be of any use. Instead you will have to provide two triangles, one for each side, and turn back-face culling on, so that they don't interfere with each other when rendering.
[/quote]

Can you post here some example of shader, similar to my problem
and provide guidance on the application of this shader in my code?
0

Share this post


Link to post
Share on other sites
I don't think doubling each point is a good idea because my polygon is quite big. In better way vertex buffer contain 50 000 points, in worst - 10 000 000 and more (sometimes it just can't be drawn). Now I'm trying to reduce number of vertices by using Indexes, unfortinutly without success. There is other topic with more information about my project http://www.gamedev.net/topic/635625-fastest-way-to-draw-rectangles-with-slimdx-sharpdx/
0

Share this post


Link to post
Share on other sites
That is quite big. Let us look at the numbers:

Your current vertex size is 20 (4 floats, 4 bytes each for position, 4 bytes for the color)
10 million vertices.
This alone gives you approx 200 Mb of vertex data.

With a naive setup (add quads/tris as they come) this number will be scaled by factor of 6 or 3 respectively, so you've probably already blown the GPU memory limit of an average consumer card (or the limit the driver gives you). As you say: One draw call impossible. True, duplicating vertices further (or adding additional vertex data) is undesirable.

Sure you can now massage the API to make it work , but with these numbers I'm inclined to suggest an non-realtime approach (you could still use D3D for rendering though). Have you tried a GDI-setup (with low render quality) ?

Anyway, here some suggestions for D3D optimizations.
  • No need to use a Vector4 for position if your w is always 1. The D3D runtime will do that automatically for Vector3 (D3DDECLTYPE_FLOAT3 )
  • Reduce precision of your vertex elements. Half-floats/shorts for positions ? Scalar for the color ? With shaders you can even do sophisticated packing (custom format).
  • Why rely on big memory or insist on few draw calls ? Split your mesh into parts the API/GPU can cope with one at a time. You can still get good performance with that. It's sort of streaming.
  • Indexing, as Dynamo_Maestro suggested. To get familiar with start with something real simple (triangle, quad, two adjacent quads, grid, a sphere...).
  • Shaders: As mentioned, greater flexibility.
  • Instancing. Is a way to render "the same" geometry multiple times with different position/color/whatever. In your case this would be the quads for the geometry and the position and color for the instances. Consider this advanced D3D API, it needs SM 3.
But always know: no API-trick (or even using a "faster" API like D3D) is a silver bullet. You can setup a complex system reducing e.g. payload and the thing still renders slower.
Do some research and chose wisely which path you wanna go because I think you have a challenging problem.
1

Share this post


Link to post
Share on other sites

That is quite big. Let us look at the numbers:

Your current vertex size is 20 (4 floats, 4 bytes each for position, 4 bytes for the color)
10 million vertices.
This alone gives you approx 200 Mb of vertex data.

With a naive setup (add quads/tris as they come) this number will be scaled by factor of 6 or 3 respectively, so you've probably already blown the GPU memory limit of an average consumer card (or the limit the driver gives you). As you say: One draw call impossible. True, duplicating vertices further (or adding additional vertex data) is undesirable.

Sure you can now massage the API to make it work , but with these numbers I'm inclined to suggest an non-realtime approach (you could still use D3D for rendering though). Have you tried a GDI-setup (with low render quality) ?

Anyway, here some suggestions for D3D optimizations.

  • No need to use a Vector4 for position if your w is always 1. The D3D runtime will do that automatically for Vector3 (D3DDECLTYPE_FLOAT3 )
  • Reduce precision of your vertex elements. Half-floats/shorts for positions ? Scalar for the color ? With shaders you can even do sophisticated packing (custom format).
  • Why rely on big memory or insist on few draw calls ? Split your mesh into parts the API/GPU can cope with one at a time. You can still get good performance with that. It's sort of streaming.
  • Indexing, as Dynamo_Maestro suggested. To get familiar with start with something real simple (triangle, quad, two adjacent quads, grid, a sphere...).
  • Shaders: As mentioned, greater flexibility.
  • Instancing. Is a way to render "the same" geometry multiple times with different position/color/whatever. In your case this would be the quads for the geometry and the position and color for the instances. Consider this advanced D3D API, it needs SM 3.
But always know: no API-trick (or even using a "faster" API like D3D) is a silver bullet. You can setup a complex system reducing e.g. payload and the thing still renders slower.
Do some research and chose wisely which path you wanna go because I think you have a challenging problem.

 

Thanks for your interest to my problem! 
So, about your suggestions, I've already made changes in Vectors, now they are Vector3. It works fine. Now I'm trying to implement Indexes. It seems to be easy, with triangle list it realy is, but I can't force it to draw line list. But it is my bad, i'll do it soon.
I'm not very good in DirectX programming, so I have no idea what is SM 3, but idea with multiple geometry is very seductive. I'll try to figure out with this.
About shaders,  I read about them but I didn't find how to solve any of my problems with their help... They are too difficult for me)
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