Krita Source Code Documentation
Loading...
Searching...
No Matches
PhongPixelProcessor Class Reference

#include <phong_pixel_processor.h>

Public Member Functions

QVector< quint16 > IlluminatePixel ()
 
QVector< quint16 > IlluminatePixelFromHeightmap (quint32 posup, quint32 posdown, quint32 posleft, quint32 posright)
 
QVector< quint16 > IlluminatePixelFromNormalmap (qreal r, qreal g, qreal b)
 
void initialize (const KisPropertiesConfigurationSP config)
 
void normalizeHeightmap ()
 
 PhongPixelProcessor (quint32 pixelArea, const KisPropertiesConfigurationSP config)
 
void setLightVector (QVector3D light_vector)
 
 ~PhongPixelProcessor ()
 

Public Attributes

bool diffuseLightIsEnabled
 
Illuminant fastLight
 
Illuminant fastLight2
 
qreal Ia
 Total ambient light.
 
qreal Id
 Total diffuse light.
 
qreal Is
 Total specular light.
 
qreal Ka
 Ambient light coefficient.
 
qreal Kd
 Diffuse light coefficient.
 
qreal Ks
 Specular light coefficient.
 
QVector3D light_vector
 
QList< IlluminantlightSources
 Light sources to use (those disabled in the GUI are not present here)
 
QVector3D normal_vector
 
QVector< double > realheightmap
 
QVector3D reflection_vector
 
qreal shiny_exp
 Shinyness exponent.
 
quint8 size
 Size of this stuff.
 
bool specularLightIsEnabled
 
QVector3D vision_vector
 
QVector3D x_vector
 
QVector3D y_vector
 

Private Attributes

quint32 m_pixelArea
 

Detailed Description

Definition at line 25 of file phong_pixel_processor.h.

Constructor & Destructor Documentation

◆ PhongPixelProcessor()

PhongPixelProcessor::PhongPixelProcessor ( quint32 pixelArea,
const KisPropertiesConfigurationSP config )

Definition at line 12 of file phong_pixel_processor.cpp.

13{
14 m_pixelArea = pixelArea;
15 initialize(config);
16}
void initialize(const KisPropertiesConfigurationSP config)

References initialize(), and m_pixelArea.

◆ ~PhongPixelProcessor()

PhongPixelProcessor::~PhongPixelProcessor ( )

Definition at line 83 of file phong_pixel_processor.cpp.

84{
85
86}

Member Function Documentation

◆ IlluminatePixel()

QVector< quint16 > PhongPixelProcessor::IlluminatePixel ( )

Definition at line 115 of file phong_pixel_processor.cpp.

116{
117 qreal temp;
118 quint8 channel = 0;
119 const quint8 totalChannels = 3; // The 4th is alpha and we'll fill it with a nice 0xFFFF
120 qreal computation[] = {0, 0, 0};
121 QVector<quint16> finalPixel(4, 0xFFFF);
122
123 if (lightSources.size() == 0)
124 return finalPixel;
125
126 // PREPARE ALGORITHM HERE
127
128 for (int i = 0; i < size; i++) {
129 light_vector = lightSources.at(i).lightVector;
130
131 for (channel = 0; channel < totalChannels; channel++) {
132 Ia = lightSources.at(i).RGBvalue.at(channel) * Ka;
133 computation[channel] += Ia;
134 }
136 temp = Kd * QVector3D::dotProduct(normal_vector, light_vector);
137 for (channel = 0; channel < totalChannels; channel++) {
138 Id = lightSources.at(i).RGBvalue.at(channel) * temp;
139 if (Id < 0) Id = 0;
140 if (Id > 1) Id = 1;
141 computation[channel] += Id;
142 }
143 }
144
146 reflection_vector = (2 * pow(QVector3D::dotProduct(normal_vector, light_vector), shiny_exp)) * normal_vector - light_vector;
147 temp = Ks * QVector3D::dotProduct(vision_vector, reflection_vector);
148 for (channel = 0; channel < totalChannels; channel++) {
149 Is = lightSources.at(i).RGBvalue.at(channel) * temp;
150 if (Is < 0) Is = 0;
151 if (Is > 1) Is = 1;
152 computation[channel] += Is;
153 }
154 }
155 }
156
157 for (channel = 0; channel < totalChannels; channel++) {
158 if (computation[channel] > 1)
159 computation[channel] = 1;
160 if (computation[channel] < 0)
161 computation[channel] = 0;
162 }
163
164 //RGBA actually uses the BGRA order of channels, hence the disorder
165 finalPixel[2] = quint16(computation[0] * 0xFFFF);
166 finalPixel[1] = quint16(computation[1] * 0xFFFF);
167 finalPixel[0] = quint16(computation[2] * 0xFFFF);
168
169 return finalPixel;
170}
qreal Kd
Diffuse light coefficient.
qreal Ks
Specular light coefficient.
qreal shiny_exp
Shinyness exponent.
qreal Is
Total specular light.
qreal Ia
Total ambient light.
qreal Id
Total diffuse light.
qreal Ka
Ambient light coefficient.
quint8 size
Size of this stuff.
QList< Illuminant > lightSources
Light sources to use (those disabled in the GUI are not present here)

