ValveSoftware / ValveSoftware/source-sdk-2013

$detailblendfactor is not respected by UnlitGeneric material shader

Open
#1,975 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C++
Stars
10k
Forks
3k
Avg merge
8d 11h
Merged PRs (30d)
2

Description

Currently, most of the $detailblendmode options work with the UnlitGeneric shader except for one serious problem: $detailblendfactor is permanently stuck at 0 regardless of what's programmed into the VMT.

The issue stems from the fact that UnlitGeneric and VertexLitGeneric both rely on the same helper code to set $detailblendfactor:
https://github.com/ValveSoftware/source-sdk-2013/blob/88fa198fba3fb85d46d4c95018254693fdc3af0a/src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp#L1214

As you can see above, $selfillumtint and $detailblendfactor share the same register, with the first three channels being utilized by $selfillumtint and the final channel being utilized by $detailblendfactor. This is a problem because $selfillumtint is hardcoded to -1 in the UnlitGeneric shader, which in turn causes the write for BOTH components of the register's channels to be skipped

It looks to me like full funtionality of $detailblendmode in UnlitGeneric can be restored by simply guarding against this -1 condition and instead writing white to the $selfillumtint channels rather than the current behavior of discarding everything. The shader never actually accesses those channels, so it seems completely safe to do so:

if ( info.m_nSelfIllumTint != -1 )
{
      pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant_W( 4, info.m_nSelfIllumTint, fBlendFac
}
else
{
      pContextData->m_SemiStaticCmdsOut.SetPixelShaderConstant4( 4, 1.0f, 1.0f, 1.0f, fBlendFactor );
}

This fix would be extremely nice to have for usecases like mine (drawing abstract 3D visualizations from VScript). Visualizations like these can greatly benefit from utilizing smooth two-texture blend effects, but currently that's impossible without the extremely undesirable world lighting that VertexLitGeneric imposes.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in src/materialsystem/stdshaders/vertexlitgeneric_dx9_helper.cpp around line 1214, where UnlitGeneric and VertexLitGeneric set the shared self-illumination and detail-blend constant. Trace how UnlitGeneric supplies the -1 self-illumination value, then verify the helper preserves the detail blend factor while leaving unused self-illumination channels valid. Done means UnlitGeneric honors $detailblendfactor and its detail blend modes remain functional.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
72/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.