Inkscape
Vector Graphics Editor
Loading...
Searching...
No Matches
nr-light.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Light rendering helpers
4 *
5 * Author:
6 * Jean-Rene Reinhard <jr@komite.net>
7 *
8 * Copyright (C) 2006 Jean-Rene Reinhard
9 *
10 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
11 */
12
13#include <cmath>
14
15#include "display/nr-light.h"
16#include "display/nr-3dutils.h"
20#include "colors/color.h"
21
22namespace Inkscape {
23namespace Filters {
24
26{
27 color = lighting_color;
28 azimuth = M_PI / 180 * light.azimuth;
29 elevation = M_PI / 180 * light.elevation;
30}
31
33
35 v[X_3D] = std::cos(azimuth)*std::cos(elevation);
36 v[Y_3D] = std::sin(azimuth)*std::cos(elevation);
37 v[Z_3D] = std::sin(elevation);
38}
39
45
46PointLight::PointLight(PointLightData const &light, guint32 lighting_color, const Geom::Affine &trans, int device_scale) {
47 color = lighting_color;
48 l_x = light.x * device_scale;
49 l_y = light.y * device_scale;
50 l_z = light.z * device_scale;
51 NR::convert_coord(l_x, l_y, l_z, trans);
52}
53
54PointLight::~PointLight() = default;
55
56void PointLight::light_vector(NR::Fvector &v, double x, double y, double z) {
57 v[X_3D] = l_x - x;
58 v[Y_3D] = l_y - y;
59 v[Z_3D] = l_z - z;
61}
62
68
69SpotLight::SpotLight(SpotLightData const &light, guint32 lighting_color, const Geom::Affine &trans, int device_scale)
70{
71 double p_x, p_y, p_z;
72 color = lighting_color;
73 l_x = light.x * device_scale;
74 l_y = light.y * device_scale;
75 l_z = light.z * device_scale;
76 p_x = light.pointsAtX * device_scale;
77 p_y = light.pointsAtY * device_scale;
78 p_z = light.pointsAtZ * device_scale;
79 cos_lca = std::cos(M_PI / 180 * light.limitingConeAngle);
81 NR::convert_coord(l_x, l_y, l_z, trans);
82 NR::convert_coord(p_x, p_y, p_z, trans);
83 S[X_3D] = p_x - l_x;
84 S[Y_3D] = p_y - l_y;
85 S[Z_3D] = p_z - l_z;
87}
88
89SpotLight::~SpotLight() = default;
90
91void SpotLight::light_vector(NR::Fvector &v, double x, double y, double z) {
92 v[X_3D] = l_x - x;
93 v[Y_3D] = l_y - y;
94 v[Z_3D] = l_z - z;
96}
97
99 double spmod = (-1) * NR::scalar_product(L, S);
100 if (spmod <= cos_lca)
101 spmod = 0;
102 else
103 spmod = std::pow(spmod, speExp);
104 lc[LIGHT_RED] = spmod * SP_RGBA32_R_U(color);
105 lc[LIGHT_GREEN] = spmod * SP_RGBA32_G_U(color);
106 lc[LIGHT_BLUE] = spmod * SP_RGBA32_B_U(color);
107}
108
109} /* namespace Filters */
110} /* namespace Inkscape */
111
112/*
113 Local Variables:
114 mode:c++
115 c-file-style:"stroustrup"
116 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
117 indent-tabs-mode:nil
118 fill-column:99
119 End:
120*/
121// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
3x3 matrix representing an affine transformation.
Definition affine.h:70
void light_components(NR::Fvector &lc)
Computes the light components of the distant light.
Definition nr-light.cpp:40
void light_vector(NR::Fvector &v)
Computes the light vector of the distant light.
Definition nr-light.cpp:34
DistantLight(DistantLightData const &light, guint32 lighting_color)
Constructor.
Definition nr-light.cpp:25
void light_components(NR::Fvector &lc)
Computes the light components of the distant light.
Definition nr-light.cpp:63
PointLight(PointLightData const &light, guint32 lighting_color, const Geom::Affine &trans, int device_scale=1)
Constructor.
Definition nr-light.cpp:46
void light_vector(NR::Fvector &v, double x, double y, double z)
Computes the light vector of the distant light at point (x,y,z).
Definition nr-light.cpp:56
SpotLight(SpotLightData const &light, guint32 lighting_color, const Geom::Affine &trans, int device_scale=1)
Constructor.
Definition nr-light.cpp:69
void light_vector(NR::Fvector &v, double x, double y, double z)
Computes the light vector of the distant light at point (x,y,z).
Definition nr-light.cpp:91
void light_components(NR::Fvector &lc, const NR::Fvector &L)
Computes the light components of the distant light at the current point.
Definition nr-light.cpp:98
constexpr uint32_t SP_RGBA32_R_U(uint32_t v)
Definition utils.h:27
constexpr uint32_t SP_RGBA32_G_U(uint32_t v)
Definition utils.h:31
constexpr uint32_t SP_RGBA32_B_U(uint32_t v)
Definition utils.h:35
SVG <filter> implementation, see sp-filter.cpp.
unsigned int guint32
Helper class to stream background task notifications as a series of messages.
void normalize_vector(Fvector &v)
Normalizes a vector.
gdouble scalar_product(const Fvector &a, const Fvector &b)
Computes the scalar product between two Fvectors.
void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Affine const &trans)
TODO: insert short description here.
SVG <filter> implementation, see sp-filter.cpp.
SVG <filter> implementation, see sp-filter.cpp.
a type of 3 gdouble components vectors
Definition nr-3dutils.h:29