Sign in to follow this  
MattSmith_79985

DX11 Couple of DX10 Questions

Recommended Posts

So When I first learned Direct X it was DX11, but there wasn't a TON of resources available so I started going off Frank Luna's DX10 book. I feel that I understand everything besides a "few" select things (mainly differences between DX10 and 11)

Anyways here they go:
For Vertex and Index buffers I noticed this:

[code]
D3D10_BUFFER_DESC vbd;
vbd.Usage = D3D10_USAGE_IMMUTABLE;
vbd.ByteWidth = sizeof(Vertex) * mNumVertices;
vbd.BindFlags = D3D10_BIND_VERTEX_BUFFER;
vbd.CPUAccessFlags = 0;
vbd.MiscFlags = 0;
D3D10_SUBRESOURCE_DATA vinitData;
vinitData.pSysMem = &vertices[0]; <-------
HR(md3dDevice->CreateBuffer(&vbd, &vinitData, &mVB));[/code]

What exactly does the piece I have an arrow pointed at do? I think in DX11 it was something completely different (like 3 lines worth) I think we used something like:

[code]
D3D11_MAPPED_SUBRESOURCE ms;
devcon->Map(pVBuffer, NULL, D3D11_MAP_WRITE_DISCARD, NULL, &ms); // map the buffer
memcpy(ms.pData, OurVertices, sizeof(OurVertices)); // copy the data
devcon->Unmap(pVBuffer, NULL);[/code]


ok secondly is dealing with HLSL in DX11 I would compile the shader and do something like this:

[code]
ID3D10Blob *VS, *PS;
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "VShader", "vs_5_0", 0, 0, 0, &VS, 0, 0);
D3DX11CompileFromFile(L"shaders.hlsl", 0, 0, "PShader", "ps_5_0", 0, 0, 0, &PS, 0, 0);

// create the shader objects
dev->CreateVertexShader(VS->GetBufferPointer(), VS->GetBufferSize(), NULL, &pVS);
dev->CreatePixelShader(PS->GetBufferPointer(), PS->GetBufferSize(), NULL, &pPS);

// set the shader objects
devcon->VSSetShader(pVS, 0, 0);
devcon->PSSetShader(pPS, 0, 0);[/code]


but in the DX10 code it's like:

[code]
D3D10_TECHNIQUE_DESC techDesc;
mTech->GetDesc( &techDesc );
for(UINT p = 0; p < techDesc.Passes; ++p)
{
mWVP = mView*mProj;
mfxWVPVar->SetMatrix((float*)&mWVP);
mTech->GetPassByIndex( p )->Apply(0);
mLand.draw();
}[/code]


and this:

[code]
mTech = mFX->GetTechniqueByName("ColorTech");

mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();[/code]


I've looked around the book, and it doesnt really explain what these do.
also here's the HLSL for reference for the DX10 book

[code]
//=============================================================================
// color.fx by Frank Luna (C) 2008 All Rights Reserved.
//
// Transforms and colors geometry.
//=============================================================================


cbuffer cbPerObject
{
float4x4 gWVP;
};

void VS(float3 iPosL : POSITION,
float4 iColor : COLOR,
out float4 oPosH : SV_POSITION,
out float4 oColor : COLOR)
{
// Transform to homogeneous clip space.
oPosH = mul(float4(iPosL, 1.0f), gWVP);

// Just pass vertex color into the pixel shader.
oColor = iColor;
}

float4 PS(float4 posH : SV_POSITION,
float4 color : COLOR) : SV_Target
{
return color;
}
/*
RasterizerState Wireframe
{
FillMode = Wireframe;
CullMode = Back;
FrontCounterClockwise = false;
};*/

technique10 ColorTech
{
pass P0
{
SetVertexShader( CompileShader( vs_4_0, VS() ) );
SetGeometryShader( NULL );
SetPixelShader( CompileShader( ps_4_0, PS() ) );

//SetRasterizerState(Wireframe);
}
}[/code]


I've never seen a "technique" mentioned in DX11....and i'd def. never seen anything like this:

mTech = mFX->GetTechniqueByName("ColorTech");

mfxWVPVar = mFX->GetVariableByName("gWVP")->AsMatrix();

seems like creating an input layout and such is ALOT easier in DX11...

anyone care to explain what these are?

Share this post


Link to post
Share on other sites
Texus    248
The line where the arrow is pointing at just stores the adress of your first vertex in vinitData.pSysMem.
This is one of the things that vinitData stores.
If I am not wrong you can also just map it like in DX11.

The part you show about HLSL in DX11 is when initializing, while the DX10 code you posted is for drawing it.

The techniques are indead not used in DX11 (although you can use them).
In DX11 you work directly with the pixel and vertex shader, you can also do this in DX10 and then you don't have to use techniques.

