MCPcopy Create free account
hub / github.com/carbonengine/trinity / UpdateSubSurfaceFrontScatterData

Method UpdateSubSurfaceFrontScatterData

trinity/Tr2SSSSS.cpp:187–268  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187void Tr2SSSSS::UpdateSubSurfaceFrontScatterData( Tr2RenderContext& renderContext )
188{
189
190 // FUTUREWORK this will be exposed via a "quality" setting
191 const int nSamples = 17;
192 std::array<Vector4, nSamples> kernel;
193
194 // Update front scattering kernal
195 {
196
197
198 const float RANGE = nSamples > 20 ? 3.0f : 2.0f;
199 const float EXPONENT = 2.0f;
200
201
202 // Calculate the offsets
203 float step = 2.0f * RANGE / ( nSamples - 1 );
204 for( int i = 0; i < nSamples; i++ )
205 {
206 float o = -RANGE + float( i ) * step;
207 float sign = o < 0.0f ? -1.0f : 1.0f;
208 kernel[i].w = RANGE * sign * abs( pow( o, EXPONENT ) ) / pow( RANGE, EXPONENT );
209 }
210
211 // Calculate the weights
212 for( int i = 0; i < nSamples; i++ )
213 {
214 float w0 = i > 0 ? abs( kernel[i].w - kernel[i - 1].w ) : 0.0f;
215 float w1 = i < nSamples - 1 ? abs( kernel[i].w - kernel[i + 1].w ) : 0.0f;
216 float area = ( w0 + w1 ) / 2.0f;
217 Vector3 t = profile( kernel[i].w ) * area;
218 kernel[i].x = t.x;
219 kernel[i].y = t.y;
220 kernel[i].z = t.z;
221 }
222
223
224 // We want the offset 0.0 to come first
225 Vector4 t = kernel[nSamples / 2];
226 for( int i = nSamples / 2; i > 0; i-- )
227 kernel[i] = kernel[i - 1];
228 kernel[0] = t;
229
230
231 // Calculate the sum of the weights, we will need to normalize them below
232 Vector3 sum = Vector3( 0.0f, 0.0f, 0.0f );
233 for( int i = 0; i < nSamples; i++ )
234 {
235 sum += Vector3( kernel[i].x, kernel[i].y, kernel[i].z );
236 }
237
238 // Normalize the weights
239 for( int i = 0; i < nSamples; i++ )
240 {
241 kernel[i].x /= sum.x;
242 kernel[i].y /= sum.y;
243 kernel[i].z /= sum.z;
244 }

Callers

nothing calls this directly

Calls 5

profileFunction · 0.85
Vector3Class · 0.70
MapForWritingMethod · 0.45
GetGpuBufferMethod · 0.45
UnmapForWritingMethod · 0.45

Tested by

no test coverage detected