| 129 | } |
| 130 | |
| 131 | void GLTF_PBR_Renderer::InitMaterialSRB(GLTF::Model& Model, |
| 132 | GLTF::Material& Material, |
| 133 | IBuffer* pFrameAttribs, |
| 134 | IShaderResourceBinding* pMaterialSRB) |
| 135 | { |
| 136 | if (pMaterialSRB == nullptr) |
| 137 | { |
| 138 | LOG_ERROR_MESSAGE("Failed to create material SRB"); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | InitCommonSRBVars(pMaterialSRB, pFrameAttribs); |
| 143 | |
| 144 | auto SetTexture = [&](TEXTURE_ATTRIB_ID ID, ITextureView* pDefaultTexSRV) // |
| 145 | { |
| 146 | const int TexAttribId = m_Settings.TextureAttribIndices[ID]; |
| 147 | if (TexAttribId < 0) |
| 148 | { |
| 149 | UNEXPECTED("Texture attribute is not initialized"); |
| 150 | return; |
| 151 | } |
| 152 | |
| 153 | RefCntAutoPtr<ITextureView> pTexSRV; |
| 154 | |
| 155 | auto TexIdx = Material.GetTextureId(TexAttribId); |
| 156 | if (TexIdx >= 0) |
| 157 | { |
| 158 | if (auto* pTexture = Model.GetTexture(TexIdx)) |
| 159 | { |
| 160 | if (pTexture->GetDesc().Type == RESOURCE_DIM_TEX_2D_ARRAY) |
| 161 | pTexSRV = pTexture->GetDefaultView(TEXTURE_VIEW_SHADER_RESOURCE); |
| 162 | else |
| 163 | { |
| 164 | TextureViewDesc SRVDesc; |
| 165 | SRVDesc.ViewType = TEXTURE_VIEW_SHADER_RESOURCE; |
| 166 | SRVDesc.TextureDim = RESOURCE_DIM_TEX_2D_ARRAY; |
| 167 | pTexture->CreateView(SRVDesc, &pTexSRV); |
| 168 | } |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | if (pTexSRV == nullptr) |
| 173 | pTexSRV = pDefaultTexSRV; |
| 174 | |
| 175 | this->SetMaterialTexture(pMaterialSRB, pTexSRV, ID); |
| 176 | }; |
| 177 | |
| 178 | SetTexture(TEXTURE_ATTRIB_ID_BASE_COLOR, m_pWhiteTexSRV); |
| 179 | SetTexture(TEXTURE_ATTRIB_ID_PHYS_DESC, m_pDefaultPhysDescSRV); |
| 180 | SetTexture(TEXTURE_ATTRIB_ID_NORMAL, m_pDefaultNormalMapSRV); |
| 181 | |
| 182 | if (m_Settings.EnableAO) |
| 183 | { |
| 184 | SetTexture(TEXTURE_ATTRIB_ID_OCCLUSION, m_pWhiteTexSRV); |
| 185 | } |
| 186 | |
| 187 | if (m_Settings.EnableEmissive) |
| 188 | { |
nothing calls this directly
no test coverage detected