I don't have much experience with it so I don't know whether you can use those variables without an effect in DX10.

Sorry that I edited this post a few times, but I accidentaly posted it to early.

Share this post


Link to post
Share on other sites
Six222    453
[color="#1C2837"][size="2"][color="#000000"]vinitData Is a pointer to the initial data to place inside the buffer once it's been created[/color][/size][/color]

[size="2"]And techniques are ways of calling different shaders for example...[/size]

[size="2"][code]
technique10 Tech1
{
Pass P0
{
SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PixelShaderWithNoEffects())); <---
}
}

technique10 Tech2
{
Pass P0
{

SetVertexShader(CompileShader(vs_4_0, VS()));
SetGeometryShader(NULL);
SetPixelShader(CompileShader(ps_4_0, PixelShaderWithEffects())); <---
}
}
[/code]
[/size][size="2"]And then in your main code you would just select a technique on which you would want to use[/size]

Share this post


Link to post
Share on other sites
Six222    453
You can still use memcpy to map data into a buffer... just the 2nd parameter in [color="#1C2837"][font="CourierNew, monospace"][size="2"][color="#000000"]md3dDevice[/color][color="#666600"]->[/color][color="#660066"]CreateBuffer[/color][color="#666600"](&[/color][color="#000000"]vbd[/color][color="#666600"],[/color] [color="#666600"]&[/color][color="#000000"]vinitData[/color][color="#666600"],[/color] [color="#666600"]&[/color][color="#000000"]mVB) is used to set initial data in the buffer you can just set it to NULL [/color][/size][/font][/color][font="CourierNew, monospace"][size="2"][color="#000000"]md3dDevice[/color][color="#666600"]->[/color][color="#660066"]CreateBuffer[/color][color="#666600"](&[/color][color="#000000"]vbd[/color][color="#666600"],[/color][color="#000000"] NULL[/color][color="#666600"],[/color] [color="#666600"]&[/color][color="#000000"]mVB)[/color][/size][/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][size="2"][color="#000000"]Oh and fail in my last post...[/color][/size][/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][size="2"][color="#000000"]Edit:[/color][/size][/font]
[font="CourierNew, monospace"] [/font]
[font="CourierNew, monospace"][size="2"][color="#000000"]Here's an example of copying data in dx10[/color][/size][/font]
[font="CourierNew, monospace"] [/font][font="CourierNew, monospace"][size="2"][code]
bool CVertexBuffer::MapIndexData(UINT numIndex, void* pData)
{
void* pVoid;
IndexBuffer->Map(D3D10_MAP_WRITE_DISCARD, 0, &pVoid); // map the vertex buffer
memcpy(pVoid, pData, sizeof(int) * numIndex); // copy the vertices to the buffer
IndexBuffer->Unmap();

this->numIndexes = numIndex;

return true;
}
[/code][/size][/font]

Share this post


Link to post
Share on other sites
Six222    453
[quote name='Mercfh' timestamp='1305645480' post='4811953']
^^ Ya thats what I did in the DX11. Ok that makes sense then.

the technique thing.......for DX10 is a whole different other mess tho.
[/quote]

