Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion Client/game_sa/CRendererSA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ CRendererSA::~CRendererSA()
{
}

void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided)
{
CBaseModelInfoSAInterface* pModelInfoSAInterface = pModelInfo->GetInterface();
if (!pModelInfoSAInterface)
Expand All @@ -48,6 +48,13 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, flo
// Setup ambient light multiplier
SetLightColoursForPedsCarsAndObjects(lighting);

RwCullMode currentCullMode;
if (doubleSided)
{
RwRenderStateGet(rwRENDERSTATECULLMODE, &currentCullMode);
RwRenderStateSet(rwRENDERSTATECULLMODE, RWRSTATE(rwCULLMODECULLNONE));
}

if (pRwObject->type == RP_TYPE_ATOMIC)
{
RpAtomic* pRpAtomic = reinterpret_cast<RpAtomic*>(pRwObject);
Expand All @@ -59,6 +66,9 @@ void CRendererSA::RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, flo
RpClumpRender(pClump);
}

if (doubleSided)
RwRenderStateSet(rwRENDERSTATECULLMODE, RWRSTATE(currentCullMode));

// Restore ambient light
SetAmbientColours();
}
2 changes: 1 addition & 1 deletion Client/game_sa/CRendererSA.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class CRendererSA : public CRenderer
CRendererSA();
~CRendererSA();

void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) override;
void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided) override;
};
8 changes: 4 additions & 4 deletions Client/mods/deathmatch/logic/CModelRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
#include "game\CRenderer.h"
#include "game\CVisibilityPlugins.h"

bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting)
bool CModelRenderer::EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided)
{
if (g_pCore->IsWindowMinimized())
return false;

if (pModelInfo && pModelInfo->IsLoaded())
{
m_Queue.emplace_back(pModelInfo, matrix, lighting);
m_Queue.emplace_back(pModelInfo, matrix, lighting, doubleSided);
return true;
}

Expand Down Expand Up @@ -54,7 +54,7 @@ void CModelRenderer::Render()
for (auto& modelDesc : m_Queue)
{
if (modelDesc.pModelInfo->IsLoaded() && !modelDesc.pModelInfo->GetIdeFlag(eModelIdeFlag::DRAW_LAST))
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting);
pRenderer->RenderModel(modelDesc.pModelInfo, modelDesc.matrix, modelDesc.lighting, modelDesc.doubleSided);
}

m_Queue.clear();
Expand All @@ -68,5 +68,5 @@ void CModelRenderer::RenderEntity(SModelToRender* modelDesc, float distance)
CRenderer* pRenderer = g_pGame->GetRenderer();
assert(pRenderer);

pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting);
pRenderer->RenderModel(modelDesc->pModelInfo, modelDesc->matrix, modelDesc->lighting, modelDesc->doubleSided);
}
12 changes: 7 additions & 5 deletions Client/mods/deathmatch/logic/CModelRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,20 @@ class CModelRenderer final
struct SModelToRender final
{
CModelInfo* pModelInfo;
CMatrix matrix;
float lighting;
CMatrix matrix;
float lighting;
bool doubleSided;

SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f) :
SModelToRender(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting = 0.0f, bool doubleSided = false) :
pModelInfo(pModelInfo),
matrix(matrix),
lighting(lighting)
lighting(lighting),
doubleSided(doubleSided)
{
}
};

bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting);
bool EnqueueModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided);

void Update();

Expand Down
4 changes: 2 additions & 2 deletions Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2123,7 +2123,7 @@ bool CLuaDrawingDefs::DxDrawWiredSphere(lua_State* const luaVM, const CVector po
return true;
}

bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting)
bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting, std::optional<bool> doubleSided)
{
CModelInfo* pModelInfo = g_pGame->GetModelInfo(modelID);
if (!pModelInfo)
Expand All @@ -2138,5 +2138,5 @@ bool CLuaDrawingDefs::DxDrawModel3D(std::uint32_t modelID, CVector position, CVe
ConvertDegreesToRadians(rotation);

return g_pClientGame->GetModelRenderer()->EnqueueModel(pModelInfo,
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f));
CMatrix{position, rotation, scale.value_or(CVector{1.0f, 1.0f, 1.0f})}, lighting.value_or(0.0f), doubleSided.value_or(false));
}
2 changes: 1 addition & 1 deletion Client/mods/deathmatch/logic/luadefs/CLuaDrawingDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CLuaDrawingDefs : public CLuaDefs
static bool DxDrawWiredSphere(lua_State* const luaVM, const CVector position, const float radius, const std::optional<SColor> color,
const std::optional<float> lineWidth, const std::optional<unsigned int> iterations);

static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting);
static bool DxDrawModel3D(std::uint32_t modelID, CVector position, CVector rotation, const std::optional<CVector> scale, const std::optional<float> lighting, std::optional<bool> doubleSided);

