Skip to content

Commit eb4f983

Browse files
committed
select material index in new order 1. Henke Tables -> 2. Palik -> 3. Cromer.
1 parent 1a5b765 commit eb4f983

File tree

1 file changed

+27
-26
lines changed

1 file changed

+27
-26
lines changed

Intern/rayx-core/src/Shader/RefractiveIndex.cpp

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -113,32 +113,7 @@ complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const
113113
return complex::Complex(-1.0, -1.0);
114114
}
115115

116-
// try to get refractive index using Palik table
117-
if (getPalikEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
118-
int low = 0; // <= energy
119-
int high = getPalikEntryCount(material, materialIndices) - 1; // >= energy
120-
121-
PalikEntry low_entry = getPalikEntry(low, material, materialIndices, materialTable);
122-
PalikEntry high_entry = getPalikEntry(high, material, materialIndices, materialTable);
123-
124-
if (low_entry.m_energy <= energy && energy <= high_entry.m_energy) { // if 'energy' is in range of tha PalikTable
125-
// binary search
126-
while (high - low > 1) {
127-
int center = (low + high) / 2;
128-
PalikEntry center_entry = getPalikEntry(center, material, materialIndices, materialTable);
129-
if (energy < center_entry.m_energy) {
130-
high = center;
131-
} else {
132-
low = center;
133-
}
134-
}
135-
136-
PalikEntry entry = getPalikEntry(low, material, materialIndices, materialTable);
137-
return complex::Complex(entry.m_n, entry.m_k);
138-
}
139-
}
140-
141-
// get refractive index with Nff table
116+
// get refractive index with Nff table
142117
if (getNffEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
143118
int low = 0; // <= energy
144119
int high = getNffEntryCount(material, materialIndices) - 1; // >= energy
@@ -167,6 +142,32 @@ complex::Complex RAYX_API getRefractiveIndex(double energy, int material, const
167142
return complex::Complex(n, k);
168143
}
169144

145+
// try to get refractive index using Palik table
146+
if (getPalikEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
147+
int low = 0; // <= energy
148+
int high = getPalikEntryCount(material, materialIndices) - 1; // >= energy
149+
150+
PalikEntry low_entry = getPalikEntry(low, material, materialIndices, materialTable);
151+
PalikEntry high_entry = getPalikEntry(high, material, materialIndices, materialTable);
152+
153+
if (low_entry.m_energy <= energy && energy <= high_entry.m_energy) { // if 'energy' is in range of tha PalikTable
154+
// binary search
155+
while (high - low > 1) {
156+
int center = (low + high) / 2;
157+
PalikEntry center_entry = getPalikEntry(center, material, materialIndices, materialTable);
158+
if (energy < center_entry.m_energy) {
159+
high = center;
160+
} else {
161+
low = center;
162+
}
163+
}
164+
165+
PalikEntry entry = getPalikEntry(low, material, materialIndices, materialTable);
166+
return complex::Complex(entry.m_n, entry.m_k);
167+
}
168+
}
169+
170+
170171
// get refractive index with Cromer table
171172
if (getCromerEntryCount(material, materialIndices) > 0) { // don't try binary search if there are 0 entries!
172173
int low = 0; // <= energy

0 commit comments

Comments
 (0)