Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!


1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


pulo

Member Since 23 Jun 2012
Offline Last Active Aug 17 2014 04:56 AM

Topics I've Started

Dynamic Shader Linkage and ShaderReflection

22 June 2014 - 06:24 AM

Hey there,

 

i am currently trying to integrate Dynamic Shader Linkage into my ShaderReflection Code. I examined the Win32 Sample Microsoft provided, where they are declaring a cbuffer like this:

cbuffer cbPerFrame : register( b0 )
{
   cAmbientLight     g_ambientLight;
   cHemiAmbientLight g_hemiAmbientLight;
   cDirectionalLight g_directionalLight;
   cEnvironmentLight g_environmentLight;
   float4            g_vEyeDir;   
};

While cAmbientLight, cHemiAmbientLight etc. are all classes interfacing the iBaseLight interface. This is a example:

 

interface iBaseLight
{
   float3 IlluminateAmbient(float3 vNormal);
   
   float3 IlluminateDiffuse(float3 vNormal);


   float3 IlluminateSpecular(float3 vNormal, int specularPower );
   
};


//--------------------------------------------------------------------------------------
// Classes
//--------------------------------------------------------------------------------------
class cAmbientLight : iBaseLight
{
   float3 m_vLightColor;     
   bool     m_bEnable;
   
   float3 IlluminateAmbient(float3 vNormal);
      
   float3 IlluminateDiffuse(float3 vNormal)
   { 
      return (float3)0;
   }


   float3 IlluminateSpecular(float3 vNormal, int specularPower )
   { 
      return (float3)0;
   }
};

Now i am already able to get the needed constant buffer variables out of the reflection (m_vLightColor and m_bEnable in this case), but i was wondering if there is a reliable method to detect if the constant buffer variable is a interface class (like cAmbient Light for example).
The Reflection of this constant buffer only gives D3D_SVC_STRUCT as class type for the variables. By browing through the MSDN i notcied that there are existing two classes which would suit: D3D_SVC_INTERFACE_POINTER and D3D_SVC_INTERFACE_CLASS.

Am i doing something wrong or is it normal that the class displayed here is a STRUCT?

 

 

 


Texure mapping goes wrong. Why?

14 June 2014 - 02:24 PM

Hey there,

 

i am currently trying to render a model and "attach" a texture to it.

The model is based on a .obj file which i am converting to a binary file for faster loading times (my code is nearly the same as this one: http://www.getcodesamples.com/src/B364EC3C/690BAF9B).

 

Now rendering the model works quite nice. 

Texture mapping seems to be a problem though. By looking at my rendering it seems like the texture coordinates are wrong, but the obj2vbo.cpp file was provided by microsoft in a sample code, so i would rather look a my own code first.

 

This is how i load the binary file:

void createMeshData(_In_ byte* meshData, _Out_ VertexBuffer** vertexBuffer, _Out_ IndexBuffer** indexBuffer, _Out_ uint32* vertexCount, _Out_ uint32* indexCount){
    *vertexCount = *reinterpret_cast<uint32*>(meshData);
    *indexCount = *reinterpret_cast<uint32*>(meshData + sizeof(uint32));
    BasicVertex* vertices = reinterpret_cast<BasicVertex*>(meshData + sizeof(uint32)* 2);
    *vertexBuffer = this->m_renderer->createVertexBuffer(vertices, sizeof(BasicVertex) * (*vertexCount), false);
    unsigned short* indices = reinterpret_cast<unsigned short*>(meshData + sizeof(uint32)* 2 + sizeof (BasicVertex)* (*vertexCount));
    *indexBuffer = this->m_renderer->createIndexBuffer(indices, sizeof(unsigned short)* (*indexCount), false);
}

By debugging the Shader i found that my samplerState and my TextureResource bound to the shader should be correct.

My sampler description looks like this:

 

D3D11_SAMPLER_DESC samplerDesc;
samplerDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
samplerDesc.MipLODBias = 0.0f;
samplerDesc.MaxAnisotropy = 1;
samplerDesc.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDesc.BorderColor[0] = 0.0f; samplerDesc.BorderColor[1] = 0.0f; samplerDesc.BorderColor[2] = 0.0f; samplerDesc.BorderColor[3] = 0.0f;
samplerDesc.MinLOD = 0;
samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;

While this is my PixelShader:

 

Texture2D objTexture;
SamplerState samplerState;


struct PixelInput
{
    float4 position : SV_POSITION;
    float2 tex: TEXCOORD0;
};


float4 main(PixelInput input) : SV_TARGET
{
    float4 textureColor;


    textureColor = objTexture.Sample(samplerState, input.tex);


    return textureColor;
}

Do you see something obvious wrong? If not then let me know and i take another look at my conversion code or post it here aswell if i see nothing wrong with it.

Thanks in advance!

 

EDIT: Here is a picture of how it looks at the moment:

ddWOnu4.jpg


D3DReflect does not detect constant buffers

26 May 2014 - 03:51 PM

Hey there,

So i am trying to get the number of constant buffers from my compiled shaders through reflection. Sadly it is not working as expected and i don't know why. Here is how i load the shader code inside a ID3DBlob:

ID3DBlob* vertexBlob;
HRESULT result = D3DReadFileToBlob(vertexShader.c_str(), &vertexBlob);

And this is how i get the reflection:

ComPtr<ID3D11ShaderReflection> reflection;
HRESULT hr = D3DReflect(shader.code->GetBufferPointer(), shader.code->GetBufferSize(), IID_ID3D11ShaderReflection, reinterpret_cast<void**>(reflection.GetAddressOf()));

if (FAILED(hr)) {
// SOMETHING WENT WRONG;
return (nullptr);
}

D3D11_SHADER_DESC shaderDesc;
reflection->GetDesc(&shaderDesc);

If i check the shaderDesc in Debug the ConstantBuffers variable is 0. I already made sure that changes made to the Shader are getting recognized. I added another input variable and the number of input parameters inside the description increased. Finally here is how i define the constant buffer, but i don't think that this is the problem:

cbuffer perObject 
{
matrix worldViewProj;
};

struct vertexInput
{
float3 position : POSITION;
float3 color : COLOR;
};

float4 main(vertexInput input) : SV_POSITION
{
return float4(input.position, 1.0f);
}

Has anyone any ideas what might be wrong?-
Thank you in advance.

 

 


Window creation called from constructor not working

08 March 2014 - 06:39 AM

Hi there,
 
i am trying to implement a little wrapper class for the win32 window api. It works quite nicely, but one problem i cannot seem to solve remains, and it is a quite peculiar one. 
This is the code in the class (only the relevant parts):

 

LRESULT CALLBACK WindowProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
    // sort through and find what code to run for the message given
    switch (message)
    {
        // this message is read when the window is closed
        case WM_DESTROY:
        {
            // close the application entirely
            PostQuitMessage(0);
            return 0;
        }break;
     }


    // Handle any messages the switch statement didn't
    return DefWindowProc(hWnd, message, wParam, lParam);
}

Window::Window(HINSTANCE thisInstance, DirectX::XMINT2 size, wstring title, bool enableFullscreen) :
appInstance(thisInstance),
position(0, 0),
size(size),
#ifdef UNICODE
title(title),
#else
title(string(title.begin(), title.end())),
#endif
fullscreen(false)
{
    this->buildWindow();
    if (fullscreen)
        setFullscreenWindowed(true);
}


Window::~Window()
{
    DestroyWindow(windowHandle);


    UnregisterClass(CLASSNAME, appInstance);
}


void Window::buildWindow()
{
    WNDCLASSEX wClass; //window class structur
    wClass.hInstance = this->appInstance;
    wClass.lpszClassName = "Classname";
    wClass.lpfnWndProc = WindowProc;
    wClass.style = CS_HREDRAW | CS_VREDRAW;
    wClass.cbSize = sizeof(WNDCLASSEX);
    wClass.hIcon = NULL;
    wClass.hCursor = LoadCursor(NULL, IDC_ARROW);
    wClass.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
    wClass.lpszMenuName = NULL;
    wClass.hbrBackground = NULL;
    wClass.cbClsExtra = 0;
    wClass.cbWndExtra = 0;
    if (!RegisterClassEx(&wClass))
    {
          Debug::getInstance().log("Faild to create Window Class", EDEBUG_LEVEL::E_ERROR);
          //throw some errors
          return;
    }

    this->windowHandle = CreateWindowEx(
         NULL,
        "Classname",
        "Dies ist ein Titel", //real window title
        WS_OVERLAPPED | WS_CAPTION | WS_SYSMENU | WS_MINIMIZEBOX,
        0, 0,
        800, 600,
        NULL,
        NULL,
        this->appInstance,
        NULL
        );
    if (this->windowHandle == NULL)
    {
         Debug::getInstance().log("CreateWindow failed.", EDEBUG_LEVEL::E_ERROR);
    }
}

void Window::show()
{
    ShowWindow(windowHandle, SW_SHOW);
    UpdateWindow(windowHandle);
    SetFocus(windowHandle);
}

And this is my main loop (in main.cpp)
 
 

int WINAPI WinMain(HINSTANCE instance, HINSTANCE prevInstance, PSTR sCmdLine, int cmdShow)
{
    Window mainWindow = Window(instance, { 800, 600 }, std::wstring(L"Hier steht ein netter Titel"), false);
    mainWindow.show();

    MSG msg;

    while (TRUE) {
        while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE)) {
            TranslateMessage(&msg);
            DispatchMessage(&msg);
        }

        if (msg.message == WM_QUIT) {
            break;
        }
    }

    return msg.wParam;
}

Now the problem is: The window does not appear. In fact it gets destroyed immediately after its creation. The reason for this seems to be that i call the 

buildWindow()

 method from the constructor of the Window class. If i call the method like a member function directly from the main-loop like 

mainWindow.buildWindow()

 right before 

mainWindow.show()

 it works as expected. What is wrong here?

 

Thanks in advance


Two objects appear on different heights (but same center)

06 December 2013 - 11:43 AM

I have a problem i am unable to solve. I've tried for several hours now, but i just don't understand what the problem is.

I am rendering different rectangles with the help of the DirectXTK (PrimitiveBatch) and surrounding them with a BoundingOrientedBox (DirectXCollision.h). For visualization i draw the corners of the BoundingBox to make sure that everything works fine. And it is! Except when i change the y-position of the rectangle. The strange thing is: My BoundingBox corners are below the actual rectangle, but the center of the rectangle and the center of the bounding box are both at the same and right position, only my rendered rectangle is mispositioned.
 

Here how i set up the BoundingBox:

this->boundingBox = new BoundingOrientedBox(XMFLOAT3(XMVectorGetX(this->position), XMVectorGetY(this->position), XMVectorGetZ(this->position)), XMFLOAT3(width/2.0f, height/2.0f, depth/2.0f), XMFLOAT4(XMVectorGetX(this->orientationQuaternion), XMVectorGetY(this->orientationQuaternion), XMVectorGetZ(this->orientationQuaternion), XMVectorGetW(this->orientationQuaternion)));

And this is how i set-up my vertices for the rectangle:

float x = XMVectorGetX(this->position) - getWidth()/2;
float y = XMVectorGetY(this->position) - getHeight()/2;
float z = XMVectorGetZ(this->position) - getDepth()/2;

// FRONT
this->vertexPosition[0] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z, 1), Colors::Blue);
this->vertexPosition[1] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z, 1), Colors::Blue);
this->vertexPosition[2] = VertexPositionColor(XMVectorSet(x, y, z, 1), Colors::Blue);
this->vertexPosition[3] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z, 1), Colors::Blue);
// RIGHT
this->vertexPosition[4] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z, 1), Colors::Blue);
this->vertexPosition[5] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[6] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z, 1), Colors::Blue);
this->vertexPosition[7] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z + getDepth(), 1), Colors::Blue);
// TOP
this->vertexPosition[8] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[9] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[10] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z, 1), Colors::Blue);
this->vertexPosition[11] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z, 1), Colors::Blue);
// BACK
this->vertexPosition[12] = VertexPositionColor(XMVectorSet(x + getWidth(), y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[13] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[14] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z + getDepth(), 1), Colors::Blue);
this->vertexPosition[15] = VertexPositionColor(XMVectorSet(x, y, z + getDepth(), 1), Colors::Blue);
// LEFT
this->vertexPosition[16] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z + getDepth(), 1), Colors::Blue);
this->vertexPosition[17] = VertexPositionColor(XMVectorSet(x, y + getHeight(), z, 1), Colors::Blue);
this->vertexPosition[18] = VertexPositionColor(XMVectorSet(x, y, z + getDepth(), 1), Colors::Blue);
this->vertexPosition[19] = VertexPositionColor(XMVectorSet(x, y, z, 1), Colors::Blue);
// BOTTOM
this->vertexPosition[20] = VertexPositionColor(XMVectorSet(x, y, z, 1), Colors::Blue);
this->vertexPosition[21] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z, 1), Colors::Blue);
this->vertexPosition[22] = VertexPositionColor(XMVectorSet(x, y, z + getDepth(), 1), Colors::Blue);
this->vertexPosition[23] = VertexPositionColor(XMVectorSet(x + getWidth(), y, z + getDepth(), 1), Colors::Blue);

This is how i calculate and apply the world transforms:

For the corner points:

XMMATRIX scale = XMMatrixScaling(0.01f, 0.01f, 0.01f);
XMMATRIX trans = XMMatrixTranslation(XMVectorGetX(cornerPoint), XMVectorGetY(cornerPoint), XMVectorGetZ(cornerPoint));
g_pEffectPositionNormal->SetWorld(scale * trans);

g_pBall->Draw(g_pEffectPositionNormal, g_pInputLayoutPositionNormal);

The cornerPoint is a vector with the position for one of the corners of the bounding box.
 

And my rectangle:

g_pEffectPositionNormal->SetWorld(body->getOrientation() * XMMatrixTranslation(XMVectorGetX(body->getPos()), XMVectorGetY(body->getPos()), XMVectorGetZ(body->getPos())));

g_pEffectPositionNormal->Apply(pd3dImmediateContext);
pd3dImmediateContext->IASetInputLayout(g_pInputLayoutPositionNormal);


g_pPrimitiveBatchPositionColor->Begin();
g_pPrimitiveBatchPositionColor->Draw(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP, body->getVertexPosition(), 24);
g_pPrimitiveBatchPositionColor->End();

Where getPos() returns the center point position of my rectangle

 

Do you see anything obvious wrong with it?
Thanks

 


PARTNERS