• Advertisement
  • Popular Tags

  • Popular Now

  • Advertisement
  • Similar Content

    • By evelyn4you
      Hello,
      i try to implement voxel cone tracing in my game engine.
      I have read many publications about this, but some crucial portions are still not clear to me.
      At first step i try to emplement the easiest "poor mans" method
      a.  my test scene "Sponza Atrium" is voxelized completetly in a static voxel grid 128^3 ( structured buffer contains albedo)
      b. i dont care about "conservative rasterization" and dont use any sparse voxel access structure
      c. every voxel does have the same color for every side ( top, bottom, front .. )
      d.  one directional light injects light to the voxels ( another stuctured buffer )
      I will try to say what i think is correct ( please correct me )
      GI lighting a given vertecie  in a ideal method
      A.  we would shoot many ( e.g. 1000 ) rays in the half hemisphere which is oriented according to the normal of that vertecie
      B.  we would take into account every occluder ( which is very much work load) and sample the color from the hit point.
      C. according to the angle between ray and the vertecie normal we would weigth ( cosin ) the color and sum up all samples and devide by the count of rays
      Voxel GI lighting
      In priciple we want to do the same thing with our voxel structure.
      Even if we would know where the correct hit points of the vertecie are we would have the task to calculate the weighted sum of many voxels.
      Saving time for weighted summing up of colors of each voxel
      To save the time for weighted summing up of colors of each voxel we build bricks or clusters.
      Every 8 neigbour voxels make a "cluster voxel" of level 1, ( this is done recursively for many levels ).
      The color of a side of a "cluster voxel" is the average of the colors of the four containing voxels sides with the same orientation.

      After having done this we can sample the far away parts just by sampling the coresponding "cluster voxel with the coresponding level" and get the summed up color.
      Actually this process is done be mip mapping a texture that contains the colors of the voxels which places the color of the neighbouring voxels also near by in the texture.
      Cone tracing, howto ??
      Here my understanding is confus ?? How is the voxel structure efficiently traced.
      I simply cannot understand how the occlusion problem is fastly solved so that we know which single voxel or "cluster voxel" of which level we have to sample.
      Supposed,  i am in a dark room that is filled with many boxes of different kind of sizes an i have a pocket lamp e.g. with a pyramid formed light cone
      - i would see some single voxels near or far
      - i would also see many different kind of boxes "clustered voxels" of different sizes which are partly occluded
      How do i make a weighted sum of this ligting area ??
      e.g. if i want to sample a "clustered voxel level 4" i have to take into account how much per cent of the area of this "clustered voxel" is occluded.
      Please be patient with me, i really try to understand but maybe i need some more explanation than others
      best regards evelyn
       
       
    • By Endemoniada

      Hi guys, when I do picking followed by ray-plane intersection the results are all wrong. I am pretty sure my ray-plane intersection is correct so I'll just show the picking part. Please take a look:
       
      // get projection_matrix DirectX::XMFLOAT4X4 mat; DirectX::XMStoreFloat4x4(&mat, projection_matrix); float2 v; v.x = (((2.0f * (float)mouse_x) / (float)screen_width) - 1.0f) / mat._11; v.y = -(((2.0f * (float)mouse_y) / (float)screen_height) - 1.0f) / mat._22; // get inverse of view_matrix DirectX::XMMATRIX inv_view = DirectX::XMMatrixInverse(nullptr, view_matrix); DirectX::XMStoreFloat4x4(&mat, inv_view); // create ray origin (camera position) float3 ray_origin; ray_origin.x = mat._41; ray_origin.y = mat._42; ray_origin.z = mat._43; // create ray direction float3 ray_dir; ray_dir.x = v.x * mat._11 + v.y * mat._21 + mat._31; ray_dir.y = v.x * mat._12 + v.y * mat._22 + mat._32; ray_dir.z = v.x * mat._13 + v.y * mat._23 + mat._33;  
      That should give me a ray origin and direction in world space but when I do the ray-plane intersection the results are all wrong.
      If I click on the bottom half of the screen ray_dir.z becomes negative (more so as I click lower). I don't understand how that can be, shouldn't it always be pointing down the z-axis ?
      I had this working in the past but I can't find my old code
      Please help. Thank you.
    • By turanszkij
      Hi,
      I finally managed to get the DX11 emulating Vulkan device working but everything is flipped vertically now because Vulkan has a different clipping space. What are the best practices out there to keep these implementation consistent? I tried using a vertically flipped viewport, and while it works on Nvidia 1050, the Vulkan debug layer is throwing error messages that this is not supported in the spec so it might not work on others. There is also the possibility to flip the clip scpace position Y coordinate before writing out with vertex shader, but that requires changing and recompiling every shader. I could also bake it into the camera projection matrices, though I want to avoid that because then I need to track down for the whole engine where I upload matrices... Any chance of an easy extension or something? If not, I will probably go with changing the vertex shaders.
    • By evelyn4you
      Hello,
      in my game engine i want to implement my own bone weight painting tool, so to say a virtual brush painting tool for a mesh.
      I have already implemented my own "dual quaternion skinning" animation system with "morphs" (=blend shapes)  and "bone driven"  "corrective morphs" (= morph is dependent from a bending or twisting bone)
      But now i have no idea which is the best method to implement a brush painting system.
      Just some proposals
      a.  i would build a kind of additional "vertecie structure", that can help me to find the surrounding (neighbours) vertecie indexes from a given "central vertecie" index
      b.  the structure should also give information about the distance from the neighbour vertecsies to the given "central vertecie" index
      c.  calculate the strength of the adding color to the "central vertecie" an the neighbour vertecies by a formula with linear or quadratic distance fall off
      d.  the central vertecie would be detected as that vertecie that is hit by a orthogonal projection from my cursor (=brush) in world space an the mesh
            but my problem is that there could be several  vertecies that can be hit simultaniously. e.g. i want to paint the inward side of the left leg. the right leg will also be hit.
      I think the given problem is quite typical an there are standard approaches that i dont know.
      Any help or tutorial are welcome
      P.S. I am working with SharpDX, DirectX11
        
    • By Luca Davidian
      Hi, I'm implementing a simple 3D engine based on DirectX11. I'm trying to render a skybox with a cubemap on it and to do so I'm using DDS Texture Loader from DirectXTex library. I use texassemble to generate the cubemap (texture array of 6 textures) into a DDS file that I load at runtime. I generated a cube "dome" and sample the texture using the position vector of the vertex as the sample coordinates (so far so good), but I always get the same face of the cubemap mapped on the sky. As I look around I always get the same face (and it wobbles a bit if I move the camera). My code:   
      //Texture.cpp:         Texture::Texture(const wchar_t *textureFilePath, const std::string &textureType) : mType(textureType)         {             //CreateDDSTextureFromFile(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, &mResource, &mShaderResourceView);             CreateDDSTextureFromFileEx(Game::GetInstance()->GetDevice(), Game::GetInstance()->GetDeviceContext(), textureFilePath, 0, D3D11_USAGE_DEFAULT, D3D11_BIND_SHADER_RESOURCE, 0, D3D11_RESOURCE_MISC_TEXTURECUBE, false, &mResource, &mShaderResourceView);         }     // SkyBox.cpp:          void SkyBox::Draw()     {         // set cube map         ID3D11ShaderResourceView *resource = mTexture.GetResource();         Game::GetInstance()->GetDeviceContext()->PSSetShaderResources(0, 1, &resource);              // set primitive topology         Game::GetInstance()->GetDeviceContext()->IASetPrimitiveTopology(D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST);              mMesh.Bind();         mMesh.Draw();     }     // Vertex Shader:     cbuffer Transform : register(b0)     {         float4x4 viewProjectionMatrix;     };          float4 main(inout float3 pos : POSITION) : SV_POSITION     {         return mul(float4(pos, 1.0f), viewProjectionMatrix);     }     // Pixel Shader:     SamplerState cubeSampler;     TextureCube cubeMap;          float4 main(in float3 pos : POSITION) : SV_TARGET     {         float4 color = cubeMap.Sample(cubeSampler, pos.xyz);         return color;     } I tried both functions grom DDS loader but I keep getting the same result. All results I found on the web are about the old SDK toolkits, but I'm using the new DirectXTex lib.
  • Advertisement
  • Advertisement
