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

Method CacheLightInformation

Rendering/WebGPU/vtkWebGPULight.cxx:22–97  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

20
21//------------------------------------------------------------------------------
22void vtkWebGPULight::CacheLightInformation(vtkRenderer* renderer, vtkCamera* camera)
23{
24 // Init the cache with right information
25 LightInfo& li = this->CachedLightInfo;
26 std::memset(&li.Pad, 0, sizeof(li.Pad));
27 li.Type = this->LightType;
28 li.Color[0] = { static_cast<vtkTypeFloat32>(this->DiffuseColor[0] * this->Intensity) };
29 li.Color[1] = { static_cast<vtkTypeFloat32>(this->DiffuseColor[1] * this->Intensity) };
30 li.Color[2] = { static_cast<vtkTypeFloat32>(this->DiffuseColor[2] * this->Intensity) };
31 li.Positional = 0;
32 li.ConeAngle = 0;
33 li.Exponent = 0;
34 std::memset(&li.DirectionVC, 0, sizeof(li.DirectionVC));
35 std::memset(&li.PositionVC, 0, sizeof(li.PositionVC));
36 std::memset(&li.Attenuation, 0, sizeof(li.Attenuation));
37
38 auto wgpuRenderer = reinterpret_cast<vtkWebGPURenderer*>(renderer);
39 if (wgpuRenderer->GetLightingComplexity() >=
40 vtkWebGPURenderer::LightingComplexityEnum::Directional)
41 {
42 // for lightkit case there are some parameters to set
43 vtkTransform* viewTF = camera->GetModelViewTransformObject();
44 // get required info from light
45 double* lfp = this->GetTransformedFocalPoint();
46 double* lp = this->GetTransformedPosition();
47 double lightDir[3];
48 vtkMath::Subtract(lfp, lp, lightDir);
49 vtkMath::Normalize(lightDir);
50 double tDirView[3];
51 viewTF->TransformNormal(lightDir, tDirView);
52
53 if (!this->LightTypeIsSceneLight() && wgpuRenderer->GetUserLightTransform() != nullptr)
54 {
55 double* tDir = wgpuRenderer->GetUserLightTransform()->TransformNormal(tDirView);
56 li.DirectionVC[0] = tDir[0];
57 li.DirectionVC[1] = tDir[1];
58 li.DirectionVC[2] = tDir[2];
59 }
60 else
61 {
62 // for lightkit case there are some parameters to set
63 li.DirectionVC[0] = tDirView[0];
64 li.DirectionVC[1] = tDirView[1];
65 li.DirectionVC[2] = tDirView[2];
66 }
67
68 // we are done unless we have positional lights
69 if (wgpuRenderer->GetLightingComplexity() >=
70 vtkWebGPURenderer::LightingComplexityEnum::Positional)
71 {
72 // if positional lights pass down more parameters
73 double* attn = this->AttenuationValues;
74 li.Attenuation[0] = attn[0];
75 li.Attenuation[1] = attn[1];
76 li.Attenuation[2] = attn[2];
77 double tlpView[3];
78 viewTF->TransformPoint(lp, tlpView);
79 if (!this->LightTypeIsSceneLight() && wgpuRenderer->GetUserLightTransform() != nullptr)

Callers 1

RenderMethod · 0.95

Calls 8

LightTypeIsSceneLightMethod · 0.80
SubtractFunction · 0.50
NormalizeFunction · 0.50
GetUserLightTransformMethod · 0.45
TransformPointMethod · 0.45

Tested by

no test coverage detected