[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: =?utf-8?q?=5Bcalligra=5D_krita/ui=3A_Adding_new_widget_to_manipu?=
From: José_Luis_Vergara <pentalis () gmail ! com>
Date: 2011-06-30 20:39:10
Message-ID: 20110630203910.224E3A60C6 () git ! kde ! org
[Download RAW message or body]
Git commit 5ccf143e84440d52db9d79a9517a48ae2495b7e0 by José Luis Vergara.
Committed on 25/06/2011 at 21:09.
Pushed by jlvergara into branch 'master'.
Adding new widget to manipulate light sources useful for impasto and bumpmap, \
KisLightStage
M +2 -0 krita/ui/CMakeLists.txt
A +344 -0 krita/ui/widgets/kis_light_source.cpp [License: GPL (v2+)]
A +87 -0 krita/ui/widgets/kis_light_source.h [License: GPL (v2+)]
A +255 -0 krita/ui/widgets/kis_light_stage.cpp [License: GPL (v2+)]
A +58 -0 krita/ui/widgets/kis_light_stage.h [License: GPL (v2+)]
http://commits.kde.org/calligra/5ccf143e84440d52db9d79a9517a48ae2495b7e0
diff --git a/krita/ui/CMakeLists.txt b/krita/ui/CMakeLists.txt
index b8f49b5..d1615f4 100644
--- a/krita/ui/CMakeLists.txt
+++ b/krita/ui/CMakeLists.txt
@@ -165,6 +165,8 @@ set(kritaui_LIB_SRCS
widgets/kis_workspace_chooser.cpp
widgets/squeezedcombobox.cpp
widgets/kis_categorized_list_view.cpp
+ widgets/kis_light_source.cpp
+ widgets/kis_light_stage.cpp
)
if(HAVE_OPENGL)
diff --git a/krita/ui/widgets/kis_light_source.cpp \
b/krita/ui/widgets/kis_light_source.cpp new file mode 100644
index 0000000..8ed804e
--- /dev/null
+++ b/krita/ui/widgets/kis_light_source.cpp
@@ -0,0 +1,344 @@
+/*
+ * Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_light_source.h"
+
+// PUBLIC FUNCTIONS
+
+/*
+KisLightSource::KisLightSource(QWidget *parent = 0)
+ : QLabel(parent)
+{
+}
+*/
+//KisLightSource::KisLightSource(QColor color = QColor(0, 0, 0), qreal azimuth = 0, \
qreal altitude = 90, QWidget *parent = 0) +KisLightSource::KisLightSource(QColor \
color, qreal azimuth, qreal altitude, QWidget *parent) + : QLabel(parent)
+{
+ m_moving = false;
+
+ // Set basic properties
+ m_color = color;
+ m_azimuth = azimuth;
+ m_altitude = altitude;
+
+ // Deduce other properties from the basic set
+ qreal m; //2D vector magnitude
+ lightVector.setZ( sin( altitude * M_PI / 180 ) );
+ m = cos( altitude * M_PI / 180);
+
+ qDebug() << "m: " << m;
+ qDebug() << "orig Altitude: " << altitude;
+
+ // take the negative azimuth to make the spinning counterclockwise
+ // TODO BUG make it negative again
+ lightVector.setX( cos( azimuth * M_PI / 180 ) * m );
+ lightVector.setY( sin( azimuth * M_PI / 180 ) * m );
+
+ // Create background
+ m_icondiameter = 13;
+ m_selecthalothickness = 3;
+ setPixmap(createBackground());
+ resize(m_icondiameter, m_icondiameter);
+
+ m_center = QPointF(qreal(size().width()) / 2, qreal(size().height()) / 2);
+
+ RGBvalue << color.redF();
+ RGBvalue << color.greenF();
+ RGBvalue << color.blueF();
+
+ show();
+ if (parentWidget())
+ this->parentWidget()->update();
+
+ qDebug() << lightVector;
+}
+
+KisLightSource::~KisLightSource()
+{
+ this->parentWidget()->update();
+}
+
+
+void KisLightSource::mousePressEvent(QMouseEvent* event)
+{
+ QLabel::mousePressEvent(event);
+ dragStartPosition = event->globalPos();
+ m_moving = true;
+
+ // #1
+ m_selectedPosition = event->posF();
+ if (m_isselected)
+ m_selecting = false;
+ else
+ m_selecting = true;
+}
+
+void KisLightSource::mouseReleaseEvent(QMouseEvent* event)
+{
+ QLabel::mouseReleaseEvent(event);
+
+ m_moving = false;
+
+ if (m_selecting && dragStartPosition == event->globalPos()) {
+ select();
+ m_selecting = false;
+ } else if (dragStartPosition == event->globalPos()) {
+ deselect();
+ }
+}
+
+void KisLightSource::mouseMoveEvent(QMouseEvent* event)
+{
+ m_moving = true;
+ qreal newX = parentWidget()->mapFromGlobal(event->globalPos()).x();
+ qreal newY = parentWidget()->mapFromGlobal(event->globalPos()).y();
+ qreal newRelativeX = newX - qreal(parentWidget()->width() / 2);
+ qreal newRelativeY = newY - qreal(parentWidget()->height() / 2);
+
+ //Normalize
+ newRelativeX /= (parentWidget()->width() / 2);
+ newRelativeY /= (parentWidget()->height() / 2);
+
+ if (!(newRelativeX == 0 && newRelativeY == 0)) {
+ // TODO BUG reverse the symbols here later
+ m_azimuth = -atan2(newRelativeX, newRelativeY) + M_PI / 2; // In radians
+ m_azimuth *= (180 / M_PI); // To degrees
+ } else {
+ m_azimuth = 0;
+ }
+
+ //Pitagoras
+ qreal newM = sqrt(pow(newRelativeX, 2) + pow(newRelativeY, 2));
+
+ if (newM > 1) {
+ // Adjust coordinates to make newM be worth 1
+ newRelativeX = cos(m_azimuth * M_PI / 180 );
+ newRelativeY = sin(m_azimuth * M_PI / 180 );
+ newM = 1; // 1 is the current result of sqrt(pow(newRelativeX, 2) + \
pow(newRelativeY, 2)); + }
+
+ m_altitude = acos(newM); // In radians
+ m_altitude *= (180 / M_PI); // To degrees
+
+ qDebug() << "newM: " << newM;
+ qDebug() << "new Inclination: " << m_altitude;
+
+ // Set the base vector values
+ lightVector.setX( newRelativeX );
+ lightVector.setY( newRelativeY );
+ lightVector.setZ( sin( m_altitude * M_PI / 180 ) );
+
+ m_moving = false;
+
+ paintEvent(&QPaintEvent(this->geometry()));
+
+ qDebug() << lightVector;
+
+ emit moved();
+ emit azimuthChanged(m_azimuth);
+ emit altitudeChanged(m_altitude);
+ emit orbitMoved(m_azimuth, m_altitude);
+}
+
+void KisLightSource::paintEvent(QPaintEvent* event)
+{
+ if (!m_moving) {
+ QPointF parentCenter(parentWidget()->width(),
+ parentWidget()->height());
+ parentCenter /= 2;
+ move((1 + x_3D()) * parentCenter.x() - m_center.x(),
+ (1 + y_3D()) * parentCenter.y() - m_center.y());
+ QLabel::paintEvent(event);
+ } else {
+ QLabel::paintEvent(event);
+ }
+
+ show();
+}
+
+bool KisLightSource::isSelected()
+{
+ return m_isselected;
+}
+
+QColor KisLightSource::color()
+{
+ return m_color;
+}
+
+qreal KisLightSource::x_3D()
+{
+ //qDebug("x_3D = %f", lightVector.x());
+ return lightVector.x();
+}
+
+qreal KisLightSource::y_3D()
+{
+ //qDebug("y_3D = %f", lightVector.y());
+ return lightVector.y();
+}
+
+qreal KisLightSource::z_3D()
+{
+ return lightVector.z();
+}
+
+
+// PRIVATE FUNCTIONS
+
+QPixmap KisLightSource::createBackground()
+{
+ QPen pen;
+ QBrush brush;
+ QPixmap harhar(m_icondiameter, m_icondiameter);
+ harhar.fill(QColor(0,0,0,0));
+
+ QPainter painter(&harhar);
+
+ painter.setBackgroundMode(Qt::TransparentMode);
+ painter.setRenderHint(QPainter::Antialiasing, 0x08);
+
+ pen.setWidth(1);
+ pen.setColor(QColor(0, 0, 0, 150));
+
+ brush.setStyle(Qt::SolidPattern);
+ brush.setColor(m_color);
+
+ painter.setBrush(brush);
+ painter.setPen(pen);
+ painter.drawEllipse(1, 1, m_icondiameter-2, m_icondiameter-2);
+
+ return harhar;
+}
+
+QPixmap KisLightSource::createSelectedBackground()
+{
+ QPen pen;
+ QBrush brush;
+ QPixmap harhar(m_icondiameter + m_selecthalothickness * 2 + 2,
+ m_icondiameter + m_selecthalothickness * 2 + 2);
+ harhar.fill(QColor(0,0,0,0));
+
+ QPainter painter(&harhar);
+
+ painter.setBackgroundMode(Qt::TransparentMode);
+ painter.setRenderHint(QPainter::Antialiasing, 0x08);
+
+ pen.setWidth(m_selecthalothickness);
+ pen.setColor(QColor(255, 255, 0));
+
+ brush.setStyle(Qt::SolidPattern);
+ brush.setColor(m_color);
+
+ painter.setBrush(brush);
+ painter.setPen(pen);
+ painter.drawEllipse(m_selecthalothickness,
+ m_selecthalothickness,
+ m_icondiameter - m_selecthalothickness,
+ m_icondiameter - m_selecthalothickness);
+
+ return harhar;
+}
+
+
+// SIGNALS
+
+void moved();
+
+void selected();
+
+void deselected();
+
+void orbitMoved(qreal azimuth, qreal altitude);
+
+void azimuthChanged(qreal azimuth);
+
+void altitudeChanged(qreal altitude);
+
+void colorChanged(QColor color);
+
+
+// SLOTS
+
+void KisLightSource::select()
+{
+ m_moving = true;
+ m_isselected = true;
+ setPixmap(createSelectedBackground());
+ QSize newsize(m_icondiameter + m_selecthalothickness * 2 + 2,
+ m_icondiameter + m_selecthalothickness * 2 + 2);
+ QPoint newtopleft(pos().x() - (m_selecthalothickness - 1),
+ pos().y() - (m_selecthalothickness - 1));
+
+ setGeometry(QRect(newtopleft, newsize));
+ m_center = QPointF(qreal(size().width()) / 2, qreal(size().height()) / 2);
+ selected();
+
+ setColor(QColor(0, 255, 0));
+}
+
+void KisLightSource::deselect()
+{
+ m_moving = true;
+ m_isselected = false;
+ setPixmap(createBackground());
+ QSize newsize(m_icondiameter, m_icondiameter);
+ QPoint newtopleft(pos().x() + (m_selecthalothickness),
+ pos().y() + (m_selecthalothickness));
+
+ setGeometry(QRect(newtopleft, newsize));
+ m_center = QPointF(qreal(size().width()) / 2, qreal(size().height()) / 2);
+ deselected();
+}
+
+void KisLightSource::moveOrbit(qreal azimuth, qreal altitude)
+{
+ if (m_azimuth != azimuth)
+ m_azimuth = azimuth;
+ if (m_altitude != altitude)
+ m_altitude = altitude;
+ emit azimuthChanged(azimuth);
+ emit altitudeChanged(altitude);
+ emit orbitMoved(azimuth, altitude);
+}
+
+void KisLightSource::setAzimuth(qreal azimuth)
+{
+ if (m_azimuth != azimuth)
+ m_azimuth = azimuth;
+ emit azimuthChanged(azimuth);
+ emit orbitMoved(azimuth, m_altitude);
+}
+
+void KisLightSource::setAltitude(qreal altitude)
+{
+ if (m_altitude != altitude)
+ m_altitude = altitude;
+ emit altitudeChanged(altitude);
+ emit orbitMoved(m_azimuth, altitude);
+}
+
+void KisLightSource::setColor(QColor color)
+{
+ if (m_color != color)
+ m_color = color;
+ emit colorChanged(color);
+}
+
+
diff --git a/krita/ui/widgets/kis_light_source.h \
b/krita/ui/widgets/kis_light_source.h new file mode 100644
index 0000000..c3a9ae6
--- /dev/null
+++ b/krita/ui/widgets/kis_light_source.h
@@ -0,0 +1,87 @@
+/*
+ * Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef KIS_LIGHT_SOURCE_H
+#define KIS_LIGHT_SOURCE_H
+
+#include <QWidget>
+#include <QLabel>
+#include <QtGui>
+#include <QVector3D>
+#include <cmath>
+
+class KisLightSource : public QLabel
+{
+ Q_OBJECT
+
+public:
+ //explicit KisLightSource(QWidget *parent);
+ //explicit KisLightSource(QColor color, qreal azimuth, qreal inclination, \
QWidget *parent); + explicit KisLightSource(QColor color = QColor(0, 0, 0, 255), \
qreal azimuth = 0, qreal inclination = 90, QWidget *parent = 0); + virtual \
~KisLightSource(); +
+ virtual void mousePressEvent(QMouseEvent * event);
+ virtual void mouseReleaseEvent(QMouseEvent * event);
+ virtual void mouseMoveEvent(QMouseEvent * event);
+ virtual void paintEvent(QPaintEvent * event);
+
+ bool isSelected();
+ QColor color();
+
+ qreal x_3D();
+ qreal y_3D();
+ qreal z_3D();
+
+ QList<qreal> RGBvalue;
+ QVector3D lightVector;
+
+signals:
+ void moved();
+ void selected();
+ void deselected();
+ void orbitMoved(qreal azimuth, qreal altitude);
+ void azimuthChanged(qreal azimuth);
+ void altitudeChanged(qreal altitude);
+ void colorChanged(QColor color);
+
+public slots:
+ void select();
+ void deselect();
+ void moveOrbit(qreal azimuth, qreal altitude);
+ void setAzimuth(qreal azimuth);
+ void setAltitude(qreal altitude);
+ void setColor(QColor color);
+
+private:
+ bool m_moving;
+ bool m_selecting;
+ bool m_isselected;
+ quint16 m_icondiameter;
+ quint16 m_selecthalothickness;
+ qreal m_azimuth;
+ qreal m_altitude;
+ QPoint dragStartPosition;
+ QPointF m_selectedPosition;
+ QPointF m_center;
+ QColor m_color;
+ QPixmap createBackground();
+ QPixmap createSelectedBackground();
+};
+
+#endif // KIS_LIGHT_SOURCE_H
diff --git a/krita/ui/widgets/kis_light_stage.cpp \
b/krita/ui/widgets/kis_light_stage.cpp new file mode 100644
index 0000000..75a9595
--- /dev/null
+++ b/krita/ui/widgets/kis_light_stage.cpp
@@ -0,0 +1,255 @@
+/*
+ * Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+#include "kis_light_stage.h"
+
+
+KisLightStage::KisLightStage(QWidget *parent) :
+ QWidget(parent)
+{
+ diffuseLightIsEnabled = true;
+ specularLightIsEnabled = true;
+ relativeZIlum = 2 / qreal(width()); // This number is what makes the heightmap \
look like a perfect hemisphere +}
+
+KisLightStage::~KisLightStage()
+{
+
+}
+
+
+void KisLightStage::paintEvent(QPaintEvent* event)
+{
+ QImage heightmapQImage(width(), height(), QImage::Format_RGB32);
+ qDebug() << "Etto 1";
+ QPainter painter(&heightmapQImage);
+ painter.setRenderHint(QPainter::Antialiasing, 0x01);
+ QPen pen;
+ pen.setWidth(1);
+ pen.setColor(QColor(0,0,0));
+ QBrush brush(semiSphericalGradient());
+ painter.setBrush(brush);
+ painter.setPen(pen);
+ painter.drawEllipse(0, 0, this->width(), this->height());
+ painter.combinedMatrix();
+ QPainter painter2(this);
+ qDebug() << "Etto 2";
+ //painter2.setCompositionMode(QPainter::CompositionMode_SourceOver);
+/*
+ QRgb* tempcolorline;
+ for (int y = 0; y < heightmapQImage.height(); ++y) {
+ for (int x = 0; x < heightmapQImage.width(); ++x) {
+ tempcolorline = (QRgb *) heightmapQImage.scanLine(y);
+ heightmap << QColor(tempcolorline[x]).red();
+ }
+ }
+*/
+ heightmap = semiSphericalHeightmap();
+
+ // IF NO LIGHT SOURCES --> DO NOTHING HERE
+ lightSources = findChildren<KisLightSource *>();
+
+ qDebug() << lightSources;
+ painter2.drawImage(1, 1, drawPhongBumpmap(), 0, 0, width()-2, height()-2);
+ //painter2.drawImage(0, 0, heightmapQImage, 0, 0, width(), height());
+
+ QPointF center(0, 0);
+ center.setX(qreal(this->width()) / 2.0);
+ center.setY(qreal(this->height()) / 2.0);
+ qreal radius = center.x();
+ QPointF position(0, 0);
+}
+
+QRadialGradient KisLightStage::semiSphericalGradient()
+{
+ qint16 counter = 0xFF;
+ qreal m, z = 0;
+ //m = distance from center
+ //z = height, this gradient will be used as a heightmap
+ QColor stopColor(0, 0, 0);
+ QPointF center(qreal(width() / 2), qreal(height() / 2));
+ QRadialGradient semiSphere(center, qreal(width() / 2));
+ while (counter > 0) {
+ z = counter;
+ z /= 0xFF;
+ counter -= 2;
+ stopColor.setRgbF(z, z, z, 1);
+ m = sqrt(1 - z * z);
+ semiSphere.setColorAt(m, stopColor);
+ }
+ return semiSphere;
+}
+
+QVector<qreal> KisLightStage::semiSphericalHeightmap()
+{
+ qreal rx, ry; // [-1, 1]
+ QVector<qreal> foreverAlone(width() * height());
+ qreal renderAzimuth;
+ qreal rm;
+ qreal inclination;
+ qreal rz;
+ for (int y = 0; y < height(); ++y) {
+ for (int x = 0; x < width(); ++x) {
+ //Obtain relative x and y
+ rx = qreal(x - qreal(width() / 2));
+ ry = qreal(y - qreal(height() / 2));
+ //Normalize
+ rx /= qreal(width() / 2);
+ ry /= qreal(height() / 2);
+
+ if (!(rx == 0 && ry == 0)) {
+ renderAzimuth = atan2(rx, ry);
+ } else {
+ renderAzimuth = 0;
+ }
+
+ //Pitagoras
+ rm = sqrt(pow(rx, 2) + pow(ry, 2));
+
+ inclination = acos(rm);
+
+ rz = sin(inclination);
+ if (rz != rz) {
+ foreverAlone << 0;
+ } else {
+ //foreverAlone << rz;
+ foreverAlone[y * width() + x] = rz;
+ }
+ //foreverAlone[y * width() + x] = sin(inclination);
+ }
+ }
+ return foreverAlone;
+}
+
+QImage KisLightStage::drawPhongBumpmap()
+{
+ const quint16 HEIGHT_MINUS_1 = height() - 1;
+ const quint16 WIDTH_MINUS_1 = width() - 1;
+ const quint8 OUTPUT_OFFSET = 1;
+
+ quint32 posup;
+ quint32 posdown;
+ quint32 posleft;
+ quint32 posright;
+
+ QSize inputArea(width(), height());
+
+ QImage bumpmap(width()-2, height()-2, QImage::Format_RGB32);
+ bumpmap.fill(0x000000);
+
+ QRgb** bumpmapByteLines = new QRgb*[bumpmap.height()];
+
+ for (int yIndex = 0; yIndex < bumpmap.height(); yIndex++)
+ bumpmapByteLines[yIndex] = (QRgb *) bumpmap.scanLine(yIndex);
+
+ // Foreach inner pixel in the heightmap do...
+ for (int y = 1; y < HEIGHT_MINUS_1; ++y) {
+ for (int x = 1; x < WIDTH_MINUS_1; ++x) {
+ posup = (y + 1) * inputArea.width() + x;
+ posdown = (y - 1) * inputArea.width() + x;
+ posleft = y * inputArea.width() + x - 1;
+ posright = y * inputArea.width() + x + 1;
+
+ bumpmapByteLines[y - OUTPUT_OFFSET][x - OUTPUT_OFFSET] =
+ illuminatePixel(posup, posdown, posleft, posright);
+ }
+ }
+
+// delete [] bumpmapByteLines;
+ return bumpmap;
+}
+
+QRgb KisLightStage::illuminatePixel(quint32 posup, quint32 posdown, quint32 posleft, \
quint32 posright) +{
+ qreal temp;
+ quint8 channel = 0;
+ const quint8 totalChannels = 3;
+ qreal computation[] = {0, 0, 0};
+ QColor pixelColor(0, 0, 0);
+ QVector3D normal_vector(0, 0, 1);
+ QVector3D light_vector(0, 0, 1);
+ QVector3D vision_vector(0, 0, 1);
+ QVector3D reflection_vector(0, 0, 0);
+ QColor fastLight(0, 0, 0);
+ qreal Id, Kd, Ia, Ka, Is, Ks = 0;
+ Kd = 0.5;
+ Ka = 0.0;
+ Ks = 0.0;
+ qreal shiny_exp = 1;
+
+
+ // Algorithm begins, Phong Illumination Model
+
+ normal_vector.setX(- heightmap[posright] + heightmap[posleft]);
+ normal_vector.setY(- heightmap[posup] + heightmap[posdown]);
+ normal_vector.setZ(relativeZIlum);
+ //normal_vector.setZ(0.005);
+
+/*
+ QVector3D X (1, 0, heightmap[posright] - heightmap[posleft]);
+ QVector3D Y (0, 1, heightmap[posup] - heightmap[posdown]);
+ normal_vector = QVector3D::crossProduct(X, Y);
+ qDebug() << normal_vector;
+*/
+ normal_vector.normalize();
+
+ // PREPARE ALGORITHM HERE
+
+ for (int i = 0; i < lightSources.count(); i++) {
+ light_vector = lightSources.at(i)->lightVector;
+
+ for (channel = 0; channel < totalChannels; channel++) {
+ Ia = lightSources.at(i)->RGBvalue.at(channel) * Ka;
+ computation[channel] += Ia;
+ }
+ if (diffuseLightIsEnabled) {
+ //temp = Kd * QVector3D::dotProduct(normal_vector, light_vector);
+ temp = Kd * QVector3D::dotProduct(light_vector, normal_vector);
+ for (channel = 0; channel < totalChannels; channel++) {
+ Id = lightSources.at(i)->RGBvalue.at(channel) * temp;
+ if (Id < 0) Id = 0;
+ if (Id > 1) Id = 1;
+ computation[channel] += Id;
+ }
+ }
+
+ if (specularLightIsEnabled) {
+ reflection_vector = 2 * QVector3D::dotProduct(normal_vector, \
light_vector) * normal_vector - light_vector; + temp = Ks * \
pow(QVector3D::dotProduct(reflection_vector, vision_vector), shiny_exp); + \
for (channel = 0; channel < totalChannels; channel++) { + Is = \
lightSources.at(i)->RGBvalue.at(channel) * temp; + if (Is < 0) Is \
= 0; + if (Is > 1) Is = 1;
+ computation[channel] += Is;
+ }
+ }
+ }
+
+ for (channel = 0; channel < totalChannels; channel++) {
+ if (computation[channel] > 1)
+ computation[channel] = 1;
+ if (computation[channel] < 0)
+ computation[channel] = 0;
+ }
+
+ pixelColor.setRedF(computation[0]);
+ pixelColor.setGreenF(computation[1]);
+ pixelColor.setBlueF(computation[2]);
+
+ return pixelColor.rgb();
+}
diff --git a/krita/ui/widgets/kis_light_stage.h b/krita/ui/widgets/kis_light_stage.h
new file mode 100644
index 0000000..8620f9e
--- /dev/null
+++ b/krita/ui/widgets/kis_light_stage.h
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2011 José Luis Vergara <pentalis@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+
+#ifndef KIS_LIGHT_STAGE_h
+#define KIS_LIGHT_STAGE_h
+
+#include <QWidget>
+#include "kis_light_source.h"
+#include <krita_export.h>
+
+class KRITAUI_EXPORT KisLightStage : public QWidget
+{
+Q_OBJECT
+public:
+ explicit KisLightStage(QWidget *parent = 0);
+ virtual ~KisLightStage();
+
+ virtual void paintEvent(QPaintEvent* event = 0);
+
+ QPoint dragStartPosition;
+ QList<KisLightSource> lights;
+ QRadialGradient semiSphericalGradient();
+ QImage drawPhongBumpmap();
+ QRgb illuminatePixel(quint32 posup, quint32 posdown, quint32 posleft, quint32 \
posright); + QVector<qreal> heightmap;
+ QList<KisLightSource *> lightSources;
+ QVector<qreal> semiSphericalHeightmap();
+
+ qreal relativeZIlum;
+
+ bool diffuseLightIsEnabled;
+ bool specularLightIsEnabled;
+
+signals:
+
+public slots:
+ //void removeLight();
+ //void addLight();
+
+};
+
+#endif // KIS_LIGHT_STAGE_h
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic