directx11 help

Post your questions, suggestions and experiences regarding to Image manipulation, 3d modeling and level editing for the Irrlicht engine here.

directx11 help

Postby Seven » Sun Nov 16, 2014 2:46 am

I thought i might be of use with the new d3d11 driver and would create a small app of my own to learn directx11 first.

i created an app the initializes directx11 and then created a scenenode class that mimicks irrlicht scenenode.
i am having trouble understanding the matrix's being passed to my simple shader though and could use some help understanding.

in the scenenode i use the same methods as irrlicht (position, rotation, scale) and use the same updateabsoluteposition() each frame.

when passing params to the shader, i am stuck at the worldMatrix.

if I pass in a default world matrix the cube is rendered and everything is fine, but the cube is rendered only at the original location. I assume that, in order to move / rotate the cube, i need to pass a different worldMatrix to the shader (i.e. a scenenode specific matrix) which i had assumed would be the result of the getAbsoluteTransformation() but it doesnt seem to work.


a little code......

in scenenode (assume absoluteposition is identical to irrlicht node function)

cpp Code: Select all
 
    void SN_Cube::render()
    {
        unsigned int stride;
        unsigned int offset;
 
        // Set vertex buffer stride and offset.
        stride = sizeof(VertexType);
        offset = 0;
   
        // Set the vertex buffer to active in the input assembler so it can be rendered.
        getEngine()->getd3dImmediateContext()->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);
 
        // Set the index buffer to active in the input assembler so it can be rendered.
        getEngine()->getd3dImmediateContext()->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);
 
        // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
        getEngine()->getd3dImmediateContext()->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
 
        //      getShader()->m_ObjectTransform = getAbsoluteTransformation();
        getShader()->m_ObjectTransform = getAbsoluteTransformation();
 
    }
 


and in shader wrapper class

cpp Code: Select all
 
    bool CSShader_Color::SetShaderParameters(ID3D11DeviceContext* deviceContext, XMMATRIX worldMatrix, XMMATRIX viewMatrix,
                                               XMMATRIX projectionMatrix)
    {
        HRESULT result;
        D3D11_MAPPED_SUBRESOURCE mappedResource;
        MatrixBufferType* dataPtr;
        unsigned int bufferNumber;
 
 
        // Transpose the matrices to prepare them for the shader.
        worldMatrix = m_ObjectTransform;
        worldMatrix = DirectX::XMMatrixTranspose(worldMatrix);
        viewMatrix = DirectX::XMMatrixTranspose(viewMatrix);
        projectionMatrix = DirectX::XMMatrixTranspose(projectionMatrix);
 
        // Lock the constant buffer so it can be written to.
        result = deviceContext->Map(m_matrixBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mappedResource);
        if(FAILED(result))
        {
            return false;
        }
 
        // Get a pointer to the data in the constant buffer.
        dataPtr = (MatrixBufferType*)mappedResource.pData;
 
        // Copy the matrices into the constant buffer.
        dataPtr->world = worldMatrix;
        dataPtr->view = viewMatrix;
        dataPtr->projection = projectionMatrix;
 
        // Unlock the constant buffer.
        deviceContext->Unmap(m_matrixBuffer, 0);
 
        // Set the position of the constant buffer in the vertex shader.
        bufferNumber = 0;
 
        // Finanly set the constant buffer in the vertex shader with the updated values.
        deviceContext->VSSetConstantBuffers(bufferNumber, 1, &m_matrixBuffer);
 
        return true;
    }
 



I know that m_ObjectTransform is a wrong way to do things but i am just testing..........

so the issue / question becomes

why does setting worldView to the scenenode's transform cause nothing to be rendered and how should I do this?
Seven
 
Posts: 888
Joined: Mon Nov 14, 2005 2:03 pm

Re: directx11 help

Postby mongoose7 » Sun Nov 16, 2014 3:00 am

Where do you get the view and projection matrices from? If you get them from Irrlicht, you should understand that they are already transposed. That's right, Irrlicht matrices are the transpose of what they say they are. (Look at the code for AxB; it is clearly performing BxA!)
mongoose7
 
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: directx11 help

Postby Seven » Sun Nov 16, 2014 3:10 am

thanks mongoose, the entire project only mimics irrlicht and doesnt actually use it. Just something small that has the feel of irrlicht so that I can understand better.

if i pass an identitymatrix as the worldMatrix then it all renders fine but of course, the node is just stationary.

how do i calculate the worldmatrix for a node? I assumed that I would use the getabsolutetransform() function to do it

cpp Code: Select all
    XMMATRIX CSSceneNode::getRelativeTransformation()
    {
        XMMATRIX mat;
        XMMatrixRotationRollPitchYaw(getRotation().x, getRotation().y, getRotation().z);
        XMMatrixTranslation(getPosition().x, getPosition().y, getPosition().z);
 
        if ((m_RelativeScale.x != 1.0f) || (m_RelativeScale.y != 1.0f) || (m_RelativeScale.z != 1.0f))
        {
            XMMATRIX smat;
            XMMatrixScaling(m_RelativeScale.x,m_RelativeScale.y,m_RelativeScale.z);
            mat *= smat;
        }
 
        return mat;
    }
 
    void CSSceneNode::updateAbsolutePosition()
    {
        if (getParent())
        {
            m_AbsoluteTransformation =
                getParent()->getAbsoluteTransformation() * getRelativeTransformation();
        }
        else
            m_AbsoluteTransformation = getRelativeTransformation();
    }
 


but for some reason it isnt working. I will keep playing around but am stuck for right now....
maybe some sleep will help :)
Seven
 
Posts: 888
Joined: Mon Nov 14, 2005 2:03 pm

Re: directx11 help

Postby mongoose7 » Sun Nov 16, 2014 1:14 pm

Whose getAbsoluteTransformation() are you using? It sounds as if it is Irrlicht's as you say "I assumed that I would use the getabsolutetransform() function to do it". If it were your own function then you would know whether to use it. I can only repeat that, if you use Irrlicht's matrices and your own matrices, there will be a stuff up if you don't realise that Irrlicht's matrices are actually the transpose of what they appear to be doing.
mongoose7
 
Posts: 1227
Joined: Wed Apr 06, 2011 12:13 pm

Re: directx11 help

Postby Seven » Tue Nov 18, 2014 11:09 pm

found it. stupid mistake on my part. On the bright side, I am now an expert at directx11, with spinning, moving cubes on the screen. I wonder if I should quit my day job just yet..........
Seven
 
Posts: 888
Joined: Mon Nov 14, 2005 2:03 pm


Return to Everything 2d/3d Graphics

Who is online

Users browsing this forum: No registered users and 1 guest