References diffuseLightIsEnabled, Ia, Id, Is, Ka, Kd, Ks, light_vector, lightSources, normal_vector, reflection_vector, shiny_exp, size, specularLightIsEnabled, and vision_vector.

◆ IlluminatePixelFromHeightmap()

QVector< quint16 > PhongPixelProcessor::IlluminatePixelFromHeightmap ( quint32 posup,
quint32 posdown,
quint32 posleft,
quint32 posright )

Definition at line 95 of file phong_pixel_processor.cpp.

96{
97 QVector<quint16> finalPixel(4, 0xFFFF);
98
99 if (lightSources.size() == 0)
100 return finalPixel;
101
102 // Algorithm begins, Phong Illumination Model
103 normal_vector.setX(- realheightmap[posright] + realheightmap[posleft]);
104 normal_vector.setY(- realheightmap[posup] + realheightmap[posdown]);
105 normal_vector.setZ(8);
106 normal_vector.normalize();
107
108 // PREPARE ALGORITHM HERE
109
110 finalPixel = IlluminatePixel();
111
112 return finalPixel;
113}
QVector< quint16 > IlluminatePixel()
QVector< double > realheightmap

References IlluminatePixel(), lightSources, normal_vector, and realheightmap.

◆ IlluminatePixelFromNormalmap()

QVector< quint16 > PhongPixelProcessor::IlluminatePixelFromNormalmap ( qreal r,
qreal g,
qreal b )

Definition at line 172 of file phong_pixel_processor.cpp.

173{
174 QVector<quint16> finalPixel(4, 0xFFFF);
175
176 if (lightSources.size() == 0)
177 return finalPixel;
178
179 // if ()
180 // Algorithm begins, Phong Illumination Model
181 normal_vector.setX(r*2-1.0);
182 normal_vector.setY(-(g*2-1.0));
183 normal_vector.setZ(b*2-1.0);
184 //normal_vector.normalize();
185
186 // PREPARE ALGORITHM HERE
187
188 finalPixel = IlluminatePixel();
189
190 return finalPixel;
191}

References IlluminatePixel(), lightSources, and normal_vector.

◆ initialize()

void PhongPixelProcessor::initialize ( const KisPropertiesConfigurationSP config)

Definition at line 18 of file phong_pixel_processor.cpp.

19{
20 // Basic, fundamental
21 normal_vector = QVector3D(0, 0, 1);
22 vision_vector = QVector3D(0, 0, 1);
23 x_vector = QVector3D(1, 0, 0);
24 y_vector = QVector3D(0, 1, 0);
25
26 // Mutable
27 light_vector = QVector3D(0, 0, 0);
28 reflection_vector = QVector3D(0, 0, 0);
29
30 //setLightVector(QVector3D(-8, 8, 2));
31
33 QVariant guiLight[PHONG_TOTAL_ILLUMINANTS];
34
35 qint32 azimuth;
36 qint32 inclination;
37
38 for (int i = 0; i < PHONG_TOTAL_ILLUMINANTS; i++) {
39 if (config->getBool(PHONG_ILLUMINANT_IS_ENABLED[i])) {
40 if (config->getProperty(PHONG_ILLUMINANT_COLOR[i], guiLight[i])) {
41 light[i].RGBvalue << guiLight[i].value<QColor>().redF();
42 light[i].RGBvalue << guiLight[i].value<QColor>().greenF();
43 light[i].RGBvalue << guiLight[i].value<QColor>().blueF();
44
45 azimuth = config->getInt(PHONG_ILLUMINANT_AZIMUTH[i]) - 90;
46 inclination = config->getInt(PHONG_ILLUMINANT_INCLINATION[i]);
47
48 qreal m; //2D vector magnitude
49 light[i].lightVector.setZ( sin( inclination * M_PI / 180 ) );
50 m = cos( inclination * M_PI / 180);
51
52 light[i].lightVector.setX( cos( azimuth * M_PI / 180 ) * m );
53 light[i].lightVector.setY( sin( azimuth * M_PI / 180 ) * m );
54 //Pay close attention to this, indexes will move in this line
55 lightSources.append(light[i]);
56 }
57 }
58 }
59
60 size = lightSources.size();
61
62 //Code that exists only to swiftly switch to the other algorithm (reallyFastIlluminatePixel) to test
63 if (size > 0) {
64 fastLight = light[0];
65 fastLight2 = light[0];
66 }
67
68 //Ka, Kd and Ks must be between 0 and 1 or grave errors will happen
69 Ka = config->getDouble(PHONG_AMBIENT_REFLECTIVITY);
70 Kd = config->getDouble(PHONG_DIFFUSE_REFLECTIVITY);
71 Ks = config->getDouble(PHONG_SPECULAR_REFLECTIVITY);
72 shiny_exp = config->getInt(PHONG_SHINYNESS_EXPONENT);
73
74 Ia = Id = Is = 0;
75
78
80}
#define M_PI
Definition kis_global.h:111
const QString PHONG_SPECULAR_REFLECTIVITY_IS_ENABLED
const QString PHONG_DIFFUSE_REFLECTIVITY_IS_ENABLED
const QString PHONG_ILLUMINANT_AZIMUTH[]
const QString PHONG_ILLUMINANT_INCLINATION[]
const QString PHONG_ILLUMINANT_COLOR[]
const quint8 PHONG_TOTAL_ILLUMINANTS
const QString PHONG_SHINYNESS_EXPONENT
const QString PHONG_DIFFUSE_REFLECTIVITY
const QString PHONG_ILLUMINANT_IS_ENABLED[]
const QString PHONG_SPECULAR_REFLECTIVITY
const QString PHONG_AMBIENT_REFLECTIVITY
QList< qreal > RGBvalue

References diffuseLightIsEnabled, fastLight, fastLight2, Ia, Id, Is, Ka, Kd, Ks, light_vector, lightSources, Illuminant::lightVector, M_PI, m_pixelArea, normal_vector, PHONG_AMBIENT_REFLECTIVITY, PHONG_DIFFUSE_REFLECTIVITY, PHONG_DIFFUSE_REFLECTIVITY_IS_ENABLED, PHONG_ILLUMINANT_AZIMUTH, PHONG_ILLUMINANT_COLOR, PHONG_ILLUMINANT_INCLINATION, PHONG_ILLUMINANT_IS_ENABLED, PHONG_SHINYNESS_EXPONENT, PHONG_SPECULAR_REFLECTIVITY, PHONG_SPECULAR_REFLECTIVITY_IS_ENABLED, PHONG_TOTAL_ILLUMINANTS, realheightmap, reflection_vector, Illuminant::RGBvalue, shiny_exp, size, specularLightIsEnabled, vision_vector, x_vector, and y_vector.

◆ normalizeHeightmap()

void PhongPixelProcessor::normalizeHeightmap ( )

◆ setLightVector()

void PhongPixelProcessor::setLightVector ( QVector3D light_vector)

Definition at line 89 of file phong_pixel_processor.cpp.

90{
91 lightVector.normalize();
92 light_vector = lightVector;
93}

References light_vector.

Member Data Documentation

◆ diffuseLightIsEnabled

bool PhongPixelProcessor::diffuseLightIsEnabled

Definition at line 80 of file phong_pixel_processor.h.

◆ fastLight

Illuminant PhongPixelProcessor::fastLight

Definition at line 77 of file phong_pixel_processor.h.

◆ fastLight2

Illuminant PhongPixelProcessor::fastLight2

Definition at line 78 of file phong_pixel_processor.h.

◆ Ia

qreal PhongPixelProcessor::Ia

Total ambient light.

Definition at line 57 of file phong_pixel_processor.h.

◆ Id

qreal PhongPixelProcessor::Id

Total diffuse light.

Definition at line 60 of file phong_pixel_processor.h.

◆ Is

qreal PhongPixelProcessor::Is

Total specular light.

Definition at line 63 of file phong_pixel_processor.h.

◆ Ka

qreal PhongPixelProcessor::Ka

Ambient light coefficient.

Definition at line 45 of file phong_pixel_processor.h.

◆ Kd

qreal PhongPixelProcessor::Kd

Diffuse light coefficient.

Definition at line 48 of file phong_pixel_processor.h.

◆ Ks

qreal PhongPixelProcessor::Ks

Specular light coefficient.

Definition at line 51 of file phong_pixel_processor.h.

◆ light_vector

QVector3D PhongPixelProcessor::light_vector

Definition at line 39 of file phong_pixel_processor.h.

◆ lightSources

QList<Illuminant> PhongPixelProcessor::lightSources

Light sources to use (those disabled in the GUI are not present here)

Definition at line 72 of file phong_pixel_processor.h.

◆ m_pixelArea

quint32 PhongPixelProcessor::m_pixelArea
private

Definition at line 84 of file phong_pixel_processor.h.

◆ normal_vector

QVector3D PhongPixelProcessor::normal_vector

Definition at line 36 of file phong_pixel_processor.h.

◆ realheightmap

QVector<double> PhongPixelProcessor::realheightmap

Definition at line 42 of file phong_pixel_processor.h.

◆ reflection_vector

QVector3D PhongPixelProcessor::reflection_vector

Definition at line 35 of file phong_pixel_processor.h.

◆ shiny_exp

qreal PhongPixelProcessor::shiny_exp

Shinyness exponent.

Definition at line 54 of file phong_pixel_processor.h.

◆ size

quint8 PhongPixelProcessor::size

Size of this stuff.

Definition at line 75 of file phong_pixel_processor.h.

◆ specularLightIsEnabled

bool PhongPixelProcessor::specularLightIsEnabled

Definition at line 81 of file phong_pixel_processor.h.

◆ vision_vector

QVector3D PhongPixelProcessor::vision_vector

Definition at line 40 of file phong_pixel_processor.h.

◆ x_vector

QVector3D PhongPixelProcessor::x_vector

Definition at line 37 of file phong_pixel_processor.h.

◆ y_vector

QVector3D PhongPixelProcessor::y_vector

Definition at line 38 of file phong_pixel_processor.h.


The documentation for this class was generated from the following files: