11/*
2- * Copyright 2019-2024 Diligent Graphics LLC
2+ * Copyright 2019-2025 Diligent Graphics LLC
33 * Copyright 2015-2019 Egor Yusov
44 *
55 * Licensed under the Apache License, Version 2.0 (the "License");
@@ -245,7 +245,7 @@ class RingMeshBuilder
245245 enum QUAD_TRIANGULATION_TYPE QuadTriangType)
246246 {
247247 m_RingMeshes.push_back (RingSectorMesh ());
248- auto & CurrMesh = m_RingMeshes.back ();
248+ RingSectorMesh & CurrMesh = m_RingMeshes.back ();
249249
250250 std::vector<Uint32> IB;
251251 StdTriStrip32 TriStrip (IB, StdIndexGenerator (m_iGridDimenion));
@@ -267,12 +267,12 @@ class RingMeshBuilder
267267 VERIFY (CurrMesh.pIndBuff , " Failed to create index buffer" );
268268
269269 // Compute bounding box
270- auto & BB = CurrMesh.BndBox ;
271- BB.Max = float3 (-FLT_MAX, -FLT_MAX, -FLT_MAX);
272- BB.Min = float3 (+FLT_MAX, +FLT_MAX, +FLT_MAX);
270+ BoundBox & BB{ CurrMesh.BndBox } ;
271+ BB.Max = float3 (-FLT_MAX, -FLT_MAX, -FLT_MAX);
272+ BB.Min = float3 (+FLT_MAX, +FLT_MAX, +FLT_MAX);
273273 for (auto Ind = IB.begin (); Ind != IB.end (); ++Ind)
274274 {
275- const auto & CurrVert = m_VB[*Ind].f3WorldPos ;
275+ const float3 & CurrVert = m_VB[*Ind].f3WorldPos ;
276276
277277 BB.Min = std::min (BB.Min , CurrVert);
278278 BB.Max = std::max (BB.Max , CurrVert);
@@ -320,8 +320,8 @@ void GenerateSphereGeometry(IRenderDevice* pDevice,
320320 for (int iRow = 0 ; iRow < iGridDimension; ++iRow)
321321 for (int iCol = 0 ; iCol < iGridDimension; ++iCol)
322322 {
323- auto & CurrVert = VB[iCurrGridStart + iCol + iRow * iGridDimension];
324- auto & f3Pos = CurrVert.f3WorldPos ;
323+ HemisphereVertex & CurrVert = VB[iCurrGridStart + iCol + iRow * iGridDimension];
324+ float3& f3Pos = CurrVert.f3WorldPos ;
325325
326326 f3Pos.x = static_cast <float >(iCol) / static_cast <float >(iGridDimension - 1 );
327327 f3Pos.z = static_cast <float >(iRow) / static_cast <float >(iGridDimension - 1 );
@@ -360,19 +360,19 @@ void GenerateSphereGeometry(IRenderDevice* pDevice,
360360 // Top & bottom boundaries
361361 for (int iRow = 0 ; iRow < iGridDimension; iRow += iGridDimension - 1 )
362362 {
363- const auto & V0 = VB[iCurrGridStart + i - 1 + iRow * iGridDimension].f3WorldPos ;
364- auto & V1 = VB[iCurrGridStart + i + 0 + iRow * iGridDimension].f3WorldPos ;
365- const auto & V2 = VB[iCurrGridStart + i + 1 + iRow * iGridDimension].f3WorldPos ;
366- V1 = (V0 + V2) / 2 .f ;
363+ const float3 & V0 = VB[iCurrGridStart + i - 1 + iRow * iGridDimension].f3WorldPos ;
364+ float3 & V1 = VB[iCurrGridStart + i + 0 + iRow * iGridDimension].f3WorldPos ;
365+ const float3 & V2 = VB[iCurrGridStart + i + 1 + iRow * iGridDimension].f3WorldPos ;
366+ V1 = (V0 + V2) / 2 .f ;
367367 }
368368
369369 // Left & right boundaries
370370 for (int iCol = 0 ; iCol < iGridDimension; iCol += iGridDimension - 1 )
371371 {
372- const auto & V0 = VB[iCurrGridStart + iCol + (i - 1 ) * iGridDimension].f3WorldPos ;
373- auto & V1 = VB[iCurrGridStart + iCol + (i + 0 ) * iGridDimension].f3WorldPos ;
374- const auto & V2 = VB[iCurrGridStart + iCol + (i + 1 ) * iGridDimension].f3WorldPos ;
375- V1 = (V0 + V2) / 2 .f ;
372+ const float3 & V0 = VB[iCurrGridStart + iCol + (i - 1 ) * iGridDimension].f3WorldPos ;
373+ float3 & V1 = VB[iCurrGridStart + iCol + (i + 0 ) * iGridDimension].f3WorldPos ;
374+ const float3 & V2 = VB[iCurrGridStart + iCol + (i + 1 ) * iGridDimension].f3WorldPos ;
375+ V1 = (V0 + V2) / 2 .f ;
376376 }
377377 }
378378 }
@@ -411,84 +411,6 @@ void GenerateSphereGeometry(IRenderDevice* pDevice,
411411 // clang-format on
412412 }
413413 }
414-
415- // We do not need per-vertex normals as we use normal map to shade terrain
416- // Sphere tangent vertex are computed in the shader
417- #if 0
418- // Compute normals
419- const float3 *pV0 = nullptr;
420- const float3 *pV1 = &VB[ IB[0] ].f3WorldPos;
421- const float3 *pV2 = &VB[ IB[1] ].f3WorldPos;
422- float fSign = +1;
423- for(Uint32 Ind=2; Ind < m_uiIndicesInIndBuff; ++Ind)
424- {
425- fSign = -fSign;
426- pV0 = pV1;
427- pV1 = pV2;
428- pV2 = &VB[ IB[Ind] ].f3WorldPos;
429- float3 Rib0 = *pV0 - *pV1;
430- float3 Rib1 = *pV1 - *pV2;
431- float3 TriN;
432- D3DXVec3Cross(&TriN, &Rib0, &Rib1);
433- float fLength = D3DXVec3Length(&TriN);
434- if( fLength > 0.1 )
435- {
436- TriN /= fLength*fSign;
437- for(int i=-2; i <= 0; ++i)
438- VB[ IB[Ind+i] ].f3Normal += TriN;
439- }
440- }
441- for(auto VBIt=VB.begin(); VBIt != VB.end(); ++VBIt)
442- {
443- float fLength = D3DXVec3Length(&VBIt->f3Normal);
444- if( fLength > 1 )
445- VBIt->f3Normal /= fLength;
446- }
447-
448- // Adjust normals on boundaries
449- for(int iRing = iStartRing; iRing < iNumRings-1; ++iRing)
450- {
451- int iCurrGridStart = (iRing-iStartRing) * iGridDimension*iGridDimension;
452- int iNextGridStart = (iRing-iStartRing+1) * iGridDimension*iGridDimension;
453- for(int i=0; i < iGridDimension; i+=2)
454- {
455- for(int Bnd=0; Bnd < 2; ++Bnd)
456- {
457- const int CurrGridOffsets[] = {0, iGridDimension-1};
458- const int NextGridPffsets[] = {iGridQuart, iGridQuart*3};
459- // Left and right boundaries
460- {
461- auto &CurrGridN = VB[iCurrGridStart + CurrGridOffsets[Bnd] + i*iGridDimension].f3Normal;
462- auto &NextGridN = VB[iNextGridStart + NextGridPffsets[Bnd] + (iGridQuart+i/2)*iGridDimension].f3Normal;
463- auto NewN = CurrGridN + NextGridN;
464- D3DXVec3Normalize(&NewN, &NewN);
465- CurrGridN = NextGridN = NewN;
466- if( i > 1 )
467- {
468- auto &PrevCurrGridN = VB[iCurrGridStart + CurrGridOffsets[Bnd] + (i-2)*iGridDimension].f3Normal;
469- auto MiddleN = PrevCurrGridN + NewN;
470- D3DXVec3Normalize( &VB[iCurrGridStart + CurrGridOffsets[Bnd] + (i-1)*iGridDimension].f3Normal, &MiddleN);
471- }
472- }
473-
474- // Bottom and top boundaries
475- {
476- auto &CurrGridN = VB[iCurrGridStart + i + CurrGridOffsets[Bnd]*iGridDimension].f3Normal;
477- auto &NextGridN = VB[iNextGridStart + (iGridQuart+i/2) + NextGridPffsets[Bnd]*iGridDimension].f3Normal;
478- auto NewN = CurrGridN + NextGridN;
479- D3DXVec3Normalize(&NewN, &NewN);
480- CurrGridN = NextGridN = NewN;
481- if( i > 1 )
482- {
483- auto &PrevCurrGridN = VB[iCurrGridStart + (i-2) + CurrGridOffsets[Bnd]*iGridDimension].f3Normal;
484- auto MiddleN = PrevCurrGridN + NewN;
485- D3DXVec3Normalize( &VB[iCurrGridStart + (i-1) + CurrGridOffsets[Bnd]*iGridDimension].f3Normal, &MiddleN);
486- }
487- }
488- }
489- }
490- }
491- #endif
492414}
493415
494416
@@ -530,7 +452,7 @@ void EarthHemsiphere::RenderNormalMap(IRenderDevice* pDevice,
530452 size_t CurrMipStride = iHeightMapDim / 2 ;
531453 for (Uint32 uiMipLevel = 1 ; uiMipLevel < HeightMapDesc.MipLevels ; ++uiMipLevel)
532454 {
533- const auto MipProps = GetMipLevelProperties (HeightMapDesc, uiMipLevel);
455+ const MipLevelProperties MipProps = GetMipLevelProperties (HeightMapDesc, uiMipLevel);
534456 for (size_t Row = 0 ; Row < MipProps.LogicalHeight ; ++Row)
535457 {
536458 for (size_t Col = 0 ; Col < MipProps.LogicalWidth ; ++Col)
@@ -580,7 +502,7 @@ void EarthHemsiphere::RenderNormalMap(IRenderDevice* pDevice,
580502 pContext->SetPipelineState (pRenderNormalMapPSO);
581503 pContext->CommitShaderResources (pRenderNormalMapSRB, RESOURCE_STATE_TRANSITION_MODE_TRANSITION);
582504
583- const auto & NormalMapDesc = ptex2DNormalMap->GetDesc ();
505+ const TextureDesc & NormalMapDesc = ptex2DNormalMap->GetDesc ();
584506 for (Uint32 uiMipLevel = 0 ; uiMipLevel < NormalMapDesc.MipLevels ; ++uiMipLevel)
585507 {
586508 TextureViewDesc TexViewDesc;
@@ -680,7 +602,7 @@ void EarthHemsiphere::Create(class ElevationDataSource* pDataSource,
680602
681603 RefCntAutoPtr<ITexture> ptex2DMtrlMask;
682604 CreateTextureFromFile (MaterialMaskPath, TextureLoadInfo (), pDevice, &ptex2DMtrlMask);
683- auto ptex2DMtrlMaskSRV = ptex2DMtrlMask->GetDefaultView (TEXTURE_VIEW_SHADER_RESOURCE);
605+ ITextureView* ptex2DMtrlMaskSRV = ptex2DMtrlMask->GetDefaultView (TEXTURE_VIEW_SHADER_RESOURCE);
684606 m_pResMapping->AddResource (" g_tex2DMtrlMap" , ptex2DMtrlMaskSRV, true );
685607
686608 // Load tiles
@@ -717,7 +639,7 @@ void EarthHemsiphere::Create(class ElevationDataSource* pDataSource,
717639 });
718640
719641 auto PipelineCallback = MakeCallback ([&](PipelineStateCreateInfo& pPipelineCI) {
720- auto & GraphicsPipelineCI{static_cast <GraphicsPipelineStateCreateInfo&>(pPipelineCI)};
642+ GraphicsPipelineStateCreateInfo & GraphicsPipelineCI{static_cast <GraphicsPipelineStateCreateInfo&>(pPipelineCI)};
721643 GraphicsPipelineCI.GraphicsPipeline .DSVFormat = m_Params.ShadowMapFormat ;
722644 });
723645 m_pRSNLoader->LoadPipelineState ({" Render Hemisphere Z Only" , PIPELINE_TYPE_GRAPHICS, false , false , PipelineCallback, PipelineCallback, ShaderCallback, ShaderCallback}, &m_pHemisphereZOnlyPSO);
@@ -790,7 +712,7 @@ void EarthHemsiphere::Render(IDeviceContext* pContext,
790712 });
791713
792714 auto PipelineCallback = MakeCallback ([&](PipelineStateCreateInfo& pPipelineCI) {
793- auto & GraphicsPipelineCI{static_cast <GraphicsPipelineStateCreateInfo&>(pPipelineCI)};
715+ GraphicsPipelineStateCreateInfo & GraphicsPipelineCI{static_cast <GraphicsPipelineStateCreateInfo&>(pPipelineCI)};
794716 GraphicsPipelineCI.GraphicsPipeline .DSVFormat = TEX_FORMAT_D32_FLOAT;
795717 GraphicsPipelineCI.GraphicsPipeline .RTVFormats [0 ] = m_Params.DstRTVFormat ;
796718 GraphicsPipelineCI.GraphicsPipeline .NumRenderTargets = 1 ;
@@ -802,8 +724,8 @@ void EarthHemsiphere::Render(IDeviceContext* pContext,
802724 m_pHemisphereSRB->BindResources (SHADER_TYPE_VERTEX, m_pResMapping, BIND_SHADER_RESOURCES_KEEP_EXISTING);
803725 }
804726
805- ViewFrustumExt ViewFrustum;
806- auto DevType = m_pDevice->GetDeviceInfo ().Type ;
727+ ViewFrustumExt ViewFrustum;
728+ RENDER_DEVICE_TYPE DevType = m_pDevice->GetDeviceInfo ().Type ;
807729 ExtractViewFrustumPlanesFromMatrix (CameraViewProjMatrix, ViewFrustum, DevType == RENDER_DEVICE_TYPE_D3D11 || DevType == RENDER_DEVICE_TYPE_D3D12);
808730
809731 {
0 commit comments