Skip to content

Grass: light each bush by its own terrain normal again - #28

Merged
ivan-ushakov merged 1 commit into
crossplatformfrom
fix/grass-normal
Jul 26, 2026
Merged

Grass: light each bush by its own terrain normal again#28
ivan-ushakov merged 1 commit into
crossplatformfrom
fix/grass-normal

Conversation

@ivan-ushakov

Copy link
Copy Markdown
Collaborator

No description provided.

ColorByNormalRGBA lived in Render/D3D/D3DRenderTexture.cpp and went out of the
build with the D3D9 backend, leaving a no-op that returned 0xffffffff. It is not
a D3D function -- it is pure math -- and GrassMap::BuildGrass calls it for real:

	bush.normal.RGBA() = ColorByNormalRGBA(normal);

so every bush on every map got a packed normal of (255,255,255), which
grass.vert.hlsl unbiases to (1,1,1) and feeds to

	ndl = -dot(normal.xyz * 2 - 1, LightDirection.xyz)

One constant light term for the whole grass layer, no matter what the blade was
standing on. Only the RGB was affected: BuildGrass overwrites normal.a with the
blade intensity on the next line, so per-blade brightness was always right.

Restores the original body. Verified under lldb against C2_M08 -- the packing
matches round((n+1)*127.5) on flat ground (normal (0,0,0.998) -> 0x8080ff) and on
slopes ((0.221,0.414,0.883) -> 0x9cb4f0, (0.266,0.452,0.851) -> 0xa1b9ec), and
the unpack end is already correct: NORMAL is declared D3DDECLTYPE_D3DCOLOR, the
same type as COLOR0, which the shader reads with the same .bgra swizzle and which
visibly carries the right terrain colour.

The visible change is modest with the sun overhead, which is where C2_M08 starts:
light dir (0.069, 0, -0.996) puts flat ground at 0.996 where it used to be 0.927,
and a 25-degree slope at 0.864. The error the stub introduced on flat ground is
exactly the sun's horizontal component, so it grows toward dawn and dusk.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
@ivan-ushakov
ivan-ushakov merged commit baf8d11 into crossplatform Jul 26, 2026
4 checks passed
@ivan-ushakov
ivan-ushakov deleted the fix/grass-normal branch July 26, 2026 06:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant