MCPcopy Create free account
hub / github.com/Kitware/VTK / BuildShadingTable

Method BuildShadingTable

Rendering/Volume/vtkEncodedGradientShader.cxx:363–537  ·  view source on GitHub ↗

Build a shading table for a light with the given direction and color, for a material of the given type. material[0] = ambient, material[1] = diffuse, material[2] = specular, material[3] = specular exponent. If the ambient flag is 1, then ambient illumination is added. If not, then this means we are calculating the "other side" of two sided lighting, so no ambient intensity is added in. If update_

Source from the content-addressed store, hash-verified

361// be handled. There is one shading table per volume, and the index
362// value indicates which index table is to be updated
363void vtkEncodedGradientShader::BuildShadingTable(int index, double lightDirection[3],
364 double lightAmbientColor[3], double lightDiffuseColor[3], double lightSpecularColor[3],
365 double lightIntensity, double viewDirection[3], double material[4], int twoSided,
366 vtkEncodedGradientEstimator* gradest, int updateFlag)
367{
368 double lx, ly, lz;
369 double n_dot_l;
370 double n_dot_v;
371 int i;
372 float* nptr;
373 float* sdr_ptr;
374 float* sdg_ptr;
375 float* sdb_ptr;
376 float* ssr_ptr;
377 float* ssg_ptr;
378 float* ssb_ptr;
379 double Ka, Es, Kd_intensity, Ks_intensity;
380 double half_x, half_y, half_z;
381 double mag, n_dot_h, specular_value;
382 int norm_size;
383
384 // Move to local variables
385 lx = lightDirection[0];
386 ly = lightDirection[1];
387 lz = lightDirection[2];
388
389 half_x = lx - viewDirection[0];
390 half_y = ly - viewDirection[1];
391 half_z = lz - viewDirection[2];
392
393 mag = sqrt(half_x * half_x + half_y * half_y + half_z * half_z);
394
395 if (mag != 0.0)
396 {
397 half_x /= mag;
398 half_y /= mag;
399 half_z /= mag;
400 }
401
402 Ka = material[0] * lightIntensity;
403 Es = material[3];
404 Kd_intensity = material[1] * lightIntensity;
405 Ks_intensity = material[2] * lightIntensity;
406
407 nptr = gradest->GetDirectionEncoder()->GetDecodedGradientTable();
408
409 norm_size = gradest->GetDirectionEncoder()->GetNumberOfEncodedDirections();
410
411 if (this->ShadingTableSize[index] != norm_size)
412 {
413 for (i = 0; i < 6; i++)
414 {
415 delete[] this->ShadingTable[index][i];
416 this->ShadingTable[index][i] = new float[norm_size];
417 }
418 this->ShadingTableSize[index] = norm_size;
419 }
420

Callers 1

UpdateShadingTableMethod · 0.95

Calls 4

sqrtFunction · 0.50
powFunction · 0.50

Tested by

no test coverage detected