달력

10

« 2017/10 »

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  •  
  •  
  •  
  •  

'3d texture'에 해당되는 글 1

  1. 2010.08.08 Solid Texture Synthesis를 위한 준비사항


비어있는 32bit 3D Texture 생성
D3D10_TEXTURE3D_DESC desc;

 desc.Width = m_nWidth;
 desc.Height = m_nHeight;
 desc.Depth = m_nDepth;
 desc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
 desc.MipLevels = 1;
 desc.Format=DXGI_FORMAT_R8G8B8A8_UNORM;
 desc.Usage = D3D10_USAGE_DYNAMIC;
 desc.CPUAccessFlags = D3D10_CPU_ACCESS_WRITE;
 desc.MiscFlags = 0;

 hr = m_pDevice->CreateTexture3D(&desc, NULL, &m_p3DSolidTexture);
 if (FAILED(hr))
  return FALSE;

 
 hr = m_pDevice->CreateShaderResourceView(m_p3DSolidTexture, NULL, &m_p3DSolidTextureRV);
 if (FAILED(hr))
  return FALSE;


3D texture에 내용 채우기

RGB32 * buffer;
 
  int nWidth = m_pVolume->GetWidth();
  int nHeight = m_pVolume->GetHeight();
  int nDepth = m_pVolume->GetDepth();
 
  buffer=new RGB32[nWidth*nHeight*nDepth];
 
  int z,x,y;
  for (z = 0 ; z < nDepth; z++)
  {
   for (y = 0 ; y < nHeight; y++)
   {
    for (x = 0; x < nWidth; x++)
    {
     buffer[z*nHeight*nWidth + y*nWidth + x].r = rand() % 255;
    buffer[z*nHeight*nWidth + y*nWidth + x].g = rand() % 255;
    buffer[z*nHeight*nWidth + y*nWidth + x].b = rand() % 255;
    buffer[z*nHeight*nWidth + y*nWidth + x].a = 1;

    }
   }
  }
 
 
  ID3D10Texture3D *solidVolume = m_pVolume->Get3DSolidTexture();
 
  D3D10_MAPPED_TEXTURE3D mapped;
  hr = solidVolume->Map(0, D3D10_MAP_WRITE_DISCARD, 0, &mapped);
  if (FAILED(hr))
   return FALSE;
 
  memcpy(reinterpret_cast<RGB32 * >(mapped.pData), buffer, nWidth*nHeight*nDepth*sizeof(RGB32));
  solidVolume->Unmap(0);
 
 
  free(buffer);

 

저작자 표시
신고
Posted by 에어림