private:
static void AddDxMaterialClass(lua_State* luaVM);
Expand Down
2 changes: 1 addition & 1 deletion Client/sdk/game/CRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ class CRenderer
public:
virtual ~CRenderer() {}

virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting) = 0;
virtual void RenderModel(CModelInfo* pModelInfo, const CMatrix& matrix, float lighting, bool doubleSided) = 0;
};
186 changes: 184 additions & 2 deletions Client/sdk/game/RenderWare.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,19 @@
#define RWFORCEENUMSIZEINT ((std::int32_t)((~((std::uint32_t)0)) >> 1))
#endif
#define RWPLUGINOFFSET(_type, _base, _offset) ((_type*)((std::uint8_t*)(_base) + (_offset)))
#define RWSRCGLOBAL(variable) ((*(RwGlobals**)0xC97B24)->variable) // 0xC97B24 = RwEngineInstance pointer
#define RWRSTATE(a) (reinterpret_cast<void*>(a))
#define RW_STRUCT_ALIGN ((int)((~((unsigned int)0))>>1))
#define RW_TEXTURE_NAME_LENGTH 32
#define RW_FRAME_NAME_LENGTH 23
#define RW_MAX_TEXTURE_COORDS 8

#define RwRenderStateGet(_state, _value) RwRenderStateGetMacro(_state, _value)
#define RwRenderStateSet(_state, _value) RwRenderStateSetMacro(_state, _value)

#define RwRenderStateGetMacro(_state, _value) (RWSRCGLOBAL(dOpenDevice).fpRenderStateGet(_state, _value))
#define RwRenderStateSetMacro(_state, _value) (RWSRCGLOBAL(dOpenDevice).fpRenderStateSet(_state, _value))

/* Type IDs */

#define RP_TYPE_ATOMIC 1
Expand Down Expand Up @@ -487,6 +495,177 @@ enum RwStreamMode
STREAM_MODE_LAST = RW_STRUCT_ALIGN
};

