Mercurial > mm7
comparison DecalBuilder.cpp @ 2155:0a1438c16c2b
Render decoupling.
author | Nomad |
---|---|
date | Thu, 09 Jan 2014 17:29:17 +0200 |
parents | d44b7775fc06 |
children | 70b63fe6587c |
comparison
equal
deleted
inserted
replaced
2154:9bd7522cdbbb | 2155:0a1438c16c2b |
---|---|
646 } | 646 } |
647 LOBYTE(result) = 1; | 647 LOBYTE(result) = 1; |
648 return result; | 648 return result; |
649 } | 649 } |
650 | 650 |
651 //----- (0049C095) -------------------------------------------------------- | |
652 void DecalBuilder::DrawDecal(Decal *pDecal, float z_bias) | |
653 { | |
654 signed int v21; // [sp+Ch] [bp-864h]@15 | |
655 RenderVertexD3D3 pVerticesD3D[64]; // [sp+20h] [bp-850h]@6 | |
656 | |
657 if (pDecal->uNumVertices < 3) | |
658 { | |
659 Log::Warning(L"Decal has < 3 vertices"); | |
660 return; | |
661 } | |
662 | |
663 float color_mult; | |
664 if ( pDecal->field_C1C & 1 ) | |
665 color_mult = 1.0; | |
666 else | |
667 color_mult = pDecal->field_C18->_43B570_get_color_mult_by_time(); | |
668 | |
669 for (uint i = 0; i < pDecal->uNumVertices; ++i) | |
670 { | |
671 uint uTint = pRenderer->GetActorTintColor(pDecal->pVertices[i].vWorldViewPosition.x, pDecal->field_C14, 0, 0, nullptr); | |
672 | |
673 uint uTintR = (uTint >> 16) & 0xFF, | |
674 uTintG = (uTint >> 8) & 0xFF, | |
675 uTintB = uTint & 0xFF; | |
676 | |
677 uint uDecalColorMultR = (pDecal->uColorMultiplier >> 16) & 0xFF, | |
678 uDecalColorMultG = (pDecal->uColorMultiplier >> 8) & 0xFF, | |
679 uDecalColorMultB = pDecal->uColorMultiplier & 0xFF; | |
680 | |
681 uint uFinalR = floorf(uTintR / 255.0 * color_mult * uDecalColorMultR + 0.0f), | |
682 uFinalG = floorf(uTintG / 255.0 * color_mult * uDecalColorMultG + 0.0f), | |
683 uFinalB = floorf(uTintB / 255.0 * color_mult * uDecalColorMultB + 0.0f); | |
684 | |
685 | |
686 float v15; | |
687 if (fabs(z_bias) < 1e-5) | |
688 v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0); | |
689 else | |
690 { | |
691 v15 = 1.0 - 1.0 / ((1.0f / pGame->pIndoorCameraD3D->GetShadingDistMist()) * pDecal->pVertices[i].vWorldViewPosition.x * 1000.0) - z_bias; | |
692 if (v15 < 0.000099999997) | |
693 v15 = 0.000099999997; | |
694 } | |
695 | |
696 pVerticesD3D[i].pos.z = v15; | |
697 | |
698 pVerticesD3D[i].pos.x = pDecal->pVertices[i].vWorldViewProjX; | |
699 pVerticesD3D[i].pos.y = pDecal->pVertices[i].vWorldViewProjY; | |
700 pVerticesD3D[i].texcoord.x = pDecal->pVertices[i].u; | |
701 pVerticesD3D[i].texcoord.y = pDecal->pVertices[i].v; | |
702 pVerticesD3D[i].diffuse = (uFinalR << 16) | (uFinalG << 8) | uFinalB; | |
703 pVerticesD3D[i].specular = 0; | |
704 pVerticesD3D[i].rhw = 1.0 / pDecal->pVertices[i].vWorldViewPosition.x; | |
705 } | |
706 | |
707 if (uCurrentlyLoadedLevelType == LEVEL_Indoor) | |
708 v21 = D3DDP_DONOTLIGHT | D3DDP_DONOTCLIP | D3DDP_DONOTUPDATEEXTENTS; | |
709 else | |
710 v21 = D3DDP_DONOTLIGHT; | |
711 | |
712 ErrD3D(pRenderer->pRenderD3D->pDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, | |
713 D3DFVF_XYZRHW | D3DFVF_DIFFUSE | D3DFVF_SPECULAR | D3DFVF_TEX1, | |
714 pVerticesD3D, | |
715 pDecal->uNumVertices, | |
716 v21)); | |
717 } | |
718 | 651 |
719 //----- (0049C2CD) -------------------------------------------------------- | 652 //----- (0049C2CD) -------------------------------------------------------- |
720 void DecalBuilder::DrawDecals(float z_bias) | 653 void DecalBuilder::DrawDecals(float z_bias) |
721 { | 654 { |
722 for (uint i = 0; i < std__vector_pDecals_size; ++i) | 655 for (uint i = 0; i < std__vector_pDecals_size; ++i) |
723 DrawDecal(std__vector_pDecals + i, z_bias); | 656 pRenderer->DrawDecal(std__vector_pDecals + i, z_bias); |
724 } | 657 } |
725 | 658 |
726 //----- (0049C304) -------------------------------------------------------- | 659 //----- (0049C304) -------------------------------------------------------- |
727 void DecalBuilder::DrawBloodsplats() | 660 void DecalBuilder::DrawBloodsplats() |
728 { | 661 { |
729 if (!std__vector_pDecals_size) | 662 if (!std__vector_pDecals_size) |
730 return; | 663 return; |
731 | 664 |
732 if (pRenderer->bUsingSpecular) | 665 pRenderer->BeginDecals(); |
733 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, FALSE)); | 666 |
734 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTextureStageState(0, D3DTSS_ADDRESS, D3DTADDRESS_CLAMP)); | |
735 | |
736 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, TRUE)); | |
737 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, FALSE)); | |
738 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_NONE)); | |
739 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); | |
740 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE)); | |
741 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DITHERENABLE, FALSE)); | |
742 | |
743 IDirect3DTexture2* pTex = pGame->pIndoorCameraD3D->LoadTextureAndGetHardwarePtr("hwsplat04"); | |
744 ErrD3D(pRenderer->pRenderD3D->pDevice->SetTexture(0, pTex)); | |
745 | |
746 DrawDecals(0.00039999999); | 667 DrawDecals(0.00039999999); |
747 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_CULLMODE, D3DCULL_CW)); | 668 |
748 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ZWRITEENABLE, TRUE)); | 669 pRenderer->EndDecals(); |
749 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_ALPHABLENDENABLE, FALSE)); | |
750 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE)); | |
751 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_DESTBLEND, D3DBLEND_ZERO)); | |
752 | |
753 if (pRenderer->bUsingSpecular) | |
754 ErrD3D(pRenderer->pRenderD3D->pDevice->SetRenderState(D3DRENDERSTATE_FOGENABLE, TRUE)); | |
755 } | 670 } |
756 | 671 |
757 //----- (0049C550) -------------------------------------------------------- | 672 //----- (0049C550) -------------------------------------------------------- |
758 void DecalBuilder::DrawDecalDebugOutlines() | 673 void DecalBuilder::DrawDecalDebugOutlines() |
759 { | 674 { |