Skip to content

Commit

Permalink
merge Polystripes from https://github.com/MaxYari/GD3D11
Browse files Browse the repository at this point in the history
  • Loading branch information
kirides committed Dec 17, 2019
2 parents 4e568a3 + 31f5735 commit e736370
Show file tree
Hide file tree
Showing 14 changed files with 441 additions and 45 deletions.
3 changes: 3 additions & 0 deletions D3D11Engine/BaseGraphicsEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,9 @@ class BaseGraphicsEngine
/** Draws the static VOBs */
virtual XRESULT DrawVOBs(bool noTextures=false) { return XR_SUCCESS; }

/** Draws PolyStrips (weapon and particle trails) */
virtual XRESULT DrawPolyStrips(bool noTextures = false) { return XR_SUCCESS; };

/** Draws the sky using the GSky-Object */
virtual XRESULT DrawSky() { return XR_SUCCESS; }

Expand Down
1 change: 1 addition & 0 deletions D3D11Engine/D3D11Engine.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,7 @@ copy "$(OutDir)$(TargetName).pdb" "$(G1_SYSTEM_PATH)\ddraw.pdb"</Command>
<ClInclude Include="zCArray.h" />
<ClInclude Include="zCArrayAdapt.h" />
<ClInclude Include="zCCamera.h" />
<ClInclude Include="zCClassDef.h" />
<ClInclude Include="zCDecal.h" />
<ClInclude Include="zCInput.h" />
<ClInclude Include="zCLightmap.h" />
Expand Down
3 changes: 3 additions & 0 deletions D3D11Engine/D3D11Engine.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@
</ClInclude>
<ClInclude Include="GMeshSimple.h" />
<ClInclude Include="BaseShadowedPointLight.h" />
<ClInclude Include="zCClassDef.h">
<Filter>ZenGin\Classes</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp" />
Expand Down
130 changes: 128 additions & 2 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1613,6 +1613,13 @@ XRESULT D3D11GraphicsEngine::OnStartWorldRendering() {
// DrawParticleEffects();
Engine::GAPI->DrawParticlesSimple();

#if defined BUILD_GOTHIC_2_6_fix || defined BUILD_GOTHIC_1_08k
// Calc weapon/effect trail mesh data
Engine::GAPI->CalcPolyStripMeshes();
// Draw those
DrawPolyStrips();
#endif

// Draw debug lines
LineRenderer->Flush();

Expand Down Expand Up @@ -1769,8 +1776,8 @@ XRESULT D3D11GraphicsEngine::DrawMeshInfoListAlphablended(
SetDefaultStates();

// Setup renderstates
Engine::GAPI->GetRendererState()->RasterizerState.CullMode =
GothicRasterizerStateInfo::CM_CULL_BACK;

Engine::GAPI->GetRendererState()->RasterizerState.CullMode = GothicRasterizerStateInfo::CM_CULL_NONE;
Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();

DirectX::SimpleMath::Matrix view;
Expand Down Expand Up @@ -3626,6 +3633,125 @@ XRESULT D3D11GraphicsEngine::DrawVOBs(bool noTextures) {
return DrawVOBsInstanced();
}

XRESULT D3D11GraphicsEngine::DrawPolyStrips(bool noTextures) {
//DrawMeshInfoListAlphablended was mostly used as an example to write everything below
std::map<zCTexture*, PolyStripInfo> polyStripInfos = Engine::GAPI->GetPolyStripInfos();

SetDefaultStates();

// Setup renderstates
Engine::GAPI->GetRendererState()->RasterizerState.CullMode = GothicRasterizerStateInfo::CM_CULL_NONE;
Engine::GAPI->GetRendererState()->RasterizerState.SetDirty();


Matrix view;
Engine::GAPI->GetViewMatrix(&view);
Engine::GAPI->SetViewTransform(view);

SetActivePixelShader("PS_Diffuse");//seems like "PS_Simple" is used anyway thanks to BindShaderForTexture function used below
SetActiveVertexShader("VS_Ex");

//No idea what these do
SetupVS_ExMeshDrawCall();
SetupVS_ExConstantBuffer();

// Set constant buffer
ActivePS->GetConstantBuffer()[0]->UpdateBuffer(&Engine::GAPI->GetRendererState()->GraphicsState);
ActivePS->GetConstantBuffer()[0]->BindToPixelShader(0);

// Not sure what this does, adds some kind of sky tint?
GSky* sky = Engine::GAPI->GetSky();
ActivePS->GetConstantBuffer()[1]->UpdateBuffer(&sky->GetAtmosphereCB());
ActivePS->GetConstantBuffer()[1]->BindToPixelShader(1);

// Use default material info for now
MaterialInfo defInfo;
ActivePS->GetConstantBuffer()[2]->UpdateBuffer(&defInfo);
ActivePS->GetConstantBuffer()[2]->BindToPixelShader(2);

for (auto it = polyStripInfos.begin(); it != polyStripInfos.end(); it++) {

zCMaterial* mat = it->second.material;
zCTexture* tx = mat->GetAniTexture();
std::vector<ExVertexStruct> vertices = it->second.vertices;

if (!vertices.size()) continue;

//Setting world transform matrix/////////////
Matrix id = Matrix::Identity;

//vob->GetWorldMatrix(&id);
ActiveVS->GetConstantBuffer()[1]->UpdateBuffer(&id);
ActiveVS->GetConstantBuffer()[1]->BindToVertexShader(1);

// Check for alphablending on world mesh
bool blendAdd = mat->GetAlphaFunc() == zMAT_ALPHA_FUNC_ADD;
bool blendBlend = mat->GetAlphaFunc() == zMAT_ALPHA_FUNC_BLEND;


if (tx->CacheIn(0.6f) == zRES_CACHED_IN)
{
MyDirectDrawSurface7* surface = tx->GetSurface();
ID3D11ShaderResourceView* srv[3];

BindShaderForTexture(mat->GetAniTexture(), false, mat->GetAlphaFunc());

// Get diffuse and normalmap
srv[0] = ((D3D11Texture*)surface->GetEngineTexture())->GetShaderResourceView();
srv[1] = surface->GetNormalmap() ? ((D3D11Texture*)surface->GetNormalmap())->GetShaderResourceView() : NULL;
srv[2] = surface->GetFxMap() ? ((D3D11Texture*)surface->GetFxMap())->GetShaderResourceView() : NULL;

// Bind both
Context->PSSetShaderResources(0, 3, srv);

if ((blendAdd || blendBlend) && !Engine::GAPI->GetRendererState()->BlendState.BlendEnabled)
{
if (blendAdd)
Engine::GAPI->GetRendererState()->BlendState.SetAdditiveBlending();
else if (blendBlend)
Engine::GAPI->GetRendererState()->BlendState.SetAlphaBlending();

Engine::GAPI->GetRendererState()->BlendState.SetDirty();

Engine::GAPI->GetRendererState()->DepthState.DepthWriteEnabled = false;
Engine::GAPI->GetRendererState()->DepthState.SetDirty();

UpdateRenderStates();
}

MaterialInfo* info = Engine::GAPI->GetMaterialInfoFrom(tx);
if (!info->Constantbuffer)
info->UpdateConstantbuffer();

info->Constantbuffer->BindToPixelShader(2);

} else {
//Don't draw if texture is not yet cached (I have no idea how can I preload it in advance)
continue;
}

//Populate TempVertexBuffer and draw it
D3D11_BUFFER_DESC desc;
TempVertexBuffer->GetVertexBuffer()->GetDesc(&desc);
if (desc.ByteWidth < sizeof(ExVertexStruct) * vertices.size())
{
LogInfo() << "(PolyStrip) TempVertexBuffer too small (" << desc.ByteWidth << "), need " << sizeof(ExVertexStruct) * vertices.size() << " bytes. Recreating buffer.";

// Buffer too small, recreate it
TempVertexBuffer.reset(new D3D11VertexBuffer());
// Reinit with a bit of a margin, so it will not be reinit each time new vertex is added
TempVertexBuffer->Init(NULL, sizeof(ExVertexStruct) * vertices.size() * 1.1, D3D11VertexBuffer::B_VERTEXBUFFER, D3D11VertexBuffer::U_DYNAMIC, D3D11VertexBuffer::CA_WRITE);
}

TempVertexBuffer->UpdateBuffer(&vertices[0], sizeof(ExVertexStruct) * vertices.size());
DrawVertexBuffer(TempVertexBuffer.get(), vertices.size(), sizeof(ExVertexStruct));
}

SetDefaultStates();

return XR_SUCCESS;
}

/** Returns the current size of the backbuffer */
INT2 D3D11GraphicsEngine::GetResolution() { return Resolution; }

Expand Down
3 changes: 3 additions & 0 deletions D3D11Engine/D3D11GraphicsEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,9 @@ class D3D11GraphicsEngine : public D3D11GraphicsEngineBase {
/** Draws the static VOBs */
virtual XRESULT DrawVOBs(bool noTextures=false);

/** Draws PolyStrips (weapon and particle trails) */
XRESULT DrawPolyStrips(bool noTextures = false);

/** Draws a single VOB */
virtual void DrawVobSingle(VobInfo* vob);

Expand Down
Loading

0 comments on commit e736370

Please sign in to comment.