Haha, yeah it's basically just a way to call different shader functions. It's mainly used for selecting which shaders to use on different graphics cards... If i remember correctly DX actually provides you with a function that decides which technique is better.

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  

  • Similar Content

    • By gomidas
      I am trying to add normal map to my project I have an example of a cube: 
      I have normal in my shader I think. Then I set shader resource view for texture (NOT BUMP)
                  device.ImmediateContext.PixelShader.SetShaderResource(0, textureView);             device.ImmediateContext.Draw(VerticesCount,0); What should I do to set my normal map or how it is done in dx11 generally example c++?
    • By fighting_falcon93
      Imagine that we have a vertex structure that looks like this:
      struct Vertex { XMFLOAT3 position; XMFLOAT4 color; }; The vertex shader looks like this:
      cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; struct VertexInput { float4 position : POSITION; float4 color : COLOR; }; struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; PixelInput main(VertexInput input) { PixelInput output; input.position.w = 1.0f; output.position = mul(input.position, world); output.position = mul(output.position, view); output.position = mul(output.position, projection); output.color = input.color; return output; } And the pixel shader looks like this:
      struct PixelInput { float4 position : SV_POSITION; float4 color : COLOR; }; float4 main(PixelInput input) : SV_TARGET { return input.color; } Now let's create a quad consisting of 2 triangles and the vertices A, B, C and D:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex B. vertices[1].position = XMFLOAT3( 1.0f, 1.0f, 0.0f); vertices[1].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // Vertex D. vertices[3].position = XMFLOAT3( 1.0f, -1.0f, 0.0f); vertices[3].color = XMFLOAT4( 0.5f, 0.5f, 0.5f, 1.0f); // 1st triangle. indices[0] = 0; // Vertex A. indices[1] = 3; // Vertex D. indices[2] = 2; // Vertex C. // 2nd triangle. indices[3] = 0; // Vertex A. indices[4] = 1; // Vertex B. indices[5] = 3; // Vertex D. This will result in a grey quad as shown in the image below. I've outlined the edges in red color to better illustrate the triangles:

      Now imagine that we’d want our quad to have a different color in vertex A:
      // Vertex A. vertices[0].position = XMFLOAT3(-1.0f, 1.0f, 0.0f); vertices[0].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      That works as expected since there’s now an interpolation between the black color in vertex A and the grey color in vertices B, C and D. Let’s revert the previus changes and instead change the color of vertex C:
      // Vertex C. vertices[2].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); vertices[2].color = XMFLOAT4( 0.0f, 0.0f, 0.0f, 1.0f);
      As you can see, the interpolation is only done half of the way across the first triangle and not across the entire quad. This is because there's no edge between vertex C and vertex B.
      Which brings us to my question:
      I want the interpolation to go across the entire quad and not only across the triangle. So regardless of which vertex we decide to change the color of, the color interpolation should always go across the entire quad. Is there any efficient way of achieving this without adding more vertices and triangles?
      An illustration of what I'm trying to achieve is shown in the image below:

       
      Background
      This is just a very brief explanation of the problems background in case that would make it easier for you to understand the problems roots and maybe help you with finding a better solution to the problem.
      I'm trying to texture a terrain mesh in DirectX11. It's working, but I'm a bit unsatisfied with the result. When changing the terrain texture of a single vertex, the interpolation with the other vertices results in a hexagon shape instead of a squared shape:

      As the red arrows illustrate, I'd like the texture to be interpolated all the way into the corners of the quads.
    • By -Tau-
      Hello, I'm close to releasing my first game to Steam however, my game keeps failing the review process because it keeps crashing. The problem is that the game doesn't crash on my computer, on my laptop, on our family computer, on fathers laptop and i also gave 3 beta keys to people i know and they said the game hasn't crashed.
      Steam reports that the game doesn't crash on startup but few frames after a level has been started.
      What could cause something like this? I have no way of debugging this as the game works fine on every computer i have.
       
      Game is written in C++, using DirectX 11 and DXUT framework.
    • By haiiry
      I'm trying to get, basically, screenshot (each 1 second, without saving) of Direct3D11 application. Code works fine on my PC(Intel CPU, Radeon GPU) but crashes after few iterations on 2 others (Intel CPU + Intel integrated GPU, Intel CPU + Nvidia GPU).
      void extractBitmap(void* texture) { if (texture) { ID3D11Texture2D* d3dtex = (ID3D11Texture2D*)texture; ID3D11Texture2D* pNewTexture = NULL; D3D11_TEXTURE2D_DESC desc; d3dtex->GetDesc(&desc); desc.BindFlags = 0; desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE; desc.Usage = D3D11_USAGE_STAGING; desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB; HRESULT hRes = D3D11Device->CreateTexture2D(&desc, NULL, &pNewTexture); if (FAILED(hRes)) { printCon(std::string("CreateTexture2D FAILED:" + format_error(hRes)).c_str()); if (hRes == DXGI_ERROR_DEVICE_REMOVED) printCon(std::string("DXGI_ERROR_DEVICE_REMOVED -- " + format_error(D3D11Device->GetDeviceRemovedReason())).c_str()); } else { if (pNewTexture) { D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); // Wokring with texture pNewTexture->Release(); } } } return; } D3D11SwapChain->GetBuffer(0, __uuidof(ID3D11Texture2D), reinterpret_cast< void** >(&pBackBuffer)); extractBitmap(pBackBuffer); pBackBuffer->Release(); Crash log:
      CreateTexture2D FAILED:887a0005 DXGI_ERROR_DEVICE_REMOVED -- 887a0020 Once I comment out 
      D3D11DeviceContext->CopyResource(pNewTexture, d3dtex); 
      code works fine on all 3 PC's.
    • By Fluffy10
      Hi i'm new to this forum and was wondering if there are any good places to start learning directX 11. I bought Frank D Luna's book but it's really outdated and the projects won't even compile. I was excited to start learning from this book because it gives detailed explanations on the functions being used as well as the mathematics. Are there any tutorials / courses /books that are up to date which goes over the 3D math and functions in a detailed manner? Or where does anyone here learn directX 11? I've followed some tutorials from this website http://www.directxtutorial.com/LessonList.aspx?listid=11 which did a nice job but it doesn't explain what's happening with the math so I feel like I'm not actually learning, and it only goes up until color blending. Rasteriks tutorials doesn't go over the functions much at all or the math involved either. I'd really appreciate it if anyone can point me in the right direction, I feel really lost. Thank you
  • Popular Now