enum RwRenderState
{
rwRENDERSTATENARENDERSTATE = 0,

rwRENDERSTATETEXTURERASTER,
/**<Raster used for texturing (normally used in immediate mode).
* The value is a pointer to an \ref RwRaster.
* Default: NULL.
*/
rwRENDERSTATETEXTUREADDRESS,
/**<\ref RwTextureAddressMode: wrap, clamp, mirror or border.
* Default: rwTEXTUREADDRESSWRAP.
*/
rwRENDERSTATETEXTUREADDRESSU,
/**<\ref RwTextureAddressMode in u only.
* Default: rwTEXTUREADDRESSWRAP.
*/
rwRENDERSTATETEXTUREADDRESSV,
/**<\ref RwTextureAddressMode in v only.
* Default: rwTEXTUREADDRESSWRAP.
*/
rwRENDERSTATETEXTUREPERSPECTIVE,
/**<Perspective correction on/off (always enabled on many platforms).
*/
rwRENDERSTATEZTESTENABLE,
/**<Z-buffer test on/off.
* Default: TRUE.
*/
rwRENDERSTATESHADEMODE,
/**<\ref RwShadeMode: flat or gouraud shading.
* Default: rwSHADEMODEGOURAUD.
*/
rwRENDERSTATEZWRITEENABLE,
/**<Z-buffer write on/off.
* Default: TRUE.
*/
rwRENDERSTATETEXTUREFILTER,
/**<\ref RwTextureFilterMode: point sample, bilinear, trilinear, etc.
* Default: rwFILTERLINEAR.
*/
rwRENDERSTATESRCBLEND,
/**<\ref RwBlendFunction used to modulate the source pixel color
* when blending to the frame buffer.
* Default: rwBLENDSRCALPHA.
*/
rwRENDERSTATEDESTBLEND,
/**<\ref RwBlendFunction used to modulate the destination pixel
* color in the frame buffer when blending. The resulting pixel
* color is given by the formula
* (SRCBLEND * srcColor + DESTBLEND * destColor) for each RGB
* component. For a particular platform, not all combinations
* of blend function are allowed (see platform specific
* restrictions).
* Default: rwBLENDINVSRCALPHA.
*/
rwRENDERSTATEVERTEXALPHAENABLE,
/**<Alpha blending on/off (always enabled on some platforms).
* This is normally used in immediate mode to enable alpha blending
* when vertex colors or texture rasters have transparency. Retained
* mode pipelines will usually set this state based on material colors
* and textures.
* Default: FALSE.
*/
rwRENDERSTATEBORDERCOLOR,
/**<Border color for \ref RwTextureAddressMode
* \ref rwTEXTUREADDRESSBORDER. The value should be a packed
* RwUInt32 in a platform specific format. The macro
* RWRGBALONG(r, g, b, a) may be used to construct this using
* 8-bit color components.
* Default: RWRGBALONG(0, 0, 0, 0).
*/
rwRENDERSTATEFOGENABLE,
/**<Fogging on/off (all polygons will be fogged).
* Default: FALSE.
*/
rwRENDERSTATEFOGCOLOR,
/**<Color used for fogging. The value should be a packed RwUInt32
* in a platform specific format. The macro RWRGBALONG(r, g, b, a)
* may be used to construct this using 8-bit color components.
* Default: RWRGBALONG(0, 0, 0, 0).
*/
rwRENDERSTATEFOGTYPE,
/**<\ref RwFogType, the type of fogging to use.
* Default: rwFOGTYPELINEAR.
*/
rwRENDERSTATEFOGDENSITY,
/**<Fog density for \ref RwFogType of
* \ref rwFOGTYPEEXPONENTIAL or \ref rwFOGTYPEEXPONENTIAL2.
* The value should be a pointer to an RwReal in the
* range 0 to 1.
* Default: 1.
*/
rwRENDERSTATECULLMODE = 20,
/**<\ref RwCullMode, for selecting front/back face culling, or
* no culling.
* Default: rwCULLMODECULLBACK.
*/
rwRENDERSTATESTENCILENABLE,
/**<Stenciling on/off.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: FALSE.
*/
rwRENDERSTATESTENCILFAIL,
/**<\ref RwStencilOperation used when the stencil test passes.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: rwSTENCILOPERATIONKEEP.
*/
rwRENDERSTATESTENCILZFAIL,
/**<\ref RwStencilOperation used when the stencil test passes and
* the depth test (z-test) fails.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: rwSTENCILOPERATIONKEEP.
*/
rwRENDERSTATESTENCILPASS,
/**<\ref RwStencilOperation used when both the stencil and the depth
* (z) tests pass.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: rwSTENCILOPERATIONKEEP.
*/
rwRENDERSTATESTENCILFUNCTION,
/**<\ref RwStencilFunction for the stencil test.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: rwSTENCILFUNCTIONALWAYS.
*/
rwRENDERSTATESTENCILFUNCTIONREF,
/**<Integer reference value for the stencil test.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: 0.
*/
rwRENDERSTATESTENCILFUNCTIONMASK,
/**<Mask applied to the reference value and each stencil buffer
* entry to determine the significant bits for the stencil test.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: 0xffffffff.
*/
rwRENDERSTATESTENCILFUNCTIONWRITEMASK,
/**<Write mask applied to values written into the stencil buffer.
* <i> Supported on Xbox, D3D8, D3D9, and OpenGL only. </i>
* Default: 0xffffffff.
*/
rwRENDERSTATEALPHATESTFUNCTION,
/**<\ref RwAlphaTestFunction for the alpha test. When a pixel fails,
* neither the frame buffer nor the Z-buffer are updated.
* Default: rwALPHATESTFUNCTIONGREATER (GameCube, Xbox, D3D8, D3D9
* and OpenGL). The default PS2 behaviour is to always update the
* frame buffer and update the Z-buffer only if a greater than or
* equal test passes.
*/
rwRENDERSTATEALPHATESTFUNCTIONREF,
/**<Integer reference value for the alpha test.
* <i> Range is 0 to 255, mapped to the platform's actual range </i>
* Default: 128 (PS2) 0 (GameCube, Xbox, D3D8, D3D9 and OpenGL).
*/

rwRENDERSTATEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};

enum RwCullMode
{
rwCULLMODENACULLMODE = 0,

rwCULLMODECULLNONE,
/**<Both front and back-facing triangles are drawn. */
rwCULLMODECULLBACK,
/**<Only front-facing triangles are drawn */
rwCULLMODECULLFRONT,
/**<Only back-facing triangles are drawn */

rwCULLMODEFORCEENUMSIZEINT = RWFORCEENUMSIZEINT
};

// RenderWare base types
struct RwBuffer
{
Expand Down Expand Up @@ -532,14 +711,17 @@ struct RwError
/*****************************************************************************/

typedef bool (*RwSystemFunc)(std::int32_t, void*, void*, std::int32_t);
using RwRenderStateSetFunction = bool(*)(RwRenderState, void*);
using RwRenderStateGetFunction = bool(*)(RwRenderState, void*);

struct RwDevice
{
float gammaCorrection;
RwSystemFunc fpSystem;
float zBufferNear;
float zBufferFar;
// RwRenderStateSetFunction fpRenderStateSet;
// RwRenderStateGetFunction fpRenderStateGet;
RwRenderStateSetFunction fpRenderStateSet;
RwRenderStateGetFunction fpRenderStateGet;
// RwIm2DRenderLineFunction fpIm2DRenderLine;
// RwIm2DRenderTriangleFunction fpIm2DRenderTriangle;
// RwIm2DRenderPrimitiveFunction fpIm2DRenderPrimitive;
Expand Down
Loading