Grass: light each bush by its own terrain normal again - #28
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.