Sign in to follow this  

DX11 An Invalid parameter was passed to the returning function?

This topic is 1968 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, Am trying to follow
http://www.braynzarsoft.net/index.php?p=D3D11BD
This tutorial but I keep getting
An Invalid parameter was passed to the returning function.
When my code try to run
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
I get a error message saying that An Invalid parameter was passed to the returning function and am not sure why :(
Thank you if you could explain it to me I also copy pasted my code in here if it was needed



#include <Windows.h>
#include <d3d11.h>
#include <D3DX11.h>
#include <D3DX10.h>
#include <xnamath.h>
#include <DxErr.h>
#pragma comment(lib, "DXErr.lib")
#pragma comment(lib, "d3d11.lib")
#pragma comment(lib, "d3dx11.lib")
#pragma comment(lib, "d3dx10.lib")
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed);
int messageLoop();
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam);

HRESULT hr;
HWND hWnd = NULL;
const int windowWidth = 800;
const int windowHeight = 600;
//3DirectX
bool InitDirect3D11App(HINSTANCE hInstance);
void ReleaseObjects();
bool InitScene();
void UpdateScene();
void DrawScene();

IDXGISwapChain* SwapChain;
ID3D11Device* D3d11Device;
ID3D11DeviceContext* D3d11DevCon;
ID3D11RenderTargetView* renderTargetView;
ID3D11Buffer* TriangleVertBuffer;
ID3D11VertexShader* VS;
ID3D11PixelShader* PS;
ID3D10Blob* VSBuffer;
ID3D10Blob* PSBuffer;
ID3D11InputLayout* VertLayout;
struct Vertex //Overloaded Vertex Structure
{
Vertex(){}
Vertex(float x, float y, float z)
: pos(x,y,z){}
XMFLOAT3 pos;
};
D3D11_INPUT_ELEMENT_DESC layout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
UINT numElements = ARRAYSIZE(layout);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE prevInstance,LPSTR lpCmnLine, int nShowCmd)
{
if(!InitializeWindow(hInstance,nShowCmd,windowWidth,windowHeight,true))
{
MessageBox(0,"Window Initilize Failed","Error",MB_OK);
return 0;
}
if(!InitDirect3D11App(hInstance))
{
MessageBox(0,"DirectX Init Failed","Error",MB_OK);
return 0;
}
if(!InitScene())
{
MessageBox(0,"Scene Init Failed","Error",MB_OK);
return 0;
}
messageLoop();
ReleaseObjects();
return 0;
}
int messageLoop()
{
MSG msg;
ZeroMemory(&msg,sizeof(MSG));
while(true)
{
if(PeekMessage(&msg,NULL,0,0,PM_REMOVE))
{
if(msg.message == WM_QUIT)
{
break;
}
TranslateMessage(&msg);
DispatchMessage(&msg);

}
else
{
UpdateScene();
DrawScene();
}
}
return (int) msg.wParam;
}
bool InitializeWindow(HINSTANCE hInstance,int showWnd,int windowWidth, int windowHeight,bool windowed)
{

LPCTSTR WndClassName = "FusionEmptyWindowClass";
LPCTSTR windowTitleBar = "Fusion Empty:Placement Phase";
WNDCLASSEX wc;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = CS_HREDRAW | CS_VREDRAW;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = NULL;
wc.cbWndExtra = NULL;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL,IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+2);
wc.lpszMenuName = NULL;
wc.lpszClassName = WndClassName;
wc.hIconSm = LoadIcon(NULL, IDI_WINLOGO);
if(!RegisterClassEx(&wc))
{
MessageBox(NULL,"Error Registering The Window Class","Error",MB_OK | MB_ICONERROR);
return 0;
}
hWnd = CreateWindowEx
(
NULL,
WndClassName,
windowTitleBar,
WS_OVERLAPPEDWINDOW,
CW_USEDEFAULT,
CW_USEDEFAULT,
windowWidth,
windowHeight,
NULL,
NULL,
hInstance,
NULL
);
if (!hWnd)
{
MessageBox(NULL, "Error creating window",
"Error", MB_OK | MB_ICONERROR);
return 0;
}
ShowWindow(hWnd,showWnd);
UpdateWindow(hWnd);
return true;
}
bool InitDirect3D11App(HINSTANCE hInstace)
{
//Buffer describer
DXGI_MODE_DESC BufferDesc;

ZeroMemory(&BufferDesc,sizeof(DXGI_MODE_DESC));
BufferDesc.Width = windowWidth;
BufferDesc.Height = windowHeight;
BufferDesc.RefreshRate.Numerator= 60;
BufferDesc.RefreshRate.Denominator= 1;
BufferDesc.Format = DXGI_FORMAT_R8G8B8A8_UNORM;
BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;


//Describe our SwapChain
DXGI_SWAP_CHAIN_DESC SwapChainDesc;

ZeroMemory(&SwapChainDesc,sizeof(DXGI_SWAP_CHAIN_DESC));

SwapChainDesc.BufferDesc = BufferDesc;
SwapChainDesc.SampleDesc.Count = 1;
SwapChainDesc.SampleDesc.Quality = 0;
SwapChainDesc.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
SwapChainDesc.BufferCount = 2;
SwapChainDesc.OutputWindow = hWnd;
SwapChainDesc.Windowed = true;
SwapChainDesc.SwapEffect = DXGI_SWAP_EFFECT_DISCARD;

//Creating the SwapChain
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,NULL,NULL,NULL,
D3D11_SDK_VERSION,
&SwapChainDesc,
&SwapChain,
&D3d11Device,
NULL,
&D3d11DevCon
);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3D11CreateDeviceAndSwapChain"),MB_OK);
return 0;

}
//BackBuffer Creating
ID3D11Texture2D* BackBuffer;
hr = SwapChain->GetBuffer( 0, __uuidof( ID3D11Texture2D ), (void**)&BackBuffer );
if(FAILED(hr))
{
MessageBox(NULL, DXGetErrorDescription(hr),TEXT("SwapChain->GetBuffer"), MB_OK);
return 0;
}
//Rendering Target
hr = D3d11Device->CreateRenderTargetView(BackBuffer,NULL,&renderTargetView);
BackBuffer->Release();
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),TEXT("D3d11Device->CreateRenderTargetView"),MB_OK);
return 0;
}
//Targeting Render target
D3d11DevCon->OMSetRenderTargets( 1, &renderTargetView, NULL ); // <----------------- SET NOT GET!!!!!!
//Set the target
return true;

}
bool InitScene()
{

//Compile Shaders from shader file 5 or 4 = VERSION
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "VS", "vs_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}
hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &VSBuffer, 0, 0);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3DX11CompileFromFile",MB_OK);
}


