Skip to content

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

@AdamTadeusz

Description

@AdamTadeusz

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions