0
\$\begingroup\$

i want to read bone's weight but shader can't read data

this is my vertex type

struct SkinnedMesh
{

XMFLOAT3 Position;
XMFLOAT2 Texture;
XMFLOAT3 Normal;
XMFLOAT3 Weight;
UINT BoneIndices[4];
};

this is initialize shader code

ID3D10Blob* vertexShaderBuffer;
ID3D10Blob* pixelShaderBuffer;
D3D11_INPUT_ELEMENT_DESC polygonLayout[5];
unsigned int numElements;
DWORD ShaderFlag = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG | D3DCOMPILE_SKIP_OPTIMIZATION;

// Initialize the pointers this function will use to null.
vertexShaderBuffer = nullptr;
pixelShaderBuffer = nullptr;

// Initialize the pointers this function will use to null.
vertexShaderBuffer = nullptr;
pixelShaderBuffer = nullptr;

// Compile the vertex shader code.
if (FAILED(D3DCompileFromFile(_VSPath.c_str(), NULL, NULL, "main", "vs_4_0", ShaderFlag, 0, &vertexShaderBuffer, NULL)))
{
    MSG_BOX("Failed to compile vertex shader.");
    return E_FAIL;
}

// Compile the pixel shader code.
if (FAILED(D3DCompileFromFile(_PSPath.c_str(), NULL, NULL, "main", "ps_4_0", D3D10_SHADER_ENABLE_STRICTNESS, 0, &pixelShaderBuffer, NULL)))
{
    MSG_BOX("Failed to compile pixel shader.");
    return E_FAIL;
}

// Create the vertex shader from the buffer.
if (FAILED(_Device->CreateVertexShader(vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), NULL, VertexShader.GetAddressOf())))
{
    MSG_BOX("Failed to create vertex shader from buffer.");
    return E_FAIL;
}

// Create the pixel shader from the buffer.
if (FAILED(_Device->CreatePixelShader(pixelShaderBuffer->GetBufferPointer(), pixelShaderBuffer->GetBufferSize(), NULL, PixelShader.GetAddressOf())))
{
    MSG_BOX("Failed to create pixel shader from buffer.");
    return E_FAIL;
}

// Create the vertex input layout description.
polygonLayout[0].SemanticName = "POSITION";
polygonLayout[0].SemanticIndex = 0;
polygonLayout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[0].InputSlot = 0;
polygonLayout[0].AlignedByteOffset = 0;
polygonLayout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[0].InstanceDataStepRate = 0;

polygonLayout[1].SemanticName = "TEXCOORD";
polygonLayout[1].SemanticIndex = 0;
polygonLayout[1].Format = DXGI_FORMAT_R32G32_FLOAT;
polygonLayout[1].InputSlot = 0;
polygonLayout[1].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[1].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[1].InstanceDataStepRate = 0;

polygonLayout[2].SemanticName = "NORMAL";
polygonLayout[2].SemanticIndex = 0;
polygonLayout[2].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[2].InputSlot = 0;
polygonLayout[2].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[2].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[2].InstanceDataStepRate = 0;

polygonLayout[3].SemanticName = "BLENDWEIGHT";
polygonLayout[3].SemanticIndex = 0;
polygonLayout[3].Format = DXGI_FORMAT_R32G32B32_FLOAT;
polygonLayout[3].InputSlot = 0;
polygonLayout[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[3].InstanceDataStepRate = 0;

polygonLayout[4].SemanticName = "BLENDINDICES";
polygonLayout[4].SemanticIndex = 0;
polygonLayout[4].Format = DXGI_FORMAT_R32G32B32A32_UINT;
polygonLayout[4].InputSlot = 0;
polygonLayout[4].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
polygonLayout[4].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
polygonLayout[4].InstanceDataStepRate = 0;

numElements = sizeof(polygonLayout) / sizeof(polygonLayout[0]);

// Create the vertex input layout.8
if (FAILED(_Device->CreateInputLayout(polygonLayout, numElements, vertexShaderBuffer->GetBufferPointer(), vertexShaderBuffer->GetBufferSize(), &Layout)))
{
    MSG_BOX("Failed to create vertex input layout.");
    return E_FAIL;
}

// Release the vertex shader buffer and pixel shader buffer since they are no longer needed.
vertexShaderBuffer->Release();
vertexShaderBuffer = nullptr;

pixelShaderBuffer->Release();
pixelShaderBuffer = nullptr;

// 텍스처 샘플러 생태 구조체 생성 및 설정
D3D11_SAMPLER_DESC samplerDecs;
samplerDecs.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR; // 텍스쳐를 어떻게 처리 할 것인지
samplerDecs.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;  // UV좌표 0~1 사이에 모든 이미지가 오게 설정
samplerDecs.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;  // UV좌표 0~1 사이에 모든 이미지가 오게 설정
samplerDecs.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;  // UV좌표 0~1 사이에 모든 이미지가 오게 설정
samplerDecs.MipLODBias = 0.f;                         // 아래부터 그냥 Default
samplerDecs.MaxAnisotropy = 1;
samplerDecs.ComparisonFunc = D3D11_COMPARISON_ALWAYS;
samplerDecs.BorderColor[0] = 0;
samplerDecs.BorderColor[1] = 0;
samplerDecs.BorderColor[2] = 0;
samplerDecs.BorderColor[3] = 0;
samplerDecs.MinLOD = 0;
samplerDecs.MaxLOD = D3D11_FLOAT32_MAX;

if (FAILED(_Device->CreateSamplerState(&samplerDecs, 
 &SampleState)))
{
    MSG_BOX("Failed to create SamplerState.");
    return E_FAIL;
}
return S_OK;

this is hlsl code

cbuffer MatrixBuffer : register(b0)
{
    matrix WorldMatrix;
    matrix ViewMatrix;
    matrix ProjectionMatrix;

}
struct SkinnedInput
{
    float4 Position : POSITION;
    float2 Tex : TEXCOORD;
    float3 Normal : NORMAL;
    float3 Weights : BLENDWEIGHT;
    uint4 BoneIndices : BLENDINDICES;
};

struct SkinnedOutput
{
    float4 Position : SV_POSITION;
    float2 Tex : TEXCOORD0;
    float3 Normal : NORMAL;
};

SkinnedOutput main(SkinnedInput _Input)
{
    SkinnedOutput Out = (SkinnedOutput) 0;

    Out.Position = mul(_Input.Position, WorldMatrix);
    Out.Position = mul(Out.Position, ViewMatrix);
    Out.Position = mul(Out.Position, ProjectionMatrix);

    Out.Tex = _Input.Tex;

    Out.Normal = normalize(mul(float4(_Input.Normal, 0.f), WorldMatrix));

    
    return Out;

}

when i debug hlsl, there is no data in weights and boneindices like this

enter image description here

Anyone know about this?

\$\endgroup\$
2
  • \$\begingroup\$ Does this answer your question? I have problem in input element for shader \$\endgroup\$
    – user35344
    Commented Oct 3, 2021 at 14:58
  • \$\begingroup\$ This appears to be quite similar to your previous question. Are you still struggling with the same issue? If so, please edit your existing question, and do not post multiple questions about solving the same issue. \$\endgroup\$
    – DMGregory
    Commented Oct 3, 2021 at 14:58

0

You must log in to answer this question.

Browse other questions tagged .