Skip to content

feat: vanilla fresnel - #2332

Open
jiayev wants to merge 57 commits into
community-shaders:devfrom
jiayev:vanilla-fresnel-2
Open

feat: vanilla fresnel#2332
jiayev wants to merge 57 commits into
community-shaders:devfrom
jiayev:vanilla-fresnel-2

Conversation

@jiayev

@jiayev jiayev commented May 12, 2026

Copy link
Copy Markdown
Collaborator

This pull request introduces a new "Vanilla Fresnel" feature, providing advanced Fresnel and GGX-based physically-based rendering (PBR) specular reflection options, with extensive configurability and integration throughout the shader pipeline. The changes add new settings, update data structures, and modify lighting calculations in both general and grass-specific shaders to support these features. Additionally, the feature is integrated into the engine's feature management and configuration systems.

Major new feature: Vanilla Fresnel

  • Added a new VanillaFresnel feature with configurable settings (GGX specular, dynamic cubemap conversion, eye handling, etc.), UI controls, and serialization support (src/Features/VanillaFresnel.cpp, features/Vanilla Fresnel/Shaders/Features/VanillaFresnel.ini). [1] [2]

Shader pipeline and lighting model updates

  • Integrated Vanilla Fresnel settings into the shared shader data (SharedData::VanillaFresnelSettings), and updated the buffer to include these settings (package/Shaders/Common/SharedData.hlsli, src/FeatureBuffer.cpp). [1] [2] [3]
  • Modified main lighting evaluation to use GGX microfacet specular when enabled, with dynamic cubemap support and special handling for eyes and complex materials (package/Shaders/Lighting.hlsl, package/Shaders/Common/LightingEval.hlsli). [1] [2] [3] [4] [5] [6] [7]
  • Added a microfacet GGX specular calculation function and conditional logic to switch between Phong and GGX models (package/Shaders/Common/LightingEval.hlsli).

Grass lighting improvements

  • Updated grass lighting to support Vanilla Fresnel and GGX specular, with correct F0 and roughness parameter handling, and reflectance output (features/Grass Lighting/Shaders/GrassLighting/GrassLighting.hlsli, package/Shaders/RunGrass.hlsl). [1] [2] [3] [4] [5] [6]

Engine integration

  • Registered the new feature in the engine's feature list and included its settings in the feature buffer (src/Feature.cpp, src/FeatureBuffer.cpp). [1] [2] [3]

These changes collectively enable a more physically-accurate and configurable specular reflection model, improving visual fidelity and user control over rendering behavior.

Summary by CodeRabbit

  • New Features

    • Added "Vanilla Fresnel" feature with optional GGX microfacet specular, persistent settings and UI, tunable F0/roughness, auto cubemap conversion and special handling for eye passes.
    • Grass rendering now always outputs a Reflectance target and uses roughness-driven specular/reflectance values.
  • Bug Fixes / Behavior

    • Adjusted lighting pipeline: specular and environment accumulation/weighting change when Vanilla Fresnel or GGX-on-grass is enabled to preserve visual consistency.

@coderabbitai

coderabbitai Bot commented May 12, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Adds a VanillaFresnel feature with runtime settings and UI, exposes settings to shaders, implements GGX microfacet specular helpers and a VANILLA_FRESNEL lighting path, updates material/env handling in Lighting.hlsl, and switches grass rendering to use roughness and F0 for specular/reflectance.

Changes

Vanilla Fresnel Feature

Layer / File(s) Summary
VanillaFresnel Feature Definition & Registration
src/Features/VanillaFresnel.h, src/Features/VanillaFresnel.cpp, features/Vanilla Fresnel/Shaders/Features/VanillaFresnel.ini, src/Globals.h, src/Globals.cpp, src/Feature.cpp, src/FeatureBuffer.cpp
New VanillaFresnel feature type with nested Settings, JSON serialization, ImGui settings UI, global feature instance and registration, and feature-buffer serialization integration.
Shader Constant Buffer & Permutation/State Flags
package/Shaders/Common/SharedData.hlsli, package/Shaders/Common/Permutation.hlsli, src/State.h
Adds VanillaFresnelSettings to SharedData::FeatureData for shader access and introduces an IsEye extra-flag in shader permutation/state descriptors for eye-specific handling.
BRDF Microfacet Specular & LightingEval Integration
package/Shaders/Common/LightingEval.hlsli
Adds MicrofacetSpecular computing GGX D, Smith joint-approx G, and Schlick F; EvaluateLighting gains a VANILLA_FRESNEL branch using that helper with compensation/scaling and early return.
Grass Lighting Interface & Implementation
features/Grass Lighting/Shaders/GrassLighting/GrassLighting.hlsli, package/Shaders/RunGrass.hlsl, features/Grass Lighting/Shaders/Features/GrassLighting.ini
Changes GetLightSpecularInput signature to accept roughness and F0, adds an optional GGX-on-grass BRDF path and legacy exponential fallback, computes F0/roughness in RunGrass, always emits Reflectance for grass path, and updates specular accumulation calls.
Main Lighting Material & Environment Properties
package/Shaders/Lighting.hlsl
Conditions material F0/roughness setup and complex-specular handling on VANILLA_FRESNEL and runtime flags; adds EnableDynamicCubemapsConversion, envMask-weighted F0/roughness interpolation and clamps, and adjusts indirect/specular accumulation to avoid double-counting under vanilla Fresnel modes.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • doodlum
  • alandtse
  • SkrubbySkrubInAShrub

