Skip to content

Commit 9de7204

Browse files
committed
Merge branch 'dev/adunn/vertex_lighting_as_surface_prop' into 'main'
[REMIX-4529] Implement the vertex color as baked lighting as a per surface property See merge request lightspeedrtx/dxvk-remix-nv!1681
2 parents 03590ce + ac77acb commit 9de7204

17 files changed

+58
-36
lines changed

bridge/src/util/util_remixapi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,8 @@ void InstanceInfoObjectPicking::_dtor() {
502502
srcAlphaBlendFactor, \
503503
dstAlphaBlendFactor, \
504504
alphaBlendOp, \
505-
writeMask
505+
writeMask, \
506+
isVertexColorBakedLighting
506507
uint32_t InstanceInfoBlend::_calcSize() const {
507508
return fold_helper::calcSize(InstanceInfoBlendVars);
508509
}

bridge/test/rtx/unit/test_remix_api_common.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,8 @@ bool InstanceInfoObjectPicking::compare(const RemixApiT& me, const RemixApiT& ot
428428
srcAlphaBlendFactor, \
429429
dstAlphaBlendFactor, \
430430
alphaBlendOp, \
431-
writeMask
431+
writeMask, \
432+
isVertexColorBakedLighting
432433
using InstanceInfoBlend = Expected<remixapi_InstanceInfoBlendEXT>;
433434
void InstanceInfoBlend::init() {
434435
sType = REMIXAPI_STRUCT_TYPE_INSTANCE_INFO_BLEND_EXT;

public/include/remix/remix.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,7 @@ namespace remix {
722722
textureAlphaOperation = 1 /* DxvkRtTextureOperation::SelectArg1 */;
723723
tFactor = 0XFFFFFFFF;
724724
isTextureFactorBlend = false;
725+
isVertexColorBakedLighting = false;
725726
static_assert(sizeof remixapi_InstanceInfoBlendEXT == 96);
726727
}
727728
};

public/include/remix/remix_c.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
#define REMIXAPI_VERSION_MAJOR 0
5656
#define REMIXAPI_VERSION_MINOR 5
57-
#define REMIXAPI_VERSION_PATCH 1
57+
#define REMIXAPI_VERSION_PATCH 2
5858

5959

6060
// External
@@ -389,6 +389,7 @@ extern "C" {
389389
uint32_t dstAlphaBlendFactor;
390390
uint32_t alphaBlendOp;
391391
uint32_t writeMask;
392+
remixapi_Bool isVertexColorBakedLighting;
392393
} remixapi_InstanceInfoBlendEXT;
393394

394395
typedef struct remixapi_InstanceInfoObjectPickingEXT {

src/d3d9/d3d9_rtx_utils.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ namespace dxvk {
153153
const bool hasPositionT = d3d9State.vertexDecl != nullptr && d3d9State.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasPositionT);
154154
const bool hasColor0 = d3d9State.vertexDecl != nullptr && d3d9State.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor0);
155155
const bool hasColor1 = d3d9State.vertexDecl != nullptr && d3d9State.vertexDecl->TestFlag(D3D9VertexDeclFlag::HasColor1);
156-
const bool lighting = d3d9State.renderStates[D3DRS_LIGHTING] != 0 && !hasPositionT;
156+
const bool lighting = d3d9State.renderStates[D3DRS_LIGHTING] != 0 && !hasPositionT; // FFP lighting on only if not positionT
157157

158158
uint32_t diffuseSource = hasColor0 ? D3DMCS_COLOR1 : D3DMCS_MATERIAL;
159159
uint32_t specularSource = hasColor1 ? D3DMCS_COLOR2 : D3DMCS_MATERIAL;
@@ -218,8 +218,12 @@ namespace dxvk {
218218
m.alphaDstFactor = NormalizeFactor(m.alphaDstFactor);
219219

220220
materialData.d3dMaterial = d3d9State.material;
221+
222+
// Allow the users to configure vertex color as baked lighting for legacy draw calls.
223+
materialData.isVertexColorBakedLighting = RtxOptions::vertexColorIsBakedLighting();
221224
}
222225

226+
223227
void setFogState(D3D9DeviceEx* pDevice, FogState& fogState) {
224228
const Direct3DState9& d3d9State = *pDevice->GetRawState();
225229

src/d3d9/d3d9_vertex_declaration.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace dxvk {
1414
HasPointSize,
1515
HasFog,
1616
HasBlendWeight,
17-
HasBlendIndices
17+
HasBlendIndices,
1818
};
1919
using D3D9VertexDeclFlags = Flags<D3D9VertexDeclFlag>;
2020

src/dxvk/rtx_render/rtx_context.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1190,7 +1190,6 @@ namespace dxvk {
11901190

11911191
constants.uniformRandomNumber = jenkinsHash(constants.frameIdx);
11921192
constants.vertexColorStrength = RtxOptions::vertexColorStrength();
1193-
constants.vertexColorIsBakedLighting = RtxOptions::vertexColorIsBakedLighting();
11941193
constants.viewModelRayTMax = RtxOptions::ViewModel::rangeMeters() * RtxOptions::getMeterToWorldUnitScale();
11951194
constants.roughnessDemodulationOffset = m_common->metaDemodulate().demodulateRoughnessOffset();
11961195

src/dxvk/rtx_render/rtx_game_capturer.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ namespace dxvk {
9898
meta.textureAlphaOperation = (uint32_t) rtInstance.surface.textureAlphaOperation;
9999
meta.tFactor = rtInstance.surface.tFactor;
100100
meta.isTextureFactorBlend = rtInstance.surface.isTextureFactorBlend;
101+
meta.isVertexColorBakedLighting = rtInstance.surface.isVertexColorBakedLighting;
101102
return meta;
102103
}
103104

src/dxvk/rtx_render/rtx_instance_manager.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,6 +1049,7 @@ namespace dxvk {
10491049
currentInstance.surface.isAnimatedWater = currentInstance.testCategoryFlags(InstanceCategories::AnimatedWater);
10501050
currentInstance.surface.associatedGeometryHash = drawCall.getHash(RtxOptions::geometryAssetHashRule());
10511051
currentInstance.surface.isTextureFactorBlend = drawCall.getMaterialData().isTextureFactorBlend;
1052+
currentInstance.surface.isVertexColorBakedLighting = drawCall.getMaterialData().isVertexColorBakedLighting;
10521053
currentInstance.surface.isMotionBlurMaskOut = currentInstance.testCategoryFlags(InstanceCategories::IgnoreMotionBlur);
10531054
currentInstance.surface.ignoreTransparencyLayer = currentInstance.testCategoryFlags(InstanceCategories::IgnoreTransparencyLayer);
10541055

src/dxvk/rtx_render/rtx_materials.h

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ struct RtSurface {
9999
writeGPUHelperExplicit<2>(data, offset, indexBufferIndex);
100100
writeGPUHelperExplicit<2>(data, offset, color0BufferIndex);
101101

102-
writeGPUHelperExplicit<1>(data, offset, normalFormat == VK_FORMAT_R32_UINT ? 1 : 0);
102+
uint16_t flags0 = 0;
103+
flags0 |= normalFormat == VK_FORMAT_R32_UINT ? 1 : 0;
104+
flags0 |= isVertexColorBakedLighting ? (1 << 1) : 0;
105+
// NOTE: Spare flags bits here
103106

104-
// 1 unused bytes here.
105-
writeGPUPadding<1>(data, offset);
107+
writeGPUHelper(data, offset, flags0);
106108

107109
const uint16_t packedHash =
108110
(uint16_t) (associatedGeometryHash >> 48) ^
@@ -131,32 +133,32 @@ struct RtSurface {
131133
assert(static_cast<uint32_t>(alphaState.alphaTestReferenceValue) < (1 << 8));
132134
assert(static_cast<uint32_t>(alphaState.blendType) < (1 << 4));
133135

134-
uint32_t flags = 0;
136+
uint32_t flags1 = 0;
135137

136-
flags |= isEmissive ? (1 << 0) : 0;
137-
flags |= alphaState.isFullyOpaque ? (1 << 1) : 0;
138-
flags |= isStatic ? (1 << 2) : 0;
139-
flags |= static_cast<uint32_t>(alphaState.alphaTestType) << 3;
138+
flags1 |= isEmissive ? (1 << 0) : 0;
139+
flags1 |= alphaState.isFullyOpaque ? (1 << 1) : 0;
140+
flags1 |= isStatic ? (1 << 2) : 0;
141+
flags1 |= static_cast<uint32_t>(alphaState.alphaTestType) << 3;
140142
// Note: No mask needed as masking of this value to be 8 bit is done elsewhere.
141-
flags |= static_cast<uint32_t>(alphaState.alphaTestReferenceValue) << 6;
142-
flags |= static_cast<uint32_t>(alphaState.blendType) << 14;
143-
flags |= alphaState.invertedBlend ? (1 << 18) : 0;
144-
flags |= alphaState.isBlendingDisabled ? (1 << 19) : 0;
145-
flags |= alphaState.emissiveBlend ? (1 << 20) : 0;
146-
flags |= alphaState.isParticle ? (1 << 21) : 0;
147-
flags |= alphaState.isDecal ? (1 << 22) : 0;
148-
flags |= hasMaterialChanged ? (1 << 23) : 0;
149-
flags |= isAnimatedWater ? (1 << 24) : 0;
150-
flags |= isClipPlaneEnabled ? (1 << 25) : 0;
151-
flags |= isMatte ? (1 << 26) : 0;
152-
flags |= isTextureFactorBlend ? (1 << 27) : 0;
153-
flags |= isMotionBlurMaskOut ? (1 << 28) : 0;
154-
flags |= skipSurfaceInteractionSpritesheetAdjustment ? (1 << 29) : 0;
155-
flags |= ignoreTransparencyLayer ? (1 << 30) : 0;
143+
flags1 |= static_cast<uint32_t>(alphaState.alphaTestReferenceValue) << 6;
144+
flags1 |= static_cast<uint32_t>(alphaState.blendType) << 14;
145+
flags1 |= alphaState.invertedBlend ? (1 << 18) : 0;
146+
flags1 |= alphaState.isBlendingDisabled ? (1 << 19) : 0;
147+
flags1 |= alphaState.emissiveBlend ? (1 << 20) : 0;
148+
flags1 |= alphaState.isParticle ? (1 << 21) : 0;
149+
flags1 |= alphaState.isDecal ? (1 << 22) : 0;
150+
flags1 |= hasMaterialChanged ? (1 << 23) : 0;
151+
flags1 |= isAnimatedWater ? (1 << 24) : 0;
152+
flags1 |= isClipPlaneEnabled ? (1 << 25) : 0;
153+
flags1 |= isMatte ? (1 << 26) : 0;
154+
flags1 |= isTextureFactorBlend ? (1 << 27) : 0;
155+
flags1 |= isMotionBlurMaskOut ? (1 << 28) : 0;
156+
flags1 |= skipSurfaceInteractionSpritesheetAdjustment ? (1 << 29) : 0;
157+
flags1 |= ignoreTransparencyLayer ? (1 << 30) : 0;
156158
// Note: This flag is purely for debug view purpose. If we need to add more functional flags and running out of bits, we should move this flag to other place.
157-
flags |= isInsideFrustum ? (1 << 31) : 0;
159+
flags1 |= isInsideFrustum ? (1 << 31) : 0;
158160

159-
writeGPUHelper(data, offset, flags);
161+
writeGPUHelper(data, offset, flags1);
160162

161163
// Note: Matricies are stored on the cpu side in column-major order, the same as the GPU.
162164

@@ -289,6 +291,7 @@ struct RtSurface {
289291
bool isAnimatedWater = false;
290292
bool isClipPlaneEnabled = false;
291293
bool isTextureFactorBlend = false;
294+
bool isVertexColorBakedLighting = false;
292295
bool isMotionBlurMaskOut = false;
293296
bool skipSurfaceInteractionSpritesheetAdjustment = false;
294297
bool isInsideFrustum = false;
@@ -1597,6 +1600,7 @@ struct LegacyMaterialData {
15971600
uint32_t tFactor = 0xffffffff; // Value for D3DRS_TEXTUREFACTOR, default value of is opaque white
15981601
D3DMATERIAL9 d3dMaterial = {};
15991602
bool isTextureFactorBlend = false;
1603+
bool isVertexColorBakedLighting = false;
16001604

16011605
void setHashOverride(XXH64_hash_t hash) {
16021606
m_cachedHash = hash;

0 commit comments

Comments
 (0)