Skip to content

Fix IOR/refractionIndex being ignored in materials#8311

Merged
mvaligursky merged 1 commit into
mainfrom
mv-refraction-ior-fix
Dec 24, 2025
Merged

Fix IOR/refractionIndex being ignored in materials#8311
mvaligursky merged 1 commit into
mainfrom
mv-refraction-ior-fix

Conversation

@mvaligursky

@mvaligursky mvaligursky commented Dec 23, 2025

Copy link
Copy Markdown
Contributor

Fix IOR/refractionIndex being ignored in materials

Summary

Fixes #6911

This PR fixes an issue where custom refractionIndex values were being ignored in materials, causing all IOR rows to appear identical in transmission tests.

Changes

Bug Fix: Inverted equalish logic

The equalish checks for refractionTint, refractionIndexTint, and iorTint were inverted. The equalish function returns true when values are approximately equal, but the logic needed true when values differ from the default (to enable the shader uniform).

Before: When refractionIndex differed from the default, the shader used the hardcoded default value, ignoring the user's setting.

After: When refractionIndex differs from the default, the STD_IOR_CONSTANT define is set and the user's value is correctly passed to the shader.

Safety: Clamp refractionIndex to avoid division by zero

Added clamping to refractionIndex uniform (minimum 0.001) to prevent infinity when calculating f0 = 1.0 / litArgs_ior in the shader.

New Example

Added transmission-roughness.example.mjs using the Khronos TransmissionRoughnessTest.glb model to demonstrate and verify correct IOR/roughness interaction.

Reference image
image

PlayCanvas before (all rows are the same, ior is ignored)
before

PlayCanvas now
now

@mvaligursky mvaligursky merged commit 69ab982 into main Dec 24, 2025
7 checks passed
@mvaligursky mvaligursky deleted the mv-refraction-ior-fix branch December 24, 2025 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: graphics Graphics related issue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

f0 will be infinity when refractionIndex is zero

2 participants