0

私は、一連の 2D 画像をすべて同じサイズで生データとしてフォーマットし、3D テクスチャにロードしてから、その 3D テクスチャを画面にレンダリングしようとしました。私はまだ DirectX に慣れていないので、何が間違っているのかわかりません。関連するコードは次のとおりです。

// Open the image and copy its contents into a buffer

std::ifstream image("head256x256x109", std::ifstream::binary);

int size;
char* buffer;
if (image.is_open()) {
  image.seekg(0, image.end);
  size = image.tellg();
  image.seekg(0, image.beg);
  buffer = new char[size];
  image.read(buffer, size);
  image.close();
} else {
  return false;
}

// Convert the data to RGBA data
// Here we are simply putting the same value to R, G, B and A channels.

char* RGBABuffer = new char[ size*4 ];
for( int nIndx = 0; nIndx < size; ++nIndx )
{
    RGBABuffer[nIndx*4] = buffer[nIndx];
    RGBABuffer[nIndx*4+1] = buffer[nIndx];
    RGBABuffer[nIndx*4+2] = buffer[nIndx];
    RGBABuffer[nIndx*4+3] = buffer[nIndx];
}

// Create the texture

D3D11_TEXTURE3D_DESC texture_desc;
ZeroMemory(&texture_desc, sizeof(texture_desc));
texture_desc.Width = 256;
texture_desc.Height = 256;
texture_desc.Depth = 109;
texture_desc.MipLevels = 1;
texture_desc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texture_desc.Usage = D3D11_USAGE_DEFAULT;
texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE;

D3D11_SUBRESOURCE_DATA image_data;
ZeroMemory(&image_data, sizeof(image_data));
image_data.pSysMem = RGBABuffer;
image_data.SysMemPitch = 256 * 4;
image_data.SysMemSlicePitch = 256 * 256 * 4;

d3dResult = d3dDevice_->CreateTexture3D(&texture_desc, &image_data, &texture_);

// Create a sampler

D3D11_SAMPLER_DESC colorMapDesc;
ZeroMemory( &colorMapDesc, sizeof( colorMapDesc ) );
colorMapDesc.AddressU = D3D11_TEXTURE_ADDRESS_WRAP;
colorMapDesc.AddressV = D3D11_TEXTURE_ADDRESS_WRAP;
colorMapDesc.AddressW = D3D11_TEXTURE_ADDRESS_WRAP;
colorMapDesc.ComparisonFunc = D3D11_COMPARISON_NEVER;
colorMapDesc.Filter = D3D11_FILTER_MIN_MAG_MIP_LINEAR;
colorMapDesc.MaxLOD = D3D11_FLOAT32_MAX;

d3dResult = d3dDevice_->CreateSamplerState( &colorMapDesc, &colorMapSampler_ );

シェーダー コードは可能な限り単純です。

Texture3D colorMap_ : register( t0 );
SamplerState colorSampler_ : register( s0 );

struct VS_Input
{
  float4 pos  : POSITION;
  float4 tex0 : TEXCOORD0;
};

struct PS_Input
{
  float4 pos  : SV_POSITION;
  float4 tex0 : TEXCOORD0;
};

PS_Input VS_Main( VS_Input vertex )
{
  PS_Input vsOut = ( PS_Input )0;
  vsOut.pos = vertex.pos;
  vsOut.tex0 = vertex.tex0;

  return vsOut;
}

float4 PS_Main( PS_Input frag ) : SV_TARGET
{
  return colorMap_.Sample( colorSampler_, frag.tex0 );
}

これが適切に機能するためには、ある種のアルファ ブレンディングを実装する必要があることはわかっていますが、少なくともこれで示されている画像の最初のスライスを取得したいと考えていました。ただし、取得できるのは、Render 関数で設定した背景色だけです。

float clearColor[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
d3dContext_->ClearRenderTargetView( backBufferTarget_, clearColor );

私が間違っている可能性があることについてのヘルプと、この目標を達成するために必要なその他のヒント (一連の画像から 3D テクスチャを作成して画面にレンダリングする) は、非常に役立ちます。これに関するウェブ上のドキュメントはほとんどありません。

4

0 に答える 0