Skip to content

fix(hair): remove inner gamma conversion#1338

Merged
alandtse merged 2 commits into
community-shaders:devfrom
jiayev:hair_dualspecular
Jul 31, 2025
Merged

fix(hair): remove inner gamma conversion#1338
alandtse merged 2 commits into
community-shaders:devfrom
jiayev:hair_dualspecular

Conversation

@jiayev
Copy link
Copy Markdown
Collaborator

@jiayev jiayev commented Jul 30, 2025

Summary by CodeRabbit

  • Refactor
    • Adjusted hair lighting calculations by removing certain gamma correction steps for improved consistency in specular highlights.
    • Improved specular ambient occlusion rendering by refining light reflection calculations for more accurate visual effects.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 30, 2025

Walkthrough

This change removes the application of gamma correction (Color::LinearToGamma) to two specular-related variables within the Marschner hair lighting model in the shader code. Additionally, it modifies the SpecularAOLagarde function to apply an absolute value to the sum of NdotV and ao before exponentiation. No other logic, control flow, or error handling is altered.

Changes

Cohort / File(s) Change Summary
Hair Specular Gamma Correction Removal
features/Hair Specular/Shaders/Hair/Hair.hlsli
Removed Color::LinearToGamma calls from Marschner model specular variables in two functions.
Specular Ambient Occlusion Adjustment
package/Shaders/Common/PBR.hlsli
Modified SpecularAOLagarde to use abs(NdotV + ao) before exponentiation to ensure non-negative input.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • doodlum
  • alandtse

Poem

A bunny hopped through lines of light,
Tweaked the Marschner code just right.
No gamma now for specular’s gleam,
The hair shines pure, or so it seems!
With whiskers twitching, shaders run—
Another code review, another job well done!
🐇✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc8ed7c and b14dcd4.

📒 Files selected for processing (1)
  • package/Shaders/Common/PBR.hlsli (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📓 Common learnings
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-05T05:20:45.823Z
Learning: In the skyrim-community-shaders repository, file deletion error handling improvements that replace existence checks and try-catch blocks with std::filesystem::remove error-code-based approaches are considered bug fixes rather than refactoring, as they address inadequate error handling and misleading log messages.
Learnt from: alandtse
PR: doodlum/skyrim-community-shaders#577
File: features/Wetness Effects/Shaders/WetnessEffects/WetnessEffects.hlsli:57-61
Timestamp: 2025-06-17T05:40:22.785Z
Learning: Default parameter values are supported in the HLSL compiler used by the skyrim-community-shaders project, contrary to standard HLSL (FXC/DXC) limitations.
Learnt from: jiayev
PR: doodlum/skyrim-community-shaders#0
File: :0-0
Timestamp: 2025-07-18T15:21:03.641Z
Learning: In the skyrim-community-shaders rendering pipeline, materials with alpha < 1 or alpha blending enabled are rendered in non-deferred mode rather than deferred mode. This means issues with dynamic cubemaps on transparent materials are actually non-deferred rendering issues.
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Validate shader compilation (Flatrim, .github/configs/shader-validation.yaml)
  • GitHub Check: Build plugin and addons
  • GitHub Check: Validate shader compilation (VR, .github/configs/shader-validation-vr.yaml)
🔇 Additional comments (1)
package/Shaders/Common/PBR.hlsli (1)

150-150: Confirm Numeric Stability and Formula Alignment

The addition of abs() around NdotV + ao on line 150 is a solid fix to prevent negative bases in pow(), avoiding NaNs or undefined behavior. However, the original Lagarde et al. specular-AO formula uses a clamp of (AO + max(N·V,0)) / (1 + max(N·V,0)) rather than an exponential approximation.

Please confirm:

  • That the pow(abs(NdotV + ao), exp2(-16.0 * roughness - 1.0)) - 1.0 + ao form is an intentional approximation distinct from the paper’s clamp-based equation.
  • That applying abs() does not noticeably diverge from your visual targets or introduce unintended artifacts in low-light or high-roughness scenarios.

File: package/Shaders/Common/PBR.hlsli
Line 150:

return saturate(
    pow(abs(NdotV + ao), exp2(-16.0 * roughness - 1.0))
    - 1.0
    + ao
);
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

Using provided base ref: 3d4e996
Using base ref: 3d4e996
Base commit date: 2025-07-30T14:31:29+08:00 (Wednesday, July 30, 2025 02:31 PM)
No actionable suggestions for changed features.

@github-actions
Copy link
Copy Markdown

✅ A pre-release build is available for this PR:
Download

@alandtse alandtse merged commit 284de5a into community-shaders:dev Jul 31, 2025
15 checks passed
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.

2 participants