Esempio n. 1
0
void TessellationShader::InitShader(WCHAR* vsFilename, WCHAR* hsFilename, WCHAR* dsFilename, WCHAR* psFilename)
{
	// InitShader must be overwritten and it will load both vertex and pixel shaders + setup buffers
	InitShader(vsFilename, psFilename);

	// Load other required shaders.
	loadHullShader(hsFilename);
	loadDomainShader(dsFilename);
}
void LightAlphaMapShader::InitShader(sz::ConstBufManager &buf_man, 
  WCHAR* vsFilename, WCHAR* psFilename, 
  WCHAR *hsFilename, WCHAR *dsFilename, unsigned int lights_num) {
  D3D11_BUFFER_DESC matrixBufferDesc;
  D3D11_SAMPLER_DESC samplerDesc;
  D3D11_BUFFER_DESC lightBufferDesc;
  D3D11_BUFFER_DESC camBufferDesc;
  D3D11_INPUT_ELEMENT_DESC polygon_layout[4];

  // Create the vertex input layout description.
  // This setup needs to match the VertexType stucture in the MeshClass and in the shader.
  polygon_layout[0].SemanticName = "POSITION";
  polygon_layout[0].SemanticIndex = 0;
  polygon_layout[0].Format = DXGI_FORMAT_R32G32B32_FLOAT;
  polygon_layout[0].InputSlot = 0;
  polygon_layout[0].AlignedByteOffset = 0;
  polygon_layout[0].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  polygon_layout[0].InstanceDataStepRate = 0;

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

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

  polygon_layout[3].SemanticName = "TANGENT";
  polygon_layout[3].SemanticIndex = 0;
  polygon_layout[3].Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
  polygon_layout[3].InputSlot = 0;
  polygon_layout[3].AlignedByteOffset = D3D11_APPEND_ALIGNED_ELEMENT;
  polygon_layout[3].InputSlotClass = D3D11_INPUT_PER_VERTEX_DATA;
  polygon_layout[3].InstanceDataStepRate = 0;


  // Load (+ compile) shader files
  loadVertexShader(polygon_layout, 4, vsFilename);
  loadVertexShader(L"../shaders/tessellation_vs.hlsl", &vertexshader_tessellation);
  loadDomainShader(dsFilename);
  loadHullShader(hsFilename);
  loadPixelShader(psFilename);

  // Setup the description of the dynamic matrix constant buffer that is in the vertex shader.
  matrixBufferDesc.Usage = D3D11_USAGE_DYNAMIC;
  matrixBufferDesc.ByteWidth = sizeof(sz::MatrixBufferType);
  matrixBufferDesc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
  matrixBufferDesc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
  matrixBufferDesc.MiscFlags = 0;
  matrixBufferDesc.StructureByteStride = 0;

  // Create the constant buffer pointer so we can access the vertex shader constant buffer from within this class.
  m_matrixBuffer = buf_man.CreateD3D11ConstBuffer("mvp_buffer",
    matrixBufferDesc, m_device);
  assert(m_matrixBuffer != nullptr);

  // Create a texture sampler state description.
  samplerDesc.Filter = D3D11_FILTER_ANISOTROPIC;
  samplerDesc.AddressU = D3D11_TEXTURE_ADDRESS_MIRROR;
  samplerDesc.AddressV = D3D11_TEXTURE_ADDRESS_MIRROR;
  samplerDesc.AddressW = D3D11_TEXTURE_ADDRESS_MIRROR;
  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;

  // Create the texture sampler state.
  m_device->CreateSamplerState(&samplerDesc, &m_sampleState);

  // Create the constant buffer for materials
  D3D11_BUFFER_DESC mat_buff_desc;
  // Setup material buffer
  mat_buff_desc.Usage = D3D11_USAGE_DYNAMIC;
  mat_buff_desc.ByteWidth = sizeof(sz::MaterialBufferType);
  mat_buff_desc.BindFlags = D3D11_BIND_CONSTANT_BUFFER;
  mat_buff_desc.CPUAccessFlags = D3D11_CPU_ACCESS_WRITE;
  mat_buff_desc.MiscFlags = 0;
  mat_buff_desc.StructureByteStride = 0;
  // Create the buffer
  material_buf_ = buf_man.CreateD3D11ConstBuffer("mat_buffer",
    mat_buff_desc, m_device);
  assert(material_buf_ != nullptr);

}