Jump to content
  • Advertisement

Alriightyman

Member
  • Content Count

    9
  • Joined

  • Last visited

Community Reputation

140 Neutral

About Alriightyman

  • Rank
    Newbie
  1. Alriightyman

    Constant Buffer matrix array not updating.

    I know what is wrong.  It's not that the values are wrong, they are just too small.  That really HUGE negative number is just a very, very small number that fills the 32-bit value that it becomes a larger value. I'll have to check values when I am exporting my model data so that it doesn't have this problem.  I'm sure the data types are double being down graded to floats.  Thanks for the help.   Also, Buckeye, I read your following the data, it is more or less what I do until I get completely stumped.  Then, I get annoyed and start trying anything.  It's a good read though, thanks.  Also, I hate asking questions.  I usually try as much as I can by myself and ask questions when my brain is shot. 
  2. Alriightyman

    Constant Buffer matrix array not updating.

      Yes, I transpose them before I copy them.   Yes it does, but I have set it to a much smaller number and still get the same result.   Yes, and no.  I have tried both. Same results.  And set the correct slot as well.       That's nothing, we had 256 just in our heads!      96 turns up a lot, probably because it is the number of bones supported in the shader from the chapter on skeletal animation in Luna's DX11 book.   I have two test models.  One with just a few bones, and the other has somewhere are 72 bones I think. But ericrichards22 is right, I sort of got the information from Luna's book. Although, I don't use .fx shaders.   I don't mean that the right values are in the wrong places, I am missing all the right values and have really large numbers in the matrix. For example, here is the first input matrix: [0] = 0x0098f4a8 {2.22045002e-016, -1.00000000, 0.000000000, 0.549629986} [1] = 0x0098f4b8 {1.00000000, 2.22045002e-016, 0.000000000, 386.503998} [2] = 0x0098f4c8 {0.000000000, -1.54074001e-033, -1.00000000, 0.000000000} [3] = 0x0098f4d8 {0.000000000, 0.000000000, 0.000000000, 1.00000000} Here is the first 64 bytes of the buffer 0 [0x00000000-0x00000003] | +2.22045e-016 1 [0x00000004-0x00000007] | -1 2 [0x00000008-0x0000000b] | +0 3 [0x0000000c-0x0000000f] | +0.54962999 4 [0x00000010-0x00000013] | +1 5 [0x00000014-0x00000017] | +2.22045e-016 6 [0x00000018-0x0000001b] | +0 7 [0x0000001c-0x0000001f] | +386.504 8 [0x00000020-0x00000023] | +0 9 [0x00000024-0x00000027] | -1.54074e-033 10 [0x00000028-0x0000002b] | -1 11 [0x0000002c-0x0000002f] | +0 12 [0x00000030-0x00000033] | +0 13 [0x00000034-0x00000037] | +0 14 [0x00000038-0x0000003b] | +0 15 [0x0000003c-0x0000003f] | +1 So far so good, but here is the buffer while debugging the vertex shader: BoneTransforms[0][0] = x = 0.000000000, y = -1.000000000, z = 0.000000000, w = NaN BoneTransforms[0][1] = x = 1.000000000, y = 0.000000000, z = 0.000000000, w = NaN BoneTransforms[0][2] = x = 0.000000000, y = -1996489000.000000000, z = -1.000000000, w = NaN BoneTransforms[0][3] = x = NaN, y = NaN, z = NaN, w = NaN It doesn't make sense to me.  especially (0,2).y = -1996489000.0???
  3. I have a constant buffer in my vertex shader defined as shown: cbuffer SkinnedBuffer { float4x4 BoneTransforms[96]; }; In my app I copy all the transforms matrices to my structure defined in c++ similarly to the above.  I call the map/unmap functions and use memcpy in between to copy the data to the buffer.    Now, the data in the buffer has the copied values, and checking the buffer in memory, via Visual Studio gpu debugger, all the data is there.  However, upon debugging the BoneTranforms array in the shader, the values are not even remotely correct.   I found elsewhere that the constant buffers need to be aligned appropriately. It states the a float4 occupies 1 register, so if I am using a float4x4, then that would be using 4 registers. I found example that help with correctly working with float arrays, but nothing with float4x4 arrays.  So is there another way of defining the array above?  Or am I missing something?   Please note, I am a bit new to shaders and I am not using Effects11.
  4. Alriightyman

    Problem with shader; vertex Input is wrong.

    It was the stride. That's what I was missing.  I set the vertex buffer somewhere else in my code, and didn't even notice I hadn't changed the stride to reflect the skinned vertex.     I took a class for debugging.  Most of the information taught were things I had learn myself.    Thanks for the help, now I can try to implement skinned meshes! Wish me luck!
  5. Alriightyman

    Problem with shader; vertex Input is wrong.

    All data within vertex data struct is assigned a value; I have checked.  The input to the vertex shader is wrong.  I HAVE been debugging, and I have been stuck on this for some time.  I'm not new to programming; I am a semester away from my BS in Computer Science.  I haven't really debugged graphics before, and am still new to shaders.   Also, it's not just the blendindices that are incorrect, I'm sorry if I made it seem that those were the only problem.  The first vertex is correct.  After that, they are all offset incorrectly. Here is the first vertex of the first triangle.  The input is correct according to the vertex buffer and the the c++ vertex structure. position = x = -10.000000000, y = 10.000000000, z = -10.000000000, w = NaN weights = x = 0.500000000, y = 0.500000000, z = 0.000000000 tex = x = 0.375000000, y = 0.750000000 normal = x = 0.000000000, y = 0.000000000, z = -1.000000000 tangent = x = 1.000000000, y = 0.000000000, z = 0.000000000 binormal = x = 0.000000000, y = 1.000000000, z = 0.000000000 Now, this is the second vertex of the same traingle. position = x = 0.000000000, y = 1.000000000, z = 0.000000000, w = NaN weights = x = 10.000000000, y = -10.00000000, z = -10.000000000 tex = x = 0.821455000, y = 0.178545000 normal = x = 0.000000000, y = 0.625000000, z = 1.000000000 tangent = x = 0.000000000, y = 0.000000000, z = -1.000000000 binormal = x = 1.000000000, y = 0.000000000, z = 0.000000000 The problem here is that position should be what is shown for the weights, weights should be what tex is and the x value of normal, ect..  It looks as if the input position copied the values from binormal of the last vertex. And that is what is stumped me.   Oddly, if I leave the shader alone, semantics alone, and change the vertex structure to not include blendweights or blendindices, my cube loads just fine.
  6. Alriightyman

    Problem with shader; vertex Input is wrong.

    Yes, I get a different order. Here are my layout inputs: D3D11_INPUT_ELEMENT_DESC polygonLayout[7] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, D3D11_APPEND_ALIGNED_ELEMENT, D3D11_INPUT_PER_VERTEX_DATA, 0} }; Or this way: D3D11_INPUT_ELEMENT_DESC polygonLayout[7] = { {"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 12, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 20, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"TANGENT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 32, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BINORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 44, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BLENDWEIGHT", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 56, D3D11_INPUT_PER_VERTEX_DATA, 0}, {"BLENDINDICES", 0, DXGI_FORMAT_R8G8B8A8_UINT, 0, 68, D3D11_INPUT_PER_VERTEX_DATA, 0} }; Here's the other layout like before:   https://www.dropbox.com/s/efrmx6wlge3uwh0/input2.PNG?dl=0   I am using Visual Studio 2012's Graphics Debugger. Yes, see above.   They are set in the model file I created.  It's a text file, so I can look up the data.   This is what get Rendered, I rotated it and zoomed in a bit. https://www.dropbox.com/s/xdxw690o7u4uj1g/ingame.PNG?dl=0
  7. Alriightyman

    Problem with shader; vertex Input is wrong.

    https://www.dropbox.com/s/ij91graql0f0x2g/Input.PNG?dl=0 Here, in the debugger. As you can see, in vertex 22, BLENDINDICES's fourth value is 65, and I only have 2 bones.  It is supposed to be zero. But here it is setup right: https://www.dropbox.com/s/l38bxclrolakbml/inputlayout.PNG?dl=0 Here is my vertex buffer, if it helps. https://www.dropbox.com/s/b606cgmp6b9mm7r/vertexBuffer.PNG?dl=0
  8. Alriightyman

    Problem with shader; vertex Input is wrong.

    Thanks, but no change.  I have changed those offsets a lot, manually and with D3D11_APPEND_ALIGNED_ELEMENT.  If I use D3D11_APPEND_ALIGNED_ELEMENT though,  when debugging the graphics, it seems that the input layout is reversed for some reason.  BLENDINDICES are now at the top, and POSITION is at the bottom.
  9. I seem to have an issue with my shader code.  I an trying to work with animated skeleton meshes, and ran into trouble, so I changed my shader vertex function to work like my normal shader just with the original inputs. My simple cube is displaying completely wrong.   Here is my vertex shader: cbuffer MatrixBuffer { matrix world; matrix view; matrix projection; }; cbuffer SkinnedBuffer { float4x4 BoneTransforms[96]; }; struct VertexInput { float3 position : POSITION; float2 tex : TEXCOORD0; float3 normal : NORMAL; float3 tangent : TANGENT; float3 binormal : BINORMAL; float3 weights : BLENDWEIGHT; uint4 boneIndices : BLENDINDICES; }; struct VertexOutput { float4 position : SV_POSITION; float2 tex : TEXCOORD0; float3 normal : NORMAL; float3 tangent : TANGENT; float3 binormal : BINORMAL; }; VertexOutput main( VertexInput input ) { VertexOutput output; float4 pos = float4(input.position.xyz,1.0f); output.position = mul(pos,world); output.position = mul(output.position,view); output.position = mul(output.position,projection); // store the tex coords output.tex = input.tex; // calculate the normal vector against the world matrix only and then normalize the final value output.normal = mul(input.normal,(float3x3)world); output.normal = normalize(output.normal); // calculate the tangents output.tangent = mul(input.tangent,(float3x3)world); output.tangent = normalize(output.tangent); // calculate the binormals output.binormal = mul(input.binormal,(float3x3)world); output.binormal = normalize(output.binormal); return output; } And here is the shader Initialization funciton: struct ShaderBuffer         {             unsigned int Size;             void* Buffer;             ShaderBuffer() { Size = 0; Buffer = 0; }         };         ShaderBuffer vertexShaderBuffer, pixelShaderBuffer;         //         D3D11_INPUT_ELEMENT_DESC polygonLayout[7] =    {             {"POSITION",     0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0,  D3D11_INPUT_PER_VERTEX_DATA, 0},             {"TEXCOORD",     0, DXGI_FORMAT_R32G32_FLOAT,    0, 16, D3D11_INPUT_PER_VERTEX_DATA, 0},             {"NORMAL",       0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0},             {"TANGENT",      0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0},             {"BINORMAL",     0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 48, D3D11_INPUT_PER_VERTEX_DATA, 0},             {"BLENDWEIGHT",      0, DXGI_FORMAT_R32G32B32_FLOAT,0, 60, D3D11_INPUT_PER_VERTEX_DATA, 0},             {"BLENDINDICES",  0, DXGI_FORMAT_R8G8B8A8_UINT, 0,  72, D3D11_INPUT_PER_VERTEX_DATA, 0}         };         unsigned int numElements;         D3D11_SAMPLER_DESC samplerDesc;         ID3D11Device* device = graphics->GetDevice();         vertexShaderBuffer.Buffer = LoadCompiledShader(vsfilename,vertexShaderBuffer.Size);         pixelShaderBuffer.Buffer = LoadCompiledShader(psfilename,pixelShaderBuffer.Size);         if(FAILED(device->CreateVertexShader(vertexShaderBuffer.Buffer,vertexShaderBuffer.Size,0,&m_vertexShader)))             return false;         if(FAILED(device->CreatePixelShader(pixelShaderBuffer.Buffer,pixelShaderBuffer.Size,0,&m_pixelShader)))             return false;         //         numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);         // create the vertex input layout         if(FAILED(device->CreateInputLayout(polygonLayout,numElements, vertexShaderBuffer.Buffer, vertexShaderBuffer.Size, &m_layout)))             return false;         delete [] vertexShaderBuffer.Buffer;         delete [] pixelShaderBuffer.Buffer;         m_matrixBuffer.Initialize(device);         m_lightBuffer.Initialize(device);         m_skinnedBuffer.Initialize(device);         // Create a texture sampler state description.         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;         samplerDesc.BorderColor[1] = 0;         samplerDesc.BorderColor[2] = 0;         samplerDesc.BorderColor[3] = 0;         samplerDesc.MinLOD = 0;         samplerDesc.MaxLOD = D3D11_FLOAT32_MAX;         if(FAILED(device->CreateSamplerState(&samplerDesc,&m_samplerState)))             return false;         return true; I think it is an alignment problem.  When I debug it in visual studio 2012 and check the vertex shader input, the values are waaaay off. Let me know if there is something I am missing here...   Thanks   EDIT:  Also, my buffer initialization code looks like this: // Make the constant buffer D3D11_BUFFER_DESC desc; desc.Usage = D3D11_USAGE_DYNAMIC; desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER; desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE; desc.MiscFlags = 0; desc.ByteWidth = sizeof(T); desc.StructureByteStride = 0; device->CreateBuffer(&desc,0,&m_Buffer); Edit2: My Vertex Structure struct SkinnedVertex { DirectX::XMFLOAT3 position; DirectX::XMFLOAT2 texture; DirectX::XMFLOAT3 normal; DirectX::XMFLOAT3 tangent; DirectX::XMFLOAT3 binormal; DirectX::XMFLOAT3 weights; unsigned char boneIndices[4]; };
  • Advertisement
×

Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!