Jump to content
  • Advertisement

Endemoniada

Member
  • Content Count

    650
  • Joined

  • Last visited

Community Reputation

430 Neutral

1 Follower

About Endemoniada

  • Rank
    Advanced Member

Personal Information

  • Role
    Programmer
  • Interests
    Art
    Audio
    Design
    Programming

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. Endemoniada

    D3D11 Picking Problem

    Hi vinterberg, unfortunately the results are the same, it seems to have made no difference at all.
  2. Endemoniada

    D3D11 Picking Problem

    Hi guys, I'm just getting back to this and still can't figure out what's wrong. I'll post the complete code and results: // view matrix float3 camera_target = { 0.0f, 0.0f, 0.0f }; DirectX::XMVECTOR look = DirectX::XMVectorSet(camera_target.x, camera_target.y, camera_target.z, 0.0f); DirectX::XMVECTOR eye = DirectX::XMVectorSet(camera_target.x, camera_target.y + 64.0f, camera_target.z - 64.0f, 0.0f); DirectX::XMVECTOR up = DirectX::XMVectorSet(0.0f, 1.0f, 0.0f, 0.0f); DirectX::XMMATRIX view_matrix = DirectX::XMMatrixLookAtLH(eye, look, up); // projection matrix (orthographic with same aspect as screen 16:9) DirectX::XMMATRIX projection_matrix = DirectX::XMMatrixOrthographicLH(160.0f, 90.0f, 8.0f, 128.0f); // mouse/screen coordinates float screen_width = 1920; float screen_height = 1080; float mouse_x = params[0]; float mouse_y = params[1]; // picking part DirectX::XMFLOAT4X4 mat; DirectX::XMStoreFloat4x4(&mat, projection_matrix); float point_x = ((2.0f * mouse_x) / screen_width) - 1.0f; float point_y = -(((2.0f * mouse_y) / screen_height) - 1.0f); point_x = point_x / mat._11; point_y = point_y / mat._22; DirectX::XMMATRIX inv_view = DirectX::XMMatrixInverse(nullptr, view_matrix); DirectX::XMStoreFloat4x4(&mat, inv_view); float3 ray_origin = { mat._41, mat._42, mat._43 }; float3 ray_dir; ray_dir.x = (point_x * mat._11) + (point_y * mat._21) + mat._31; ray_dir.y = (point_x * mat._12) + (point_y * mat._22) + mat._32; ray_dir.z = (point_x * mat._13) + (point_y * mat._23) + mat._33; // normalize ray_dir (not sure if necessary) normalize3(&ray_dir); The camera is simply above and behind the world origin, looking down and forward at it, like a basic top-down view. The screen resolution (same as render target) is 1920 x 1080. Here are the results: (mouse coords in screen space) : (ray direction) (960, 540) : (0.0, -0.707, 0.707) (970, 540) : (0.640, -0.543, 0.543) (1000, 540) : (0.958, -0.203, 0.203) The first set is the centre of the screen and seems fine. The second set is just 10 pixels over to the right, but look at the ray_dir.x. Look at the third set, the mouse is just 40 pixels over to the right and the ray is pretty much pointing down the x-axis. I feel like I'm missing a step somewhere. Please help. Thank you.
  3. Endemoniada

    D3D11 Picking Problem

    Hi iedoc, yes, that was a typo, I fixed it. My camera is pointing down (isometric), like in Diablo. The ray from the camera position (eye) to the camera look at point is always positive z, so it's hard for me to see how the picking ray direction can have a negative z. In any case, I still can't figure out what I'm doing wrong. When I click parts of the flat ground that are in positive x and positive z they come up as negative and are totally inaccurate. For example, when I click the ground at world coordinates (0, 0, 0) it shows ~ (-70, 0, -70) and when I click at (4, 0, 0) it shows ~ (-58, 0, -80), the values are way off, the z shouldn't change at all, and the x should only change by 4. I'll keep trying.
  4. 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.
  5. Hi guys, I am having a hard time understanding projective texture mapping. I understand shadow mapping but just don't get what I'm supposed to do to project a texture (like light coming through a grill.) What do I actually draw, quads with the light textures? Maybe someone can tell me the basics. I'm talking about the projective texture mapping that looks like it's coming from a slide projector. Thanks a lot.
  6. Endemoniada

    DXGI_FORMAT_D16_UNORM to RGB ?

    Thanks MJP, I wasn't sure I was doing it right. For my depth and shadow maps I store the linear view space depth (normalized), I learned that from your posts. If I were using DXGI_FORMAT_R32_FLOAT should I do it the same way or just store the raw depth values ? Thanks again.
  7. Hi guys, I want to visualize textures having the DXGI_FORMAT_D16_UNORM format (like depth, shadow maps, etc.) I'm copying to the clipboard but can't figure out how to get the values. // resource is mapped to subresource for (int i = 0; i < texture_height; i++) { BYTE* src = (BYTE*)(subresource.pData) + (i * subresource.RowPitch); // start of row for (int j = 0; j < texture_width; j++) { grey = *((unsigned short*)(src)); // this isn't right // fill in my rgb values here src += 2; (advance 2 bytes = 16 bits) } } Please help. Thanks.
  8. Hi guys, I am setting up instanced drawing (non-indexed) like this: struct d3d_vertex { float x, y, z; float nx, ny, nz; float u, v, w; }; struct d3d_instance { float x, y, z; }; D3D11_INPUT_ELEMENT_DESC layout[4]; layout[0] = { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[1] = { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[2] = { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[3] = { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 }; ... UINT buffer_strides[2]; buffer_strides[0] = sizeof(d3d_vertex); buffer_strides[1] = sizeof(d3d_instance); d3d_context->IASetVertexBuffers(0, 2, bufferPointers, buffer_strides, buffer_offsets); ... d3d_context->DrawInstanced(tree_model.buffer_size, 1, 0, 0); I am getting this error: ID3D11DeviceContext::DrawInstanced: Input vertex slot 0 has stride 36 which is less than the minimum stride logically expected from the current Input Layout (48 bytes). What am I missing ? Thanks. **** solved part: layout[0] = { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[1] = { "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[2] = { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 }; layout[3] = { "TEXCOORD", 1, DXGI_FORMAT_R32G32B32_FLOAT, 1, 0, D3D11_INPUT_PER_INSTANCE_DATA, 1 };
  9. Hi Nypyren, That seems to be exactly what's happening. Once I added another file or two I noticed it, it seemed out of the ordinary so I thought something was wrong. Thanks a lot.
  10. Hi guys, This is really annoying. When I clean and rebuild VS does something like this: 1>------ Rebuild All started: Project: Castle, Configuration: Debug Win32 ------ 1> StdAfx.cpp 1> Vector.cpp ... ... 1> Generating Code... 1> Compiling... 1> Bitmap.cpp 1> Generating Code... 1> Castle.vcxproj -> C:\Code\Projects\Castle\Debug\Castle.exe Notice how it compiles, then generates code, then compiles (usually one or two) more files, then generates code again. Why is it doing that ? In other projects is doesn't and I can't see any difference between them, I've tried a lot of things. Thanks.
  11. Hi, Does the background move ? I'm not familiar with Direct2D. You can always just go full D3D and render quads for the 2D stuff, it will certainly be very fast. As for loading models from Blender (or any other program) you'll need a loader. It's not that hard to code an .obj loader yourself, otherwise you can probably find some code. It depends on the format your game engines uses so I would just make it myself if I were you, it basically comes down to parsing a text file (for .obj).
  12. Endemoniada

    What books should I get next? C++

    What is more important, Windows programming or your roguelike ? I would learn to get a basic skeleton D3D11 program up and running, that shouldn't be too difficult. From there I'd make a simple 2D game, like a grid-based one. After that things will start falling into place. I don't think you need any more books.
  13. Hi guys, Do you think I should render my first-person hand/weapon in world space or view space, is there a preferred method ? I got it to work in view space but now I have to do all the lighting in view space too, that's not much of a problem but I've been doing it in world space. I think I would rather do it in world space unless there is a good reason not too. I haven't been able to get that working though. Any help would be appreciated, especially getting it to work in world space. Thanks.
  14. Hi guys, The only way I can get a CCW winding order to work is to use D3D11_CULL_NONE. Take a look: // ccw triangle on x-z plane a = (-8.0f, 0.0f, -8.0f); b = ( 8.0f, 0.0f, -8.0f); c = ( 8.0f, 0.0f,  8.0f); rasterDesc.CullMode = D3D11_CULL_BACK; rasterDesc.FrontCounterClockwise = TRUE; // that doesn't work // if I swap b with c,  and set FrontCounterClockwise = FALSE it works I am really confused. Thanks.
  15. Hi guys,   I'm still not sure about what variable types to use for buffers and shaders. It's easier to explain with code:   // vertex layout   D3D11_INPUT_ELEMENT_DESC layout[] = {  { "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },  { "TEXCOORD", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0 }, };   I use a float3 for the position, should it instead be float4 ? Also, I like to use a float4 for the uv so I can use the .zw components for custom data but what if I only use the .xy components, should it then be float2 ?   The same question applies to the shader itself:   struct VS_INPUT {  float3 position : POSITION;  float4 uv : TEXCOORD0; }; Should these exactly match the layout (like they do here) ?   This has always confused me. Thanks.
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!