ValveSoftware / ValveSoftware/source-sdk-2013

tangentSpaceTranspose matrix in lightmappedgeneric should be correct when TANGENTSPACE parameter is set to true and the material has no envMap or bumpMap

Open
#1,916 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

I'm currently working on adding an interior mapping shader to a source engine mod, using cubemaps, and tangent space. The interior cubemap is added as an extra texture to the lightmappedgeneric_dx9 pixel shader. To correctly translate our pixelToEye vector from world space to tangent space, I need the tangentSpaceTranspose calculated in the vertex shader. The vertex shader has a static parameter TANGENTSPACE, which when 1, calculates this matrix.

InteriorMapped brushes with the TANGENTSPACE parameter set to true and hasEnvMap bool in lightmappedgeneric_dx9_helper.cpp set to false.

InteriorMapped brushes with the TANGENTSPACE parameter set to true and hasEnvMap bool in lightmappedgeneric_dx9_helper.cpp set to false.

For the longest time i could not get this transformation to work, until I used the components of the matrix as colours and found out that the tangent and binormal are both 0 0 0. After some more experimenting I worked out that either passing a dummy bumpmap or dummy envmap (or setting hasBump or hasEnvMap in lightmapgeneric_dx9_helper.cpp to true, with the latter producing no errors far as I can tell), the tangent and binormal are finally correctly passed into the vertex shader.

InteriorMapped brushes with the TANGENTSPACE parameter set to true and hasEnvMap bool in lightmappedgeneric_dx9_helper.cpp set to true.

InteriorMapped brushes with the TANGENTSPACE parameter set to true and hasEnvMap bool in lightmappedgeneric_dx9_helper.cpp set to true.

I think this quirk in how the vertex shader does not receive the tangent and binormal when neither a bumpmap or envmap is present (or some other parameter I don't know about), and thus TANGENTSPACE calculates an incorrect tangentSpaceTranspose, could be better documented, either as a comment in the pixel and vertex shader, or via some new static parameter that sets the tangent and binormal correctly even without a bumpmap or envmap.

The shader was made with the help of this YouTube tutorial by Ben Cloward.

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 lightmappedgeneric_dx9_helper.cpp and the related vertex and pixel shaders. Reproduce with TANGENTSPACE enabled and no envMap or bumpMap, comparing the tangent and binormal inputs with the working case where hasEnvMap is true. Done means tangentSpaceTranspose receives correct tangent and binormal data without requiring a dummy texture or unrelated parameter.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
computer-graphics, game-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.