Poem

I nibble at the shader code tonight,
GGX facets catch the morning light,
F0 and roughness tuned just right,
Grass glints where tiny pixels gleam,
A rabbit hops beneath the fresnel beam. 🐇

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 9.52% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat: vanilla fresnel' directly and clearly matches the primary objective of this PR, which is to add a new VanillaFresnel feature to the codebase. It accurately summarizes the main change.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

@jiayev
jiayev marked this pull request as ready for review June 1, 2026 17:29
@SkrubbySkrubInAShrub

Copy link
Copy Markdown
Collaborator

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jun 2, 2026

Copy link
Copy Markdown
Contributor
✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
src/Features/VanillaFresnel.cpp (1)

66-74: ⚡ Quick win

Honor the runtime toggles before setting the eye permutation bit.

UpdateEyePermutation() always does the eye-pass detection work, so the new eye-specific permutation split stays active even when Vanilla Fresnel or eye special handling is turned off. Please clear the bit and return early unless the feature is enabled through globals::features. As per coding guidelines, "Flag potential performance impacts on rendering performance when implementing graphics features and suggest user toggles for feature control" and "Access core systems and feature registry through globals::features and globals::d3d namespaces defined in src/Globals.h".

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/Features/VanillaFresnel.cpp` around lines 66 - 74, Update
UpdateEyePermutation so it first checks the runtime feature toggle(s) in
globals::features (e.g., the Vanilla Fresnel / eye-special-handling flags) and,
if the feature is disabled, clear the IsEyeDescriptor bit on
globals::state->permutationData.ExtraShaderDescriptor and return early; only
call IsEyePass and set the IsEyeDescriptor bit when the feature toggle is
enabled. This change touches UpdateEyePermutation, IsEyePass, IsEyeDescriptor
and globals::state->permutationData.ExtraShaderDescriptor and should ensure the
eye permutation split is only active when globals::features indicates it.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/Features/VanillaFresnel.cpp`:
- Around line 66-74: Update UpdateEyePermutation so it first checks the runtime
feature toggle(s) in globals::features (e.g., the Vanilla Fresnel /
eye-special-handling flags) and, if the feature is disabled, clear the
IsEyeDescriptor bit on globals::state->permutationData.ExtraShaderDescriptor and
return early; only call IsEyePass and set the IsEyeDescriptor bit when the
feature toggle is enabled. This change touches UpdateEyePermutation, IsEyePass,
IsEyeDescriptor and globals::state->permutationData.ExtraShaderDescriptor and
should ensure the eye permutation split is only active when globals::features
indicates it.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b242c771-4297-4a35-850c-ced402f99412

📥 Commits

Reviewing files that changed from the base of the PR and between e7bfd47 and 87351d0.

📒 Files selected for processing (13)
  • features/Grass Lighting/Shaders/Features/GrassLighting.ini
  • package/Shaders/Common/LightingEval.hlsli
  • package/Shaders/Common/Permutation.hlsli
  • package/Shaders/Common/SharedData.hlsli
  • package/Shaders/Lighting.hlsl
  • package/Shaders/RunGrass.hlsl
  • src/Feature.cpp
  • src/FeatureBuffer.cpp
  • src/Features/VanillaFresnel.cpp
  • src/Features/VanillaFresnel.h
  • src/Globals.cpp
  • src/Globals.h
  • src/State.h
✅ Files skipped from review due to trivial changes (3)
  • package/Shaders/Common/Permutation.hlsli
  • features/Grass Lighting/Shaders/Features/GrassLighting.ini
  • src/Globals.h
🚧 Files skipped from review as they are similar to previous changes (7)
  • src/FeatureBuffer.cpp
  • package/Shaders/Common/LightingEval.hlsli
  • package/Shaders/RunGrass.hlsl
  • src/Feature.cpp
  • package/Shaders/Common/SharedData.hlsli
  • src/Globals.cpp
  • package/Shaders/Lighting.hlsl

@doodlum

doodlum commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator

do not merge yet

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.

4 participants