I am piecing together information on how to import models following a bunch of different tutorials, because there isn't a resource that explains how to do this in a simple way.
So far I can import and display my model, but it's shown in the Gouraud shader if I use DirectX::BasicEffect
This makes my mechanical models appear very badly shaded, because they were exported from Solidworks.
I want to try switching to DirectX::DGSLEffect , but I need to load a shader, and I don't have any shaders to test.
Can anyone point me to where I can find a pre-compiled *.cso shader?
I need one that can preferably do flat shading, but I can settle for any, just to test that my application is working right.
I know that I need to compile a shader myself from .hlsl files, but this is too many steps and I just need something that works right now before I can continue further,
Thank you,
-D
I want to point out that I am not making a video game, but a mechanical visualization tool, and I do not need to know how to write shaders or do any advanced features of DirectX at this time. Please do not recommend reading books as that would be counter-productive to the amount of time I can work on this project. I would like to learn more in the future, but not for this application. Thanks,
EDIT:
It looks like I can compile with the following line, but now I cant find any HLSL files.
ID3DBlob* PS_Buffer;
D3DCompileFromFile(L"PixelSHader.hlsl", 0, 0, "main", "ps_5_0", 0, 0, &PS_Buffer, 0);
CSO files are complied HLSL shaders. Visual Studio can generate them from HLSL files, and the DGSL pipeline can create pixel shaders using a visual language.
The DirectX Tool Kit BasicEffect system is quite flexible, so you can override in code the parameters or provide your own material information. See the wiki for more information.
If you want to use the Visual Studio content pipeline, you should look at Working with 3-D Assets for Games and Apps for the details. Visual Studio converts WaveFront obj or Autodesk fbx files and can include DGSL materials as part of that pipeline. The DirectX Tool Kit DGSLEffect provides a built-in vertex shader that will work with the DGSL shader designer output.
If you'd like an example of using the DGSLEffect pipeline, look at the tutorial Creating custom shaders with DGSL.
Related
I have searched SO and have not found one relating to the very basics, explaining step by step. We are in need of this.
Assuming that I am using only the DirectX SDK supplied by microsoft.
Also assuming that I have .fbx and .3ds models already made and in the working directory which are generic, monochrome, shapes (cube, sphere, pyramid, etc.).
Please also condense the rendering process into a function that uses the directX functions (As in, can be compiled), as an example:
//the following is a suggestion, not a guideline for those who
//want to get into 3D programming.
vector<DX3DModel>modelsToBeRendered;
void bufferFrame(vector<DX3DModel>models){
while(1){
/* something something vertexes, lets say DX3DModel only contains vertexes
and a string as a file link
(Rendering code would make it very
messy in the question, but please include it in the answer.) */
//render models.end(); here
models.pop_back();
}
}
Using a method similar to what I have above, how would I (safely) render all other actors in a single "area" while still being able to manipulate vertexes at will?
(Area is a (AxBx1) model which we will call field.fbx. This is a boundary for all actors to exist on)
The Direct3D 11 API, much like the OpenGL API, is a low-level rendering API that works in terms of resources and drawing operations on constructs containing points, lines, and triangles. It's not a high-level API that can directly load or render an model file from a 3D editor, nor does it inherently have a material/effects system.
If you are new to DirectX 11, you should consider using the DirectX Tool Kit as a good starting-point. You can't directly render from a 3DS or FBX model, but you can use either the built-in Visual Studio content pipeline for converting to a CMO or use the Samples Content Exporter to convert to SDKMESH, both of which can be loaded by DirectX Tool Kit.
Using the DirectX Tool Kit, you'd be able to use the Model class and get something basically like what you propose. See the DirectX Tool Kit tutorial, particularly the lesson Rendering a model.
For Direct3D 11 development, you should strongly consider not using the legacy DirectX SDK as it's deprecated. If you are using VS 2012 or later, you don't need it. See Where is the DirectX SDK (2015 Edition)? and The Zombie DirectX SDK.
I just want know Directx 12 API to create texture from image.
For DX11 it is D3DX11CreateShaderResourceViewFromFile and for DX9 it is D3DXCreateTextureFromFileEx and for DX12 ?
Things are a little bit better by now. Microsoft rewrote their DDSTextureLoader for DX12 and released it as part of their MiniEngine on GitHub
https://github.com/Microsoft/DirectX-Graphics-Samples/blob/master/MiniEngine/Core/DDSTextureLoader.cpp
You also may want to take a look at my derivative work that is intended to make use of the DDSTextureLoader a bit easier outside of MiniEngine.
https://github.com/ClemensX/ShadedPath12/blob/master/ShadedPath12/ShadedPath12/DDSTextureLoader.cpp
I use this loader for all my texture files. It parses DDS (DirectDrawSurface) file format pretty well, including mipmaps.
There isn't one.
Direct3D 12 is a low-level API. A very low-level API. It doesn't have convenience functions that create textures out of whole cloth from just a filename. If you want to create a texture, you have to work for it. You have to load the file, figure out what format you want it in, allocate memory for it by asking the system how much memory it would take, then go through a complex series of steps to transfer your loaded image into that memory.
The official 'utility header' for Direct3D 12 is d3dx12.h. It's an inline header and has no DLL or static library, so the functionality provided is limited to true helpers. It has no equivalent to D3DX11CreateShaderResourceViewFromFile. It is not included as part of the Windows SDK, but instead is provided under the MIT license and you are expected to just copy it into your project--it's included in the various DirectX 12 Visual Studio templates including my Direct3D Game templates.
You can use the DDSTextureLoader and WICTextureLoader modules provided in the DirectX Tool Kit for DirectX 12 for some ready-to-use texture loader for Direct3D 12. See this tutorial lesson.
It's worth noting that D3DX9, D3DX10, and D3DX11 are all deprecated and only available as part of the legacy DirectX SDK per MSDN. In other words, you shouldn't be using D3DX11CreateShaderResourceViewFromFile for your Direct3D 11 code. See this blog post for a full list of D3DX9/10/11 replacements. TL;DR: use DDSTextureLoader and WICTextureLoader in DirectX Tool Kit for DirectX 11.
Google keeps referring to this topic for questions around DX-12 and textures, so let's update.
1. Managed
If you insist on "managed" check out the samples with the last version of SharpDX (2019)
https://github.com/discosultan/dx12-game-programming
It provides a C# interface to DX-12 native and it works, there are a lot of very nice samples, including texturing,
09-Crate loads a single DDS texture and shows it on a cube
09-TexColumns shows basic UV-coordinate actions on various shapes
.. but IMHO it's not really advisable, to keep depending on the good old SharpDX library, because that library is not maintained anymore. I can't advise good alternatives for C# atm, I'm not an expert on Unity and Vulkan.
2. Unmanaged
As mentioned earlier in this topic, DX-12 things improve. They still do. Check out Chuck Walbourn's current samples here,
https://github.com/microsoft/Xbox-ATG-Samples
For straight PC/x64, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/PCSamples
For PC/UWP, you'll find this,
https://github.com/microsoft/Xbox-ATG-Samples/tree/master/UWPSamples
These are very nice x64 unmanaged C++ 14.0 examples, using DirectXtk for DirectX-12. Last update in the Master was 3 months ago. Examples involving textures, also straight bitmap textures are
SimpleTexturePC12 loads a single .jpg texture and shows it in front view
DirectXTKSimpleSample12 loads several textures
Graphics\VideoTexturePC12 shows a dynamic texture read from an .mp4 video
These projects are configured for VS2017, but they convert out of the box when loading them in VS2019 and they compile and run ok.
Other sources
A known switchboard on DX-12 is vinjn on github, his page is
http://www.vinjn.com/awesome-d3d12/
Navigate from there to study articles and find various other samples.
There is a 3dgep.com tutorial on the subject of DX12 textures, that is
https://www.3dgep.com/learning-directx-12-4/
.. accompanied by
https://github.com/jpvanoosten/LearningDirectX12
Okay i have been studying opengl online, however most tutorials i have been seeing only cover the fixed pipeline. I am trying to add it into an object oriented project, however i am not quiet sure the modern process with shaders and such. Is the process as easy as binding a buffer, as well as a shader? And what exactly are handles used for? I have added glew and glfw, even though now my log is saying glew failed to initialize, error 1282, thats a whole different topic, unless glew and glfw are incompatable. Can anyone shine a light on this subject?
The handles in opengl are just GLInts, which for example could be used to work with a VBO, VAO, stuff like that.
As for the shader, it uses the glsl shading language. Then they give the functions to compile and link the shader to your opengl context.
Asking how shaders, handles, and setting up the environment work for opengl is a very broad question, you would be better off following a tutorial. A good one would be OpenglDev which covers all the basic concepts, as well as some advanced ones. It's not opengl-es, but if you understand those tutorials opengl-es should be no problem transitioning to. The Visual Studio solution project is available for download Here, which will come with the project already setup with the required libraries.
Currently I have a 3D Cube that I drew by writing coordinates, that can rotate and move on a black screen.
Now I have a Model that I created in "3Ds Max"(It's a little backyard with high stonewalls, so I'm trying to use it as my world object.) and I want to load this model into my DirectX9/C++ project.
As far as I see in DirectX SDK examples this code is for loading .X model (which needs a plugin for "3Ds Max" to export that kind of extension. I'm not sure of this.)
Code for loading .X files into DX9/C++:
D3DXLoadMeshFromX( "Tiger.x", D3DXMESH_SYSTEMMEM,
g_pd3dDevice, NULL, &pD3DXMtrlBuffer, NULL,
&g_dwNumMaterials, &g_pMesh )
Is there a function like "D3DXLoadMeshFromOBJ(.....)" to load an Object? How do I load and render .OBJ files? 8(
Another question of mine is what is the difference between an .X file and an .OBJ file and which of them should I use?
AFAIK, DirectX does not support wavefront object files out of the box. You will need an external mesh loader for that purpose.
I can remember, that in the DX 10 SDK is a sample of how to load an .obj file, I think the sample is called MeshFromOBJ10. I don't know if it is of any use in DirectX 9.
As far as I know, the standard .x just supports basic meshes with no enhancements such as animation. If you want to try out graphical programming it is not bad, but if you are aiming for higher concepts you can later switch. I guess you can look up the advantages of the .obj files here.
It is always a good idea to create an abstraction for the input data you are using. For example, you could create a class AbstractMesh and an implementation XMesh deriving from it. Later on, you can than add other implementations like OBJMesh or anything similar.
I hope I could help you a bit :) Happy Coding!
Animation is full supported in x file format, and furthermore, it support fx files when you want to use shaders. A exporter plugin and samples you can download from this page:
http://www.cgdev.net/download.php
I am trying to develop a 3D game in openGL and i need to create many 3D objects.. I am a begginner in openGL.. I have tried with many 3D softwares like Blender , MODO, Unity 3D and Cheetah.
I am easily able to create my objects with these and exporting as Wavefront .OBJ, and converting it to a header file using a perl script. This header file is added to my openGL project..
The 3D objects are seen, but its not perfect. The script i used is to convert the .OBJ to .h using TRIANGLES.. And the object is seen with triangles. Its not full.. No way when i used TRIANGLE STRIP,FAN..? Problems with the vertices..
Is the problem with my Script or is it the wrong way i have gone..?? Or is there any other best ways to directly import 3D objects to openGL..??
The below link is the best one which you can get for 3D objects to openGL.. i got the scripts from these..
http://www.heikobehrens.net/2009/08/27/obj2opengl/
please help..
You don't want to go that way. Direct drawing mode (using TRIANGLE and friends) is extremely slow in OpenGL.
Instead, you should pick a decent format and write a loader for it (or use one found on the web). Good formats would be 3ds, obj if gzipped, collada.
Here's an example tutorial on loading from Milkshape files.
Once you load your objects programatically, you can use Vertex Arrays, or even better VBO's to display them. This is waaay faster.
Google for a mesh loader for your favorite format, or write one yourself.
I have written a reader/renderer for AC3D files that works fine on the iPhone (OpenGL ES)
Feel free to have a look at it here.
There is also an obj loader by Jeff Lamarche at google code.
AC3D can reduce the triangle count pretty good and as an alternative I ported QVis to the mac. My reader/renderer also tries to build tri-strips.
About VBO's. I have not seen any gained performance when using them in the iPhone. I'm not the only one.