Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(w3ddevice): add the fire glow on smoke after the shade on D3D11
Olcay Seygan91d08186ae90
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d59941f2d..ec73dc0d2 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -1223,7 +1223,7 @@ The whole HUD is on the hardware. Four colours carry it, and they mean the same- An aircraft's shadow lands where the sun puts it, not underneath the aircraft. Every plane and helicopter in the game's own data asks for a sun "no lower than 89 degrees", so each one cast its shadow straight down and towed it along directly below itself at any height, while the tank beside it was lit by the map's real sun and threw its shadow off to the side. Aircraft now take the same sun as everything else: a helicopter's shadow slides out from under it as it climbs, and a plane's runs ahead of or behind it depending on the hour the map is set at. On a map lit by a very low sun the shadow is held to what a 30 degree sun would cast, so it does not stretch across half the screen. The flat blob shadows under missiles and bombs follow the same ray.- A big smoke cloud darkens the ground under it and fades as it does.- Smoke and dust stand in the sunlight. A column off a burning building throws a soft shadow as thick as the smoke is: a puff of dust barely tints the sand, a black plume darkens the ground, the tanks and the houses under it and the smoke behind it. The column itself is bright on the side facing the sun and goes dark on the far side, and a cloud drifting through a building's shadow greys over with everything else in there. A cloud used to cast a round patch straight down whichever way the sun stood, and took no shade from anything. Fire casts nothing, it is light. A machine that cannot run the newer picture keeps the round patch.-- Fire lights its own smoke. The bottom of a column over a burning tank glows orange from the flames under it and flickers with them, then goes grey as it climbs out of their reach; an explosion's flash warms the smoke drifting past it. Smoke used to keep the same flat grey right down into the fire. Both renderers draw it.+- Fire lights its own smoke. The bottom of a column over a burning tank glows orange from the flames under it and flickers with them, then goes grey as it climbs out of their reach; an explosion's flash warms the smoke drifting past it. Smoke used to keep the same flat grey right down into the fire. Both renderers draw it. On the newer picture the glow stays lit where the column's own shadow falls, so a fire burning on the far side of a plume still shows orange through it instead of going dark with the smoke around it.- The soft blob shadow for trees and scenery had never been drawn at all.- Every one of the 128 tree types casts now, plus the bushes and palms.- A tree's shadow is the tree. Trunk, crown, and the gaps between the leaves, lying along thediff --git a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.hindex 5fbcc9168..6e872c938 100644--- a/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h+++ b/GeneralsMD/Code/GameEngineDevice/Include/W3DDevice/GameClient/W3DParticleSys.h@@ -80,6 +80,7 @@ public:UnsignedInt fieldIncrement; ///< 1 if every drawn particle counts against the field budgetInt drawn; ///< written by the jobUnsignedInt pastLimit; ///< written by the job: on-screen particles past capacity+ Bool glow; ///< written by the job: the fire's glow is in the normals, not the colour};private:diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cppindex b17228f24..d594bf228 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DParticleSys.cpp@@ -41,6 +41,7 @@#include "W3DDevice/GameClient/W3DDynamicLight.h"#include "WW3D2/camera.h"#include "WW3D2/dx8wrapper.h"+#include "WW3D2/dx11runtime.h"#include "Common/JobSystem.h"#ifdef _INTERNAL@@ -362,6 +363,10 @@ struct BillboardFillJobReal extentX, extentY, extentZ;SmokeLight lights[ SMOKE_LIGHTS_MAX ]; ///< this frame's, strongest firstInt lightCount;+ /// Direct3D 11 is drawing the picture: the glow goes into the normals, and its pixel program adds+ /// it after the sun's shadow and the smoke's own shade, which dimmed a fire seen through the far+ /// side of a plume when it was in the colour. Direct3D 9 shades nothing and keeps it baked.+ Bool glowAfterShade;};/// systems a pool thread claims at once; a system is a few hundred particles, so one claim a system@@ -398,13 +403,23 @@ static void fillBillboards( Int index, void *context )const RGBColor *color = p->getColor();Real red = color->red, green = color->green, blue = color->blue;+ Vector3 glow( 0.0f, 0.0f, 0.0f );if (lightCount > 0)+ {lightSmoke( pos, p->getAlpha(), lights, lightCount, red, green, blue );+ if (job->glowAfterShade)+ {+ glow.Set( red - color->red, green - color->green, blue - color->blue );+ red = color->red;+ green = color->green;+ blue = color->blue;+ }+ }const unsigned packed = DX8Wrapper::Convert_Color_Clamp( Vector4( red, green, blue, p->getAlpha() ) );// The orientation table's index wraps, as it did on Windows (Platform/MsvcFloatCasts.h).const uint8 orientation = floatToByteAsMsvc( p->getAngle() * 255.0f / (2.0f * PI) );PointGroupClass::Write_Billboard( quad, job->view, Vector3( pos->x, pos->y, pos->z ), psize,- orientation, packed );+ orientation, packed, glow );quad += 4;if (++drawn == fill.capacity)@@ -415,6 +430,7 @@ static void fillBillboards( Int index, void *context )}fill.drawn = drawn;+ fill.glow = job->glowAfterShade && lightCount > 0;}W3DParticleSystemManager::W3DParticleSystemManager()@@ -555,6 +571,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)fill.fieldIncrement = ( sys->getPriority() == AREA_EFFECT && sys->m_isGroundAligned != FALSE ) ? 1 : 0;fill.drawn = 0;fill.pastLimit = 0;+ fill.glow = FALSE;fill.texture = W3DDisplay::m_assetManager->Get_Texture( sys->getParticleTypeName().str() );PointGroupClass::Reserve_Sorted_Billboards( fill.capacity, &fill.range );m_billboardFills.push_back( fill );@@ -570,6 +587,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)fillJob.extentY = beY;fillJob.extentZ = beZ;fillJob.lightCount = TheGlobalData->m_smokeFireLighting ? gatherSmokeLights( fillJob.lights, bbox ) : 0;+ fillJob.glowAfterShade = Direct3D11_Present_Is_Enabled();JobSystem::parallel_for( (Int)m_billboardFills.size(), BILLBOARD_FILLS_PER_CLAIM, fillBillboards, &fillJob );size_t nextFill = 0;for( ParticleSystemManager::ParticleSystemListIt it = particleSysList.begin(); it != particleSysList.end(); ++it)@@ -622,7 +640,7 @@ void W3DParticleSystemManager::doParticles(RenderInfoClass &rinfo)if (nextFill < m_billboardFills.size() && m_billboardFills[ nextFill ].system == sys){BillboardFill &fill = m_billboardFills[ nextFill++ ];- PointGroupClass::Insert_Sorted_Billboards( &fill.range, fill.drawn, fill.texture, fill.shader );+ PointGroupClass::Insert_Sorted_Billboards( &fill.range, fill.drawn, fill.texture, fill.shader, fill.glow != FALSE );fill.texture->Release_Ref(); // the draw state took its own referencem_fieldParticleCount += fill.fieldIncrement * fill.drawn;m_onScreenParticleCount += fill.drawn;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cppindex 42cf0cbeb..f20f4ff2a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.cpp@@ -260,6 +260,7 @@ DX11BackendClass::DX11BackendClass(), ShadowUnitsPerDepth(0.0f), ShadowSkyFill(0.0f), ShadowReceiving(false)+ , SmokeGlow(false), NormalMappedDraws(0), DrawsMade(0), DrawsRefused(0)@@ -920,6 +921,21 @@ void DX11BackendClass::Set_Scene_View(const float view[16])}}+void DX11BackendClass::Set_Smoke_Glow(bool glow)+{+ if (SmokeGlow != glow) {+ SmokeGlow = glow;+ PipelineChanged = true;+ }+}++bool DX11BackendClass::Smoke_Glow() const+{+ return SmokeGlow && VertexProgram == ENGINE_SHADER_NONE && PixelProgram == ENGINE_SHADER_NONE+ && RenderStates.Get_Render_State(D3DRS_LIGHTING) == FALSE+ && (VertexFormat & D3DFVF_NORMAL) != 0 && (VertexFormat & D3DFVF_XYZRHW) == 0;+}+bool DX11BackendClass::Views_Current_Target(unsigned stage, ID3D11ShaderResourceView * texture) const{if (texture == NULL || CurrentTarget == NULL) {@@ -1648,6 +1664,7 @@ bool DX11BackendClass::Build_Combiner_Description(CombinerDescription & descript}description.NormalMapped = description.StageCount > 0 && Normal_Mapped();description.ShadowReceiving = description.StageCount > 0 && Shadow_Receiving();+ description.SmokeGlow = Smoke_Glow();return description.StageCount > 0;}@@ -1730,6 +1747,7 @@ bool DX11BackendClass::Build_Vertex_Description(VertexPipelineDescription & descdescription.FogVertexMode = RenderStates.Get_Render_State(D3DRS_FOGVERTEXMODE);description.NormalMapped = (Normal_Mapped()&& StageStates[0][D3DTSS_COLOROP] != D3DTOP_DISABLE) || Terrain_Bumped();+ description.SmokeGlow = Smoke_Glow();return true;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.hindex 1f6bad932..5f39079f1 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11backend.h@@ -203,6 +203,11 @@ public:// frame's camera is back; until the first one, such a draw uses the view it was drawn with.void Set_Scene_View(const float view[16]);+ // The draws that follow carry the glow of the fires near them in their normals and want it added+ // after the shade (ffvertex.h and ffshader.h, SmokeGlow). Only the sorting pool sets it, around+ // the smoke billboards' runs. An unlit draw with a normal takes it; any other ignores it.+ void Set_Smoke_Glow(bool glow);+// What is in the map, read back through a staging copy: how much of it was drawn into and how// near the nearest thing is. A caster pass that drew nothing leaves a map that is all one// value, and no draw count tells that apart from a pass that drew the world.@@ -426,6 +431,8 @@ private:float SceneView[16];bool SceneViewKnown;bool Camera_Space_Draw() const;+ bool SmokeGlow;+ bool Smoke_Glow() const;// A stage samples the target the draw is going into: the heat haze, which bends a picture that// already took its shadows, and would take them a second time.bool Samples_Current_Target() const;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cppindex 6904b6d2f..6441f5ce5 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.cpp@@ -334,6 +334,13 @@ void Direct3D11_Set_Scene_View(const float view[16])}}+void Direct3D11_Set_Smoke_Glow(bool glow)+{+ if (Active) {+ Backend.Set_Smoke_Glow(glow);+ }+}+void Direct3D11_Clear_Shadow_Parameters(){if (Active) {diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.hindex 2d9a8ae36..c40050f2f 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime.h@@ -152,6 +152,10 @@ bool Direct3D11_Fill_Smoke_Map(const float * casters, unsigned count, float stre// looks its shadow up through it.void Direct3D11_Set_Scene_View(const float view[16]);+// The draws that follow carry a fire's glow in their normals, to be added after the shade+// (DX11BackendClass::Set_Smoke_Glow). The sorting pool sets it around the smoke billboards' runs.+void Direct3D11_Set_Smoke_Glow(bool glow);+// The CPU has just written this surface. The next bind of its texture fills the Direct3D 11 copy// again. A no-op when the backend is not running.void Direct3D11_Mark_Surface_Dirty(struct IDirect3DSurface9 * surface);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cppindex c4f4e732c..24e21aa22 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/dx11runtime_posix.cpp@@ -73,6 +73,7 @@ void Direct3D11_Set_Shadow_Parameters(float, float, float, float, float, float,void Direct3D11_Clear_Shadow_Parameters() {}bool Direct3D11_Fill_Smoke_Map(const float *, unsigned, float) { return false; }void Direct3D11_Set_Scene_View(const float [16]) {}+void Direct3D11_Set_Smoke_Glow(bool) {}void Direct3D11_Mark_Surface_Dirty(struct IDirect3DSurface9 *) {}void Direct3D11_Mirror_Render_Target(struct IDirect3DSurface9 *) {}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cppindex af6055488..c91f2e37b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.cpp@@ -504,7 +504,7 @@ static bool generate_combiners(const CombinerDescription & description,if (description.NormalMapped) {hlsl += " current.rgb = saturate(current.rgb + highlight);\n";}- else if (description.SpecularAdd) {+ else if (description.SpecularAdd && !description.SmokeGlow) {// Before the fog and the alpha test, as D3D9 orders them; the alpha is the stages'.hlsl += " current.rgb = saturate(current.rgb + input.Specular.rgb);\n";}@@ -514,6 +514,11 @@ static bool generate_combiners(const CombinerDescription & description,hlsl += volumetric ? VOLUMETRIC_SHADOW_APPLY : SHADOW_APPLY;}+ // After the shade, so the light a fire throws on smoke is not dimmed by the smoke it lights.+ if (description.SmokeGlow) {+ hlsl += " current.rgb = saturate(current.rgb + input.Specular.rgb * texel.rgb);\n";+ }+if (target == COMBINER_SHADER_TARGET_D3D11&& !CombinerShader_Append_Pixel_Pipeline(description.PixelPipeline, hlsl)) {return false;@@ -593,5 +598,8 @@ std::string CombinerShader_Key(const CombinerDescription & description)if (description.SpecularAdd) {key += ":SP";}+ if (description.SmokeGlow) {+ key += ":G";+ }return key;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.hindex e482c9cee..7f11628ee 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffshader.h@@ -104,6 +104,13 @@ struct CombinerDescription// it ("Writing HLSL Shaders in Direct3D 9"). A normal mapped program adds its own highlight// instead. Initialised here for a caller that fills the rest field by field.bool SpecularAdd = false;++ // D3D11 only: the vertex half carries a fire's glow in the specular slot (VertexPipelineDescription::+ // SmokeGlow), and it is added after the shadow and the smoke's own shade, scaled by the last+ // stage's texel the way the stages scale the diffuse colour. Baked into the vertex colour, the+ // glow of a fire behind a plume went dark with the plume's far side. Replaces SpecularAdd, whose+ // slot it takes. Initialised here for a caller that fills the rest field by field.+ bool SmokeGlow = false;};// The normal mapped pixel program reads this many directional lights from its constants. Slotsdiff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cppindex 88e0987b5..16b56f89a 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.cpp@@ -512,6 +512,10 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,if (description.NormalMapped && is_pretransformed(description.FVF)) {return false;}+ if (description.SmokeGlow+ && (description.LightingEnabled || !has_normal(description.FVF) || is_pretransformed(description.FVF))) {+ return false;+ }// A pre-transformed vertex has been through the transform, the lighting and the coordinate// generation already: its position is in pixels, its colour is in the vertex, and D3D9 reads@@ -624,9 +628,14 @@ bool VertexShader_Generate(const VertexPipelineDescription & description,}// And the specular colour is the vertex's where there is one, which the pixel adds with// D3DRS_SPECULARENABLE (dx8renderer.cpp gives a mesh with a second colour array one).- body += has_specular(description.FVF)- ? " output.Specular = input.Specular;\n"- : " output.Specular = float4(0.0, 0.0, 0.0, 0.0);\n";+ if (description.SmokeGlow) {+ body += " output.Specular = float4(input.Normal, 0.0);\n";+ }+ else {+ body += has_specular(description.FVF)+ ? " output.Specular = input.Specular;\n"+ : " output.Specular = float4(0.0, 0.0, 0.0, 0.0);\n";+ }}if (description.FogEnabled) {@@ -768,5 +777,8 @@ std::string VertexShader_Key(const VertexPipelineDescription & description)if (description.NormalMapped) {key += ":N";}+ if (description.SmokeGlow) {+ key += ":G";+ }return key;}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.hindex e2b5edab3..da96f41d3 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/ffvertex.h@@ -145,6 +145,13 @@ struct VertexPipelineDescription// not depend on the normal, which ffshader reads to light the pixel again. An unlit one is the// terrain, whose pixel half (engineshader) reads only the position. Initialised here for a caller that fills the rest field by field.bool NormalMapped = false;++ // An unlit draw whose normal is not a normal: the sorted smoke billboards put the glow of the+ // fires near them there, and the program hands it on in the specular colour, which an unlit draw+ // with no second colour in its vertices otherwise leaves black. The pixel half adds it after the+ // shade (CombinerDescription::SmokeGlow). Refused on a lit draw or a format with no normal.+ // Initialised here for a caller that fills the rest field by field.+ bool SmokeGlow = false;};// Which profile the generated text is for. The two differ in the output semantic and in how thediff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cppindex 995a3b9ce..27c70356b 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.cpp@@ -1071,7 +1071,7 @@ void PointGroupClass::Reserve_Sorted_Billboards(int quads, SortingBillboardRange* the same Insert_Quads, from a range the jobs have already written. **========================================================================*/void PointGroupClass::Insert_Sorted_Billboards(SortingBillboardRange *range, int quads,- TextureClass *texture, const ShaderClass &shader)+ TextureClass *texture, const ShaderClass &shader, bool glow){if (quads > 0){@@ -1095,7 +1095,7 @@ void PointGroupClass::Insert_Sorted_Billboards(SortingBillboardRange *range, intconst unsigned short vertices=(unsigned short)(quads*4);DX8Wrapper::Set_Index_Buffer(SortingQuads, 0);DX8Wrapper::Set_Sorting_Vertex_Range(range->Array, range->Offset, vertices);- SortingRendererClass::Insert_Quads((unsigned short)quads, 0, vertices);+ SortingRendererClass::Insert_Quads((unsigned short)quads, 0, vertices, glow);DX8Wrapper::Set_Transform(D3DTS_VIEW,view);}diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.hindex b1be8f1e1..950e25db9 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/pointgr.h@@ -234,17 +234,21 @@ public:/// Bind a reserved range holding quads written by Write_Billboard and put it into the sorting/// pool, with the state Render gives a billboarded QUADS group; then release the range. The- /// shader has to be one Would_Sort_Billboards accepts. Render thread only.+ /// shader has to be one Would_Sort_Billboards accepts. glow: the quads' normals hold the glow+ /// Write_Billboard was given, for the Direct3D 11 backend to add after the shade. Render thread+ /// only.static void Insert_Sorted_Billboards(SortingBillboardRange *range, int quads,- TextureClass *texture, const ShaderClass &shader);+ TextureClass *texture, const ShaderClass &shader, bool glow = false);/// One billboard's four vertices: the transform, corner table and single-frame UVs Render uses/// for a billboarded QUADS group with per-point sizes, orientations and colours, written the/// same way so the vertices come out bit for bit the same. color is packed already- /// (DX8Wrapper::Convert_Color_Clamp). Touches nothing but its arguments and the static tables,- /// so any thread may call it.+ /// (DX8Wrapper::Convert_Color_Clamp). glow goes in the normal, which an unlit billboard does not+ /// otherwise read. Touches nothing but its arguments and the static tables, so any thread may+ /// call it.static inline void Write_Billboard(VertexFormatXYZNDUV2 *quad, const Matrix4x4 &view,- const Vector3 &world, float size, unsigned char orientation, unsigned color)+ const Vector3 &world, float size, unsigned char orientation, unsigned color,+ const Vector3 &glow){const Vector4 result=view*world;const Vector3 point(result.X,result.Y,result.Z);@@ -256,6 +260,9 @@ public:quad[k].x=location.X;quad[k].y=location.Y;quad[k].z=location.Z;+ quad[k].nx=glow.X;+ quad[k].ny=glow.Y;+ quad[k].nz=glow.Z;quad[k].diffuse=color;quad[k].u1=uv[k].X;quad[k].v1=uv[k].Y;diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cppindex a6c565245..bcc608b19 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.cpp@@ -52,6 +52,7 @@#include <wwprofile.h>#include <algorithm>#include "Lib/Clock.h" // Clock_Ticks: QueryPerformanceCounter on Windows, a monotonic clock elsewhere+#include "dx11runtime.h"#ifdef _INTERNAL// for occasional debugging...@@ -147,6 +148,7 @@ public:unsigned short min_vertex_index; // First index used in the vbunsigned short vertex_count; // Number of vertices used in vbbool quads; // four vertices a quad, in order from min_vertex_index; the ib is not read+ bool glow; // the normals hold a fire's glow (Insert_Quads)};static DLListClass<SortingNodeStruct> sorted_list;@@ -231,6 +233,7 @@ void SortingRendererClass::Insert_Triangles(state->min_vertex_index=min_vertex_index;state->vertex_count=vertex_count;state->quads=false;+ state->glow=false;SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);WWASSERT(vertex_buffer);@@ -316,7 +319,8 @@ void SortingRendererClass::Insert_Triangles(void SortingRendererClass::Insert_Quads(unsigned short quad_count,unsigned short min_vertex_index,- unsigned short vertex_count)+ unsigned short vertex_count,+ bool glow){const unsigned short polygon_count=quad_count*2;if (!WW3D::Is_Sorting_Enabled()) {@@ -340,6 +344,7 @@ void SortingRendererClass::Insert_Quads(state->min_vertex_index=min_vertex_index;state->vertex_count=vertex_count;state->quads=true;+ state->glow=glow;state->transformed_center=Vector3(0.0f,0.0f,0.0f);unsorted_list.Add_Tail(state);}@@ -693,8 +698,9 @@ static void Flush_Sorting_Batch(const TempIndexStruct* entries,unsigned entry_coif (entry_node!=node_id) {SortingNodeStruct* state=overlapping_nodes[node_id];SortingNodeStruct* next=overlapping_nodes[entry_node];- if (!Same_Draw_State(state->sorting_state,next->sorting_state)) {+ if (state->glow!=next->glow || !Same_Draw_State(state->sorting_state,next->sorting_state)) {Apply_Render_State(state->sorting_state);+ Direct3D11_Set_Smoke_Glow(state->glow);DX8Wrapper::Draw_Triangles(run_first_index,run_triangles,run_first_vertex,vertex_cursor-run_first_vertex);run_first_index=index_cursor;run_first_vertex=vertex_cursor;@@ -708,7 +714,9 @@ static void Flush_Sorting_Batch(const TempIndexStruct* entries,unsigned entry_co}Apply_Render_State(overlapping_nodes[node_id]->sorting_state);+ Direct3D11_Set_Smoke_Glow(overlapping_nodes[node_id]->glow);DX8Wrapper::Draw_Triangles(run_first_index,run_triangles,run_first_vertex,vertex_cursor-run_first_vertex);+ Direct3D11_Set_Smoke_Glow(false);tDrawEnd = Clock_Ticks();flush_profile_draw_ms += flushProfileElapsedMS(tCopyEnd, tDrawEnd);@@ -1017,6 +1025,7 @@ void SortingRendererClass::Insert_VolumeParticle(state->polygon_count=polygon_count * layerCount;//THIS IS VOLUME_PARTICLE SPECIFICstate->vertex_count=vertex_count * layerCount;//THIS IS VOLUME_PARTICLE SPECIFICstate->quads=false;+ state->glow=false;SortingVertexBufferClass* vertex_buffer=static_cast<SortingVertexBufferClass*>(state->sorting_state.vertex_buffers[0]);WWASSERT(vertex_buffer);diff --git a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.h b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.hindex 024e59586..2114390d0 100644--- a/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.h+++ b/GeneralsMD/Code/Libraries/Source/WWVegas/WW3D2/sortingrenderer.h@@ -52,11 +52,13 @@ public:unsigned short vertex_count);/// Quads laid out four vertices each, in order, from min_vertex_index; the pool sorts one entry- /// a quad and does not read the index buffer.+ /// a quad and does not read the index buffer. glow: the quads' normals hold a fire's glow, which+ /// the Direct3D 11 backend adds after the shade (Direct3D11_Set_Smoke_Glow).static void Insert_Quads(unsigned short quad_count,unsigned short min_vertex_index,- unsigned short vertex_count);+ unsigned short vertex_count,+ bool glow = false);static void Insert_VolumeParticle(const SphereClass& bounding_sphere,diff --git a/GeneralsMD/Code/Tests/test_dx11backend.cpp b/GeneralsMD/Code/Tests/test_dx11backend.cppindex 88dbf9827..22bfa9ff3 100644--- a/GeneralsMD/Code/Tests/test_dx11backend.cpp+++ b/GeneralsMD/Code/Tests/test_dx11backend.cpp@@ -368,6 +368,92 @@ TEST(dx11backend_the_same_state_resolves_to_one_pipeline)backend.Shutdown();}+// The sorted smoke billboards carry a fire's glow in their normals, and the backend adds it to what+// the stages made. The quad's normal is (0, 0, 1), so with the glow on the blue channel goes to full+// and the other two keep the vertex colour; the glow is its own pipeline and turning it off goes+// back to the first one without building a third.+TEST(dx11backend_the_smoke_glow_is_read_from_the_normal)+{+ DX11DeviceClass device;+ CHECK(device.Create_Offscreen());+ ID3D11Device * d3d = device.Get_Device();++ DX11BackendClass backend;+ CHECK(backend.Initialise(&device));++ D3D11_TEXTURE2D_DESC target_description;+ memset(&target_description, 0, sizeof(target_description));+ target_description.Width = TARGET_SIZE;+ target_description.Height = TARGET_SIZE;+ target_description.MipLevels = 1;+ target_description.ArraySize = 1;+ target_description.Format = DXGI_FORMAT_B8G8R8A8_UNORM;+ target_description.SampleDesc.Count = 1;+ target_description.Usage = D3D11_USAGE_DEFAULT;+ target_description.BindFlags = D3D11_BIND_RENDER_TARGET;++ ID3D11Texture2D * target = NULL;+ CHECK(SUCCEEDED(d3d->CreateTexture2D(&target_description, NULL, &target)));++ D3D11_TEXTURE2D_DESC staging_description = target_description;+ staging_description.Usage = D3D11_USAGE_STAGING;+ staging_description.BindFlags = 0;+ staging_description.CPUAccessFlags = D3D11_CPU_ACCESS_READ;++ ID3D11Texture2D * staging = NULL;+ CHECK(SUCCEEDED(d3d->CreateTexture2D(&staging_description, NULL, &staging)));++ ID3D11RenderTargetView * target_view = NULL;+ CHECK(SUCCEEDED(d3d->CreateRenderTargetView(target, NULL, &target_view)));+ device.Get_Context()->OMSetRenderTargets(1, &target_view, NULL);++ backend.Set_Viewport(0, 0, TARGET_SIZE, TARGET_SIZE);+ configure_unlit_pass_through(backend);++ ID3D11Buffer * vertices = NULL;+ CHECK(DX11Resource_Create_Vertex_Buffer(d3d, sizeof(QUAD_VERTICES), D3DPOOL_MANAGED, 0,+ QUAD_VERTICES, &vertices));+ ID3D11Buffer * indices = NULL;+ CHECK(DX11Resource_Create_Index_Buffer(d3d, sizeof(QUAD_INDICES), D3DPOOL_MANAGED, 0,+ QUAD_INDICES, &indices));+ backend.Set_Stream_Source(vertices, sizeof(BackendVertex), 0);+ backend.Set_Indices(indices, DXGI_FORMAT_R16_UINT);++ CHECK(backend.Draw_Indexed_Triangles(6, 0, 0));+ backend.Set_Smoke_Glow(true);+ CHECK(backend.Draw_Indexed_Triangles(6, 0, 0));++ device.Get_Context()->CopyResource(staging, target);+ D3D11_MAPPED_SUBRESOURCE mapped;+ CHECK(SUCCEEDED(device.Get_Context()->Map(staging, 0, D3D11_MAP_READ, 0, &mapped)));+ const unsigned char * centre = static_cast<const unsigned char *>(mapped.pData)+ + mapped.RowPitch * (TARGET_SIZE / 2) + (TARGET_SIZE / 2) * 4;+ CHECK_EQ(centre[0], 0xff);+ CHECK_EQ(centre[1], EXPECTED_GREEN);+ CHECK_EQ(centre[2], EXPECTED_RED);+ device.Get_Context()->Unmap(staging, 0);++ unsigned pipelines = 0;+ unsigned long long made = 0;+ unsigned long long refused = 0;+ backend.Statistics(pipelines, made, refused);+ CHECK_EQ(pipelines, 2u);++ backend.Set_Smoke_Glow(false);+ CHECK(backend.Draw_Indexed_Triangles(6, 0, 0));+ backend.Statistics(pipelines, made, refused);+ CHECK_EQ(pipelines, 2u);+ CHECK_EQ(made, 3ull);+ CHECK_EQ(refused, 0ull);++ indices->Release();+ vertices->Release();+ target_view->Release();+ staging->Release();+ target->Release();+ backend.Shutdown();+}+static const char * const CACHE_FILE_NAME = "dx11backend_test_shaders.cache";static const long LAST_RECORD_CUT_BYTES = 4;diff --git a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp b/GeneralsMD/Code/Tests/test_ffshadercompile.cppindex 8c198ee08..74c5a9069 100644--- a/GeneralsMD/Code/Tests/test_ffshadercompile.cpp+++ b/GeneralsMD/Code/Tests/test_ffshadercompile.cpp@@ -237,3 +237,43 @@ TEST(ffshadercompile_a_shadow_receiving_program_reads_the_smoke_on_d3d11_only)}CHECK(compiles(compile, eleven, D3D11_PROFILE));}++// A fire's glow on smoke goes on after the sun's shadow and the smoke's own shade, and before the+// fog: added before them, the glow of a fire behind a plume went dark with the plume's far side. It+// takes the specular slot, so a program asking for both does not add the slot twice.+TEST(ffshadercompile_the_smoke_glow_is_added_after_the_shade)+{+ CombinerDescription description;+ memset(&description, 0, sizeof(description));+ description.StageCount = 1;+ description.Stages[0] = one_stage(D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE,+ D3DTOP_MODULATE, D3DTA_TEXTURE, D3DTA_DIFFUSE, 0, true);+ description.ShadowReceiving = true;+ description.PixelPipeline.FogEnabled = true;++ std::string plain;+ CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_D3D11, plain));+ CHECK(plain.find("input.Specular.rgb * texel.rgb") == std::string::npos);+ const std::string plain_key = CombinerShader_Key(description);++ description.SmokeGlow = true;+ description.SpecularAdd = true;+ std::string eleven;+ CHECK(CombinerShader_Generate(description, COMBINER_SHADER_TARGET_D3D11, eleven));+ const size_t shade = eleven.find("light_reaching(input.Position)");+ const size_t glow = eleven.find("current.rgb + input.Specular.rgb * texel.rgb");+ const size_t fog = eleven.find("FogColour.rgb, current.rgb");+ CHECK(shade != std::string::npos);+ CHECK(glow != std::string::npos);+ CHECK(fog != std::string::npos);+ CHECK(shade < glow && glow < fog);+ CHECK(eleven.find("current.rgb + input.Specular.rgb);") == std::string::npos);+ CHECK(CombinerShader_Key(description) == plain_key + ":SP:G");++ D3DCompileFunction compile = load_compiler();+ if (compile == NULL) {+ printf(" d3dcompiler_47.dll not present, skipping the compile\n");+ return;+ }+ CHECK(compiles(compile, eleven, D3D11_PROFILE));+}diff --git a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp b/GeneralsMD/Code/Tests/test_ffvertexcompile.cppindex 244473336..d3f642c97 100644--- a/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp+++ b/GeneralsMD/Code/Tests/test_ffvertexcompile.cpp@@ -249,3 +249,35 @@ TEST(ffvertexcompile_a_normal_mapped_pair_compiles_on_d3d11)CHECK(compiles(compile, pixel_hlsl, "ps_4_0"));CHECK(!CombinerShader_Generate(pixel, COMBINER_SHADER_TARGET_D3D9, pixel_hlsl));}++// The smoke billboards' glow: the unlit vertex half hands the normal on in the specular slot, keyed+// apart from the same program without it, and refuses a lit draw, whose normal is a normal.+TEST(ffvertexcompile_the_smoke_glow_rides_the_specular_slot)+{+ VertexPipelineDescription plain = plain_description();+ VertexPipelineDescription glow = plain;+ glow.SmokeGlow = true;++ std::string plain_hlsl;+ std::string glow_hlsl;+ CHECK(VertexShader_Generate(plain, VERTEX_SHADER_TARGET_D3D11, plain_hlsl));+ CHECK(VertexShader_Generate(glow, VERTEX_SHADER_TARGET_D3D11, glow_hlsl));+ CHECK(glow_hlsl.find("output.Specular = float4(input.Normal, 0.0);") != std::string::npos);+ CHECK(plain_hlsl.find("output.Specular = float4(input.Normal") == std::string::npos);+ CHECK(VertexShader_Key(glow) == VertexShader_Key(plain) + ":G");++ VertexPipelineDescription lit = glow;+ lit.LightingEnabled = true;+ CHECK(!VertexShader_Generate(lit, VERTEX_SHADER_TARGET_D3D11, glow_hlsl));+ VertexPipelineDescription no_normal = glow;+ no_normal.FVF = D3DFVF_XYZ|D3DFVF_TEX2|D3DFVF_DIFFUSE;+ CHECK(!VertexShader_Generate(no_normal, VERTEX_SHADER_TARGET_D3D11, glow_hlsl));++ D3DCompileFunction compile = load_compiler();+ if (compile == NULL) {+ printf(" d3dcompiler_47.dll not present, skipping the compile\n");+ return;+ }+ CHECK(VertexShader_Generate(glow, VERTEX_SHADER_TARGET_D3D11, glow_hlsl));+ CHECK(compiles(compile, glow_hlsl, D3D11_PROFILE));+}