//Create the Shader Objects
//The problem
hr = D3d11Device->CreateVertexShader(VSBuffer->GetBufferPointer(), VSBuffer->GetBufferSize(), NULL, &VS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreateVertexShader",MB_OK);
}
hr = D3d11Device->CreatePixelShader(PSBuffer->GetBufferPointer(), PSBuffer->GetBufferSize(), NULL, &PS);
if(FAILED(hr))
{
MessageBox(NULL,DXGetErrorDescription(hr),"D3d11Device->CreatePixelShader",MB_OK);
}
//Set Vertex and Pixel Shaders
D3d11DevCon->VSSetShader(VS, 0, 0);
D3d11DevCon->PSSetShader(PS, 0, 0);
//Create the vertex buffer
Vertex v[] =
{
Vertex( 0.0f, 0.5f, 0.5f ),
Vertex( 0.5f, -0.5f, 0.5f ),
Vertex( -0.5f, -0.5f, 0.5f ),
};
D3D11_BUFFER_DESC vertexBufferDesc;
ZeroMemory( &vertexBufferDesc, sizeof(vertexBufferDesc) );
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
vertexBufferDesc.ByteWidth = sizeof( Vertex ) * 3;
vertexBufferDesc.BindFlags = D3D11_BIND_VERTEX_BUFFER;
vertexBufferDesc.CPUAccessFlags = 0;
vertexBufferDesc.MiscFlags = 0;
D3D11_SUBRESOURCE_DATA vertexBufferData;
ZeroMemory( &vertexBufferData, sizeof(vertexBufferData) );
vertexBufferData.pSysMem = v;
hr = D3d11Device->CreateBuffer( &vertexBufferDesc, &vertexBufferData, &TriangleVertBuffer);
//Set the vertex buffer
UINT stride = sizeof( Vertex );
UINT offset = 0;
D3d11DevCon->IASetVertexBuffers( 0, 1, &TriangleVertBuffer, &stride, &offset );
//Create the Input Layout
hr = D3d11Device->CreateInputLayout( layout, numElements, VSBuffer->GetBufferPointer(),
VSBuffer->GetBufferSize(), &VertLayout );
//Set the Input Layout
D3d11DevCon->IASetInputLayout( VertLayout );
//Set Primitive Topology
D3d11DevCon->IASetPrimitiveTopology( D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
//Create the Viewport
D3D11_VIEWPORT viewport;
ZeroMemory(&viewport, sizeof(D3D11_VIEWPORT));
viewport.TopLeftX = 0;
viewport.TopLeftY = 0;
viewport.Width = windowWidth;
viewport.Height = windowHeight;
//Set the Viewport
D3d11DevCon->RSSetViewports(1, &viewport);

return true;
}
void UpdateScene()
{

}
void DrawScene()
{
float bgColor[4] = {(0.0f, 0.0f, 0.0f, 0.0f)};
D3d11DevCon->ClearRenderTargetView(renderTargetView, bgColor);
D3d11DevCon->Draw( 3, 0 );
SwapChain->Present(0,0);
}
void ReleaseObjects()
{
//Window Release
SwapChain->Release();
D3d11Device->Release();
D3d11DevCon->Release();
//Rendering Release
TriangleVertBuffer->Release();
VS->Release();
PS->Release();
VSBuffer->Release();
PSBuffer->Release();
VertLayout->Release();

}
LRESULT CALLBACK WndProc(HWND hWnd,UINT msg,WPARAM wParam,LPARAM lParam)
{
switch(msg)
{
case WM_KEYDOWN:
{
if(wParam == VK_ESCAPE)
{
if(MessageBox(0,"Are you sure you want to Quit","Really", MB_YESNO | MB_ICONQUESTION) == IDYES)
{
DestroyWindow(hWnd);
}
}
return 0;
}
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;

}
}
return DefWindowProc(hWnd,msg,wParam,lParam);
}

Share this post


Link to post
Share on other sites
Advertisement
I've noticed it is possible to successfully compile a shader into object code (array of DWORDs) and still have CreateVertexShader() fail with INVALID_PARAMETER if the original shader had invalid numbers of instructions, samplers, constants, etc.

What does the shader you are submitting look like? Edited by Steve_Segreto

Share this post


Link to post
Share on other sites
Look like this :3

float4 VS(float4 inPos : POSITION) : SV_POSITION
{
return inPos;
}
float4 PS() : SV_TARGET
{
return float4(0.0f, 0.0f, 1.0f, 1.0f);
}

Share this post


Link to post
Share on other sites
Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong. Edited by eppo

Share this post


Link to post
Share on other sites
I also tried version 4, but it gave me the same error and I tried both on my lappy and station computer, my laptop should support version 5, cause atleast that what google said >.<, But I will try the Debug flag tommorow,unable to do it at the moment :( Edited by Conny14156

Share this post


Link to post
Share on other sites

Perhaps your hardware simply doesn't support shader model 5?

Create the D3D11 device with the debug layer enabled (D3D11_CREATE_DEVICE_DEBUG device flag). This should give you more insight as to what could be wrong.

This may seems a stupid question but is this the correct way?
hr = D3D11CreateDeviceAndSwapChain
(
NULL,
D3D_DRIVER_TYPE_HARDWARE,
NULL,
D3D11_CREATE_DEVICE_DEBUG,
NULL,
NULL,
D3D11_SDK_VERSION,
&amp;SwapChainDesc,
&amp;SwapChain,
&amp;D3d11Device,
NULL,
&amp;D3d11DevCon
);

I get no "compiler error" when I do this but nothing else really changed o.o Edited by Conny14156

Share this post


Link to post
Share on other sites
I tested a few things today and it seems like D3d11Device->CreatePixelShader somehow is the source of my problem, am not sure why but if I remove this my compiler doesnt complains any more about the CreateVertexShader but something else. Is it possible that the PixelShader returns onto the vertex and thus creating the problem? or is it cause I have DxErr included? I notice that in the the tutorial source file he does not have it cause it looks cleaner that way, but is it also the cause of my error?

Share this post


Link to post
Share on other sites
When you compile your pixelshader you are providing a pointer to the Vertexbuffer rather than the Pixelbuffer.
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &PSBuffer, 0, 0);[/source]

Share this post


Link to post
Share on other sites

When you compile your pixelshader you are providing a pointer to the Vertexbuffer rather than the Pixelbuffer.
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;VSBuffer, 0, 0);[/source]
Should be:
[source lang="cpp"]hr = D3DX11CompileFromFile("Effects.fx", 0, 0, "PS", "ps_5_0", 0, 0, 0, &amp;PSBuffer, 0, 0);[/source]


Yeha I noticed that to early today, biggest fail ever :(. but thank you :3. Edited by Conny14156

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement