Sign in to follow this  

DX11 3D engine core layout questions.

Recommended Posts

I've near finished a project in C# and started building a C++ engine for my next project.
I'm using DX11 but at DX9 feature level. I aim to build the engine around tessellation and displacement maps (I know its better off in DX11 feature level but my machine is only just behind the line of DX11 machines, so I can't use let alone debug the features.) regardless some (not heavy hitting) tesselation is my aim for the LOD effect.

ANYWAY! I have a few questions on the base of my engine, (I've got it functional so all of this is for the sake of expanding it)

1.) Model class layout.
My current layout is along the lines of: (pseudo-ish code)
Model //what is publicly used
ModelPart[] //contains model data per mesh (mesh, bones, material)
Mesh //contains mesh parts in case of large mesh
MeshPart[] //contains buffers and indices of bones relevant to the mesh to be passed to the shader

Bone[] //contains current matrix and pointers to parent bones (for getting their matrices for full transform)

Material //contains pointers to textures and an array of parameters relevant to its intended shader
What else should I be taking into account? What may I have overlooked or got wrong?

2.) I'd like to write my own converter to change models to my own format. Does anyone know what input formats are worth taking into account or if there is anything I should be aware of while doing this?

3.) I've got a fair plan of how I'm going to lay out texture channels for use (Specular Alpha acting as specular intensity, Normal map spherical normals in XY, Z Displacement, A Shader Parameter (E.G. glow)) is it worth making a program to merge textures into these formats? or should I just do it as they load?

Any and all help is much appreciated,
Thanks in advanced,

Share this post

Link to post
Share on other sites
I have to warn you: none of those questions involve API so odds are you might be overestimating the importance of using an API instead of another.
[quote name='bombshell93' timestamp='1333495939' post='4928040']
1. What else should I be taking into account? What may I have overlooked or got wrong?[/quote]This is only a small, albeit important part of engine design. Please notice how the whole material thing is extremely inflexible - I'm not very sure about what the [font=courier new,courier,monospace]parameter[][/font] array is supposed to be but I'd be somewhat careful about planning to have specific [font=courier new,courier,monospace]Specular[/font] and [font=courier new,courier,monospace]Normal[/font](map?) resources. Compare this to the high flexibility of D3D11 you aim for. I recall about a discussion on shading systems where an high-profile user suggested to basically drop everything in favor of a mere parameter array - which you correctly have there.
Rather than having a [font=courier new,courier,monospace]ParentBone [/font]pointer, I'd just store everything in a tree. It looks to me that identifying children is more important than identifying parents.
[quote name='bombshell93' timestamp='1333495939' post='4928040']
2.) I'd like to write my own converter to change models to my own format. Does anyone know what input formats are worth taking into account or if there is anything I should be aware of while doing this?[/quote]To my own surprise, OBJ provides incredible amounts of mileage for hobby projects. For 'level' assets I like Quake3 .map. I will support FBX decently a day. So far collada has not bought me much.
[quote name='bombshell93' timestamp='1333495939' post='4928040']3.) I've got a fair plan of how I'm going to lay out texture channels for use (Specular Alpha acting as specular intensity, Normal map spherical normals in XY, Z Displacement, A Shader Parameter (E.G. glow)) is it worth making a program to merge textures into these formats? or should I just do it as they load?[/quote]I do it at runtime - most of the time, it's just about setting an API enumerator. This is not always the case. DDS texture format provides everything explicitly. It is my understanding Unreal Engine has texture packages. I have no idea what they store there (besides the pixels I mean), but I think it's reasonable they go through some mangling.

Share this post

Link to post
Share on other sites
1:) you will be using instances of a object that will have a mesh, your system looks like it loads the same mesh over and over. (i dont know actualy but thats what i can see)

2:) then write a direct plugin to maya/3dmax, you wont get better results.

3:) it might be good writing a program for that. in my eyes you could write a program that compress all your textures and makes it to a atlas.
then you can put it to a constat register!

Share this post

Link to post
Share on other sites
Another idea is instead of making a straight converter is to load the modeling programs model than add any additons to it that you may want in your own editor. For instance Milkshape3d doesn't support normal or specular maps so you can make an editor to load and add them to your own model format. But like Tordin said writing your own exporter from the modeling program would be best. That way you dont have to use multiple editors.

Share this post

Link to post
Share on other sites
I find the Jason Gregory’s book (Game Engine Architecture) to be a great survey of graphic engine technologies.

I don’t know the time frame that you have, your skills, and the level of technology that you want to achieve. However, I can recommend that you research about data oriented design and component oriented design. For me the core of the engine start there, then you can plan the assets and stuff.

Good luck!!

Share this post

Link to post
Share on other sites
What i did in my engine is that mesh data is seperated from bone/skeleton data. That way i can share skeleton across different models. Each mesh can contain an set of vertex/index buffers and are broken down based on materials. Each vertex buffer can hold position/uv/color/boneIndexes etc.

Share this post

Link to post
Share on other sites
I've sorted my layout out now.
Model contains a pointer to an animation library (so its reusable) the set of current and possibly next transforms (next frame transforms in case some physics calculation is to be done on the bones or something along those lines)
The Model is then split per material into the model parts, which hold a mesh and of course the material.
The Mesh is then split into mesh parts for optimal draw calls with high poly models.

I've decided I'll have a debug system and a release system.
Debug system check if the model source (.obj .fbs etc. etc.) is newer than the converted file, if so convert it.
Release system skips the check and only reads from the converted
I'm using Assimp to help handle this, but I actually have another topic about assimp explaining how I'm having trouble with skinned meshes, bones and animations.

The third I'm still not sure, I'll probably make a material editor and make it part of the process.

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  

  • Announcements

  • Forum Statistics

    • Total Topics
    • Total Posts
  • Similar Content

    • By 51mon
      I want to change the sampling behaviour to SampleLevel(coord, ddx(coord.y).xx, ddy(coord.y).yy). I was just wondering if it's possible without explicit shader code, e.g. with some flags or so?
    • By GalacticCrew
      I want to improve the performance of my game (engine) and some of your helped me to make a GPU Profiler. After creating the GPU Profiler, I started to measure the time my GPU needs per frame. I refined my GPU time measurements to find my bottleneck.
      Searching the bottleneck
      Rendering a small scene in an Idle state takes around 15.38 ms per frame. 13.54 ms (88.04%) are spent while rendering the scene, 1.57 ms (10.22%) are spent during the SwapChain.Present call (no VSync!) and the rest is spent on other tasks like rendering the UI. I further investigated the scene rendering, since it takes über 88% of my GPU frame rendering time.
      When rendering my scene, most of the time (80.97%) is spent rendering my models. The rest is spent to render the background/skybox, updating animation data, updating pixel shader constant buffer, etc. It wasn't really suprising that most of the time is spent for my models, so I further refined my measurements to find the actual bottleneck.
      In my example scene, I have five animated NPCs. When rendering these NPCs, most actions are almost for free. Setting the proper shaders in the input layout (0.11%), updating vertex shader constant buffers (0.32%), setting textures (0.24%) and setting vertex and index buffers (0.28%). However, the rest of the GPU time (99.05% !!) is spent in two function calls: DrawIndexed and DrawIndexedInstance.
      I searched this forum and the web for other articles and threads about these functions, but I haven't found a lot of useful information. I use SharpDX and .NET Framework 4.5 to develop my game (engine). The developer of SharpDX said, that "The method DrawIndexed in SharpDX is a direct call to DirectX" (Source). DirectX 11 is widely used and SharpDX is "only" a wrapper for DirectX functions, I assume the problem is in my code.
      How I render my scene
      When rendering my scene, I render one model after another. Each model has one or more parts and one or more positions. For example, a human model has parts like head, hands, legs, torso, etc. and may be placed in different locations (on the couch, on a street, ...). For static elements like furniture, houses, etc. I use instancing, because the positions never change at run-time. Dynamic models like humans and monster don't use instancing, because positions change over time.
      When rendering a model, I use this work-flow:
      Set vertex and pixel shaders, if they need to be updated (e.g. PBR shaders, simple shader, depth info shaders, ...) Set animation data as constant buffer in the vertex shader, if the model is animated Set generic vertex shader constant buffer (world matrix, etc.) Render all parts of the model. For each part: Set diffuse, normal, specular and emissive texture shader views Set vertex buffer Set index buffer Call DrawIndexedInstanced for instanced models and DrawIndexed models What's the problem
      After my GPU profiling, I know that over 99% of the rendering time for a single model is spent in the DrawIndexedInstanced and DrawIndexed function calls. But why do they take so long? Do I have to try to optimize my vertex or pixel shaders? I do not use other types of shaders at the moment. "Le Comte du Merde-fou" suggested in this post to merge regions of vertices to larger vertex buffers to reduce the number of Draw calls. While this makes sense to me, it does not explain why rendering my five (!) animated models takes that much GPU time. To make sure I don't analyse something I wrong, I made sure to not use the D3D11_CREATE_DEVICE_DEBUG flag and to run as Release version in Visual Studio as suggested by Hodgman in this forum thread.
      My engine does its job. Multi-texturing, animation, soft shadowing, instancing, etc. are all implemented, but I need to reduce the GPU load for performance reasons. Each frame takes less than 3ms CPU time by the way. So the problem is on the GPU side, I believe.
    • By noodleBowl
      I was wondering if someone could explain this to me
      I'm working on using the windows WIC apis to load in textures for DirectX 11. I see that sometimes the WIC Pixel Formats do not directly match a DXGI Format that is used in DirectX. I see that in cases like this the original WIC Pixel Format is converted into a WIC Pixel Format that does directly match a DXGI Format. And doing this conversion is easy, but I do not understand the reason behind 2 of the WIC Pixel Formats that are converted based on Microsoft's guide
      I was wondering if someone could tell me why Microsoft's guide on this topic says that GUID_WICPixelFormat40bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA and why GUID_WICPixelFormat80bppCMYKAlpha should be converted into GUID_WICPixelFormat64bppRGBA
      In one case I would think that: 
      GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat32bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA, because the black channel (k) values would get readded / "swallowed" into into the CMY channels
      In the second case I would think that:
      GUID_WICPixelFormat40bppCMYKAlpha would convert to GUID_WICPixelFormat64bppRGBA and that GUID_WICPixelFormat80bppCMYKAlpha would convert to GUID_WICPixelFormat128bppRGBA, because the black channel (k) bits would get redistributed amongst the remaining 4 channels (CYMA) and those "new bits" added to those channels would fit in the GUID_WICPixelFormat64bppRGBA and GUID_WICPixelFormat128bppRGBA formats. But also seeing as there is no GUID_WICPixelFormat128bppRGBA format this case is kind of null and void
      I basically do not understand why Microsoft says GUID_WICPixelFormat40bppCMYKAlpha and GUID_WICPixelFormat80bppCMYKAlpha should convert to GUID_WICPixelFormat64bppRGBA in the end
    • By DejayHextrix
      Hi, New here. 
      I need some help. My fiance and I like to play this mobile game online that goes by real time. Her and I are always working but when we have free time we like to play this game. We don't always got time throughout the day to Queue Buildings, troops, Upgrades....etc.... 
      I was told to look into DLL Injection and OpenGL/DirectX Hooking. Is this true? Is this what I need to learn? 
      How do I read the Android files, or modify the files, or get the in-game tags/variables for the game I want? 
      Any assistance on this would be most appreciated. I been everywhere and seems no one knows or is to lazy to help me out. It would be nice to have assistance for once. I don't know what I need to learn. 
      So links of topics I need to learn within the comment section would be SOOOOO.....Helpful. Anything to just get me started. 
      Dejay Hextrix 
    • By GalacticCrew
      In some situations, my game starts to "lag" on older computers. I wanted to search for bottlenecks and optimize my game by searching for flaws in the shaders and in the layer between CPU and GPU. My first step was to measure the time my render function needs to solve its tasks. Every second I wrote the accumulated times of each task into my console window. Each second it takes around
      170ms to call render functions for all models (including settings shader resources, updating constant buffers, drawing all indexed and non-indexed vertices, etc.) 40ms to render the UI 790ms to call SwapChain.Present <1ms to do the rest (updating structures, etc.) In my Swap Chain description I set a frame rate of 60 Hz, if it's supported by the computer. It made sense for me that the Present function waits some time until it starts the next frame. However, I wanted to check, if this might be a problem for me. After a web search I found articles like this one, which states 
      My drivers are up-to-date so that's no issue. I installed Microsoft's PIX, but I was unable to use it. I could configure my game for x64, but PIX is not able to process DirectX 11.. After getting only error messages, I installed NVIDIA's NSight. After adjusting my game and installing all components, I couldn't get a proper result, because my game freezes after a few frames. I haven't figured out why. There is no exception or error message and other debug mechanisms like log messages and break points tell me the game freezes at the end of the render function after a few frames. So, I looked for another profiling tool and found Jeremy's GPUProfiler. However, the information returned by this tool is too basic to get an in-depth knowledge about my performance issues.
      Can anyone recommend a GPU Profiler or any other tool that might help me to find bottlenecks in my game and or that is able to indicate performance problems in my shaders? My custom graphics engine can handle subjects like multi-texturing, instancing, soft shadowing, animation, etc. However, I am pretty sure, there are things I can optimize!
      I am using SharpDX to develop a game (engine) based on DirectX 11 with .NET Framework 4.5. My graphics cards is from NVIDIA and my processor is made by Intel.
  • Popular Now