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

#include <kis_phong_bumpmap_filter.h>

+ Inheritance diagram for KisFilterPhongBumpmap:

Public Member Functions

QRect changedRect (const QRect &rect, const KisFilterConfigurationSP config, int lod) const override
 
KisConfigWidgetcreateConfigurationWidget (QWidget *parent, const KisPaintDeviceSP dev, bool useForMasks) const override
 
KisFilterConfigurationSP defaultConfiguration (KisResourcesInterfaceSP resourcesInterface) const override
 
 KisFilterPhongBumpmap ()
 
QRect neededRect (const QRect &rect, const KisFilterConfigurationSP config, int lod) const override
 
void processImpl (KisPaintDeviceSP device, const QRect &applyRect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater) const override
 
- Public Member Functions inherited from KisFilter
virtual bool configurationAllowedForMask (KisFilterConfigurationSP config) const
 
virtual void fixLoadedFilterConfigurationForMasks (KisFilterConfigurationSP config) const
 
 KisFilter (const KoID &id, const KoID &category, const QString &entry)
 
virtual bool needsTransparentPixels (const KisFilterConfigurationSP config, const KoColorSpace *cs) const
 
void process (const KisPaintDeviceSP src, KisPaintDeviceSP dst, KisSelectionSP selection, const QRect &applyRect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater=0) const
 
void process (KisPaintDeviceSP device, const QRect &applyRect, const KisFilterConfigurationSP config, KoUpdater *progressUpdater=0) const
 
virtual bool supportsLevelOfDetail (const KisFilterConfigurationSP config, int lod) const
 
 ~KisFilter () override
 
- Public Member Functions inherited from KisBaseProcessor
KisBookmarkedConfigurationManagerbookmarkManager ()
 
const KisBookmarkedConfigurationManagerbookmarkManager () const
 
ColorSpaceIndependence colorSpaceIndependence () const
 
virtual KisFilterConfigurationSP factoryConfiguration (KisResourcesInterfaceSP resourcesInterface) const
 
QString id () const
 
 KisBaseProcessor (const KoID &id, const KoID &category, const QString &entry)
 
KoID menuCategory () const
 
QString menuEntry () const
 
QString name () const
 
 Private ()
 
QKeySequence shortcut () const
 
bool showConfigurationWidget ()
 If true, the filter wants to show a configuration widget.
 
bool supportsAdjustmentLayers () const
 This filter can be used in adjustment layers.
 
bool supportsPainting () const
 
bool supportsThreading () const
 
virtual ~KisBaseProcessor ()
 
- Public Member Functions inherited from Private
 Private (KisCanvas2 *c)
 
- Public Member Functions inherited from KisShared
bool deref ()
 
bool ref ()
 
int refCount ()
 
QAtomicInt * sharedWeakReference ()
 

Additional Inherited Members

- Public Attributes inherited from KisBaseProcessor
KisBookmarkedConfigurationManagerbookmarkManager
 
KoID category
 
ColorSpaceIndependence colorSpaceIndependence
 
QString entry
 
KoID id
 
QKeySequence shortcut
 
bool showConfigurationWidget
 
bool supportsAdjustmentLayers
 
bool supportsPainting
 
bool supportsThreading
 
- Public Attributes inherited from Private
KisCanvas2canvas
 
int displayedFrame
 
int intendedFrame
 
- Protected Member Functions inherited from KisFilter
QString configEntryGroup () const
 
void setSupportsLevelOfDetail (bool value)
 
- Protected Member Functions inherited from KisBaseProcessor
void init (const QString &configEntryGroup)
 
void setColorSpaceIndependence (ColorSpaceIndependence v)
 
void setShortcut (const QKeySequence &shortcut)
 
void setShowConfigurationWidget (bool v)
 
void setSupportsAdjustmentLayers (bool v)
 
void setSupportsPainting (bool v)
 
void setSupportsThreading (bool v)
 
- Protected Member Functions inherited from KisShared
 KisShared ()
 
 ~KisShared ()
 

Detailed Description

This class is an implementation of the phong illumination model. It uses a heightmap as an input mesh (normally taken from 1 channel of a colorspace) to achieve a bumpmapping effect with multiple illumination sources.

Definition at line 20 of file kis_phong_bumpmap_filter.h.

Constructor & Destructor Documentation

◆ KisFilterPhongBumpmap()

KisFilterPhongBumpmap::KisFilterPhongBumpmap ( )

Definition at line 24 of file kis_phong_bumpmap_filter.cpp.

25 : KisFilter(KoID("phongbumpmap", i18n("Phong Bumpmap")),
26 FiltersCategoryMapId, i18n("&Phong Bumpmap..."))
27{
31}
@ TO_LAB16
void setSupportsLevelOfDetail(bool value)
KisFilter(const KoID &id, const KoID &category, const QString &entry)
Definition kis_filter.cc:22
Definition KoID.h:30
const KoID FiltersCategoryMapId("map_filters", ki18nc("The category of mapping filters, like bump map or gradient filter map. Verb.", "Map"))
void setSupportsPainting(bool v)
void setColorSpaceIndependence(ColorSpaceIndependence v)

References KisBaseProcessor::setColorSpaceIndependence(), KisFilter::setSupportsLevelOfDetail(), KisBaseProcessor::setSupportsPainting(), and TO_LAB16.

Member Function Documentation

◆ changedRect()

QRect KisFilterPhongBumpmap::changedRect ( const QRect & rect,
const KisFilterConfigurationSP config,
int lod ) const
overridevirtual

Similar to neededRect : some filters will alter a lot of pixels that are near to each other at the same time. So when you changed a single rectangle in a device, the actual rectangle that will feel the influence of this change might be bigger. Use this function to determine that rect.

Reimplemented from KisFilter.

Definition at line 215 of file kis_phong_bumpmap_filter.cpp.

216{
217 return rect;
218}

◆ createConfigurationWidget()

KisConfigWidget * KisFilterPhongBumpmap::createConfigurationWidget ( QWidget * parent,
const KisPaintDeviceSP dev,
bool useForMasks ) const
overridevirtual

Create the configuration widget for this processor.

Parameters
parentthe Qt owner widget of this widget
devthe paintdevice this filter will act on
useForMasksshown if the filer is going to be used in a mask. Some filters may provide limited options when applied as a mask (e.g. Gaussian Blur)

Reimplemented from KisBaseProcessor.

Definition at line 220 of file kis_phong_bumpmap_filter.cpp.

◆ defaultConfiguration()

KisFilterConfigurationSP KisFilterPhongBumpmap::defaultConfiguration ( KisResourcesInterfaceSP resourcesInterface) const
overridevirtual

Return the configuration set as the default by the user or the default configuration from the filter writer as returned by factoryConfiguration.

This configuration is used by default for the configuration widget and given to the process function if there is no configuration widget.

Returns
the default configuration of this widget

Reimplemented from KisBaseProcessor.

Definition at line 180 of file kis_phong_bumpmap_filter.cpp.

181{
182 KisFilterConfigurationSP config = factoryConfiguration(resourcesInterface);
183 config->setProperty(PHONG_AMBIENT_REFLECTIVITY, 0.2);
184 config->setProperty(PHONG_DIFFUSE_REFLECTIVITY, 0.5);
185 config->setProperty(PHONG_SPECULAR_REFLECTIVITY, 0.3);
186 config->setProperty(PHONG_SHINYNESS_EXPONENT, 2);
187 config->setProperty(USE_NORMALMAP_IS_ENABLED, false);
188 config->setProperty(PHONG_DIFFUSE_REFLECTIVITY_IS_ENABLED, true);
189 config->setProperty(PHONG_SPECULAR_REFLECTIVITY_IS_ENABLED, true);
190 // Indexes are off by 1 simply because arrays start at 0 and the GUI naming scheme started at 1
191 config->setProperty(PHONG_ILLUMINANT_IS_ENABLED[0], true);
192 config->setProperty(PHONG_ILLUMINANT_IS_ENABLED[1], true);
193 config->setProperty(PHONG_ILLUMINANT_IS_ENABLED[2], false);
194 config->setProperty(PHONG_ILLUMINANT_IS_ENABLED[3], false);
195 config->setProperty(PHONG_ILLUMINANT_COLOR[0], QColor(255, 255, 0));
196 config->setProperty(PHONG_ILLUMINANT_COLOR[1], QColor(255, 0, 0));
197 config->setProperty(PHONG_ILLUMINANT_COLOR[2], QColor(0, 0, 255));
198 config->setProperty(PHONG_ILLUMINANT_COLOR[3], QColor(0, 255, 0));
199 config->setProperty(PHONG_ILLUMINANT_AZIMUTH[0], 50);
200 config->setProperty(PHONG_ILLUMINANT_AZIMUTH[1], 100);
201 config->setProperty(PHONG_ILLUMINANT_AZIMUTH[2], 150);
202 config->setProperty(PHONG_ILLUMINANT_AZIMUTH[3], 200);
203 config->setProperty(PHONG_ILLUMINANT_INCLINATION[0], 25);
204 config->setProperty(PHONG_ILLUMINANT_INCLINATION[1], 20);
205 config->setProperty(PHONG_ILLUMINANT_INCLINATION[2], 30);
206 config->setProperty(PHONG_ILLUMINANT_INCLINATION[3], 40);
207 return config;
208}
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 QString PHONG_SHINYNESS_EXPONENT
const QString PHONG_DIFFUSE_REFLECTIVITY
const QString PHONG_ILLUMINANT_IS_ENABLED[]
const QString USE_NORMALMAP_IS_ENABLED
const QString PHONG_SPECULAR_REFLECTIVITY
const QString PHONG_AMBIENT_REFLECTIVITY
virtual KisFilterConfigurationSP factoryConfiguration(KisResourcesInterfaceSP resourcesInterface) const

References KisBaseProcessor::factoryConfiguration(), 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, and USE_NORMALMAP_IS_ENABLED.

◆ neededRect()

QRect KisFilterPhongBumpmap::neededRect ( const QRect & rect,
const KisFilterConfigurationSP config,
int lod ) const
overridevirtual

Some filters need pixels outside the current processing rect to compute the new value (for instance, convolution filters)

Reimplemented from KisFilter.

Definition at line 210 of file kis_phong_bumpmap_filter.cpp.

211{
212 return rect.adjusted(-1, -1, 1, 1);
213}

◆ processImpl()

void KisFilterPhongBumpmap::processImpl ( KisPaintDeviceSP device,
const QRect & applyRect,
const KisFilterConfigurationSP config,
KoUpdater * progressUpdater ) const
overridevirtual

Override this function with the implementation of your filter.

This is a low level function that expects all the conditions for the

Parameters
devicebe met. Use usual process() methods instead.
devicethe paint device to filter
applyRectthe rectangle where the filter is applied
configthe parameters of the filter
progressUpdaterto pass on the progress the filter is making

Implements KisFilter.

Definition at line 33 of file kis_phong_bumpmap_filter.cpp.

38{
39 if (!config) return;
40
41 if (progressUpdater) progressUpdater->setProgress(0);
42
43 QString userChosenHeightChannel = config->getString(PHONG_HEIGHT_CHANNEL, "FAIL");
44 bool m_usenormalmap = config->getBool(USE_NORMALMAP_IS_ENABLED);
45
46 if (userChosenHeightChannel == "FAIL") {
47 return;
48 }
49
50 const QList<KoChannelInfo*> channels = device->colorSpace()->channels();
51 KoChannelInfo *m_heightChannel = 0;
52
53 Q_FOREACH (KoChannelInfo* channel, channels) {
54 if (userChosenHeightChannel == channel->name()) {
55 m_heightChannel = channel;
56 }
57 }
58
59 if (!m_heightChannel) {
60 m_heightChannel = channels.first();
61 }
62 KIS_ASSERT_RECOVER_RETURN(m_heightChannel);
63
64 QRect inputArea = applyRect;
65 QRect outputArea = applyRect;
66 if (m_usenormalmap==false) {
67 inputArea.adjust(-1, -1, 1, 1);
68 }
69
70 quint32 posup;
71 quint32 posdown;
72 quint32 posleft;
73 quint32 posright;
74 QColor I; //Reflected light
75
76 if (progressUpdater) progressUpdater->setProgress(1);
77
78 //======Preparation paraphernalia=======
79
80 //Hardcoded facts about Phong Bumpmap: it _will_ generate an RGBA16 bumpmap
81 const quint8 BYTE_DEPTH_OF_BUMPMAP = 2; // 16 bits per channel
82 const quint8 CHANNEL_COUNT_OF_BUMPMAP = 4; // RGBA
83 const quint32 pixelsOfInputArea = abs(inputArea.width() * inputArea.height());
84 const quint32 pixelsOfOutputArea = abs(outputArea.width() * outputArea.height());
85 const quint8 pixelSize = BYTE_DEPTH_OF_BUMPMAP * CHANNEL_COUNT_OF_BUMPMAP;
86 const quint32 bytesToFillBumpmapArea = pixelsOfOutputArea * pixelSize;
87 QVector<quint8> bumpmap(bytesToFillBumpmapArea);
88 quint8 *bumpmapDataPointer = bumpmap.data();
89 quint32 ki = KoChannelInfo::displayPositionToChannelIndex(m_heightChannel->displayPosition(), channels);
90 PhongPixelProcessor tileRenderer(pixelsOfInputArea, config);
91
92
93 if (progressUpdater) progressUpdater->setProgress(2);
94
95 //===============RENDER=================
96
97 QVector<PtrToDouble> toDoubleFuncPtr(channels.count());
98 KisMathToolbox mathToolbox;
99 if (!mathToolbox.getToDoubleChannelPtr(channels, toDoubleFuncPtr)) {
100 return;
101 }
102
104 quint32 curPixel = 0;
105 iterator = device->createHLineConstIteratorNG(inputArea.x(),
106 inputArea.y(),
107 inputArea.width()
108 );
109
110 if (m_usenormalmap==false) {
111 for (qint32 srcRow = 0; srcRow < inputArea.height(); ++srcRow) {
112 do {
113 const quint8 *data = iterator->oldRawData();
114 tileRenderer.realheightmap[curPixel] = toDoubleFuncPtr[ki](data, channels[ki]->pos());
115 curPixel++;
116 }
117 while (iterator->nextPixel());
118 iterator->nextRow();
119 }
120 if (progressUpdater) progressUpdater->setProgress(50);
121
122 const int tileHeightMinus1 = inputArea.height() - 1;
123 const int tileWidthMinus1 = inputArea.width() - 1;
124
125 // Foreach INNER pixel in tile
126 for (int y = 1; y < tileHeightMinus1; ++y) {
127 for (int x = 1; x < tileWidthMinus1; ++x) {
128 posup = (y + 1) * inputArea.width() + x;
129 posdown = (y - 1) * inputArea.width() + x;
130 posleft = y * inputArea.width() + x - 1;
131 posright = y * inputArea.width() + x + 1;
132
133
134 memcpy(bumpmapDataPointer,
135 tileRenderer.IlluminatePixelFromHeightmap(posup, posdown, posleft, posright).data(),
136 pixelSize);
137
138 bumpmapDataPointer += pixelSize;
139 }
140 }
141 } else {
142 for (qint32 srcRow = 0; srcRow < inputArea.height(); ++srcRow) {
143 do {
144 const quint8 *data = iterator->oldRawData();
145 tileRenderer.realheightmap[curPixel] = toDoubleFuncPtr[ki](data, channels[ki]->pos());
146 QVector <float> current_pixel_values(4);
147 device->colorSpace()->normalisedChannelsValue(data, current_pixel_values );
148
149 //dbgKrita<< "Vector:" << current_pixel_values[2] << "," << current_pixel_values[1] << "," << current_pixel_values[0];
150 memcpy(bumpmapDataPointer,
151 tileRenderer.IlluminatePixelFromNormalmap(current_pixel_values[2], current_pixel_values[1], current_pixel_values[0]).data(),
152 pixelSize);
153
154 curPixel++;
155 //pointer that crashes here, but not in the other if statement.
156 bumpmapDataPointer += pixelSize;
157
158
159
160 }
161 while (iterator->nextPixel());
162 iterator->nextRow();
163 }
164 }
165
166 if (progressUpdater) progressUpdater->setProgress(90);
167
168 KisPaintDeviceSP bumpmapPaintDevice = new KisPaintDevice(KoColorSpaceRegistry::instance()->rgb16());
169 bumpmapPaintDevice->writeBytes(bumpmap.data(), outputArea.x(), outputArea.y(), outputArea.width(), outputArea.height());
171 KisPainter copier(device);
172 copier.bitBlt(outputArea.x(), outputArea.y(), bumpmapPaintDevice,
173 outputArea.x(), outputArea.y(), outputArea.width(), outputArea.height());
174 //device->prepareClone(bumpmapPaintDevice);
175 //device->makeCloneFrom(bumpmapPaintDevice, bumpmapPaintDevice->extent()); // THIS COULD BE BUG GY
176
177 if (progressUpdater) progressUpdater->setProgress(100);
178}
virtual const quint8 * oldRawData() const =0
virtual bool nextPixel()=0
virtual void nextRow()=0
bool getToDoubleChannelPtr(QList< KoChannelInfo * > cis, QVector< PtrToDouble > &f)
const KoColorSpace * colorSpace() const
void convertTo(const KoColorSpace *dstColorSpace, KoColorConversionTransformation::Intent renderingIntent=KoColorConversionTransformation::internalRenderingIntent(), KoColorConversionTransformation::ConversionFlags conversionFlags=KoColorConversionTransformation::internalConversionFlags(), KUndo2Command *parentCommand=nullptr, KoUpdater *progressUpdater=nullptr)
KisHLineConstIteratorSP createHLineConstIteratorNG(qint32 x, qint32 y, qint32 w) const
void writeBytes(const quint8 *data, qint32 x, qint32 y, qint32 w, qint32 h)
static int displayPositionToChannelIndex(int displayPosition, const QList< KoChannelInfo * > &channels)
QString name() const
qint32 displayPosition() const
QList< KoChannelInfo * > channels
virtual void normalisedChannelsValue(const quint8 *pixel, QVector< float > &channels) const =0
void setProgress(int percent)
Definition KoUpdater.cpp:38
void bumpmap(KisPixelSelectionSP device, const QRect &selectionRect, const bumpmap_vals_t &bmvals)
#define KIS_ASSERT_RECOVER_RETURN(cond)
Definition kis_assert.h:75
Point abs(const Point &pt)
const QString PHONG_HEIGHT_CHANNEL
static KoColorSpaceRegistry * instance()

References KisPainter::bitBlt(), bumpmap(), KoColorSpace::channels, KisPaintDevice::colorSpace(), KisPaintDevice::convertTo(), KisPaintDevice::createHLineConstIteratorNG(), KoChannelInfo::displayPosition(), KoChannelInfo::displayPositionToChannelIndex(), KisMathToolbox::getToDoubleChannelPtr(), PhongPixelProcessor::IlluminatePixelFromHeightmap(), PhongPixelProcessor::IlluminatePixelFromNormalmap(), KoColorSpaceRegistry::instance(), KoColorConversionTransformation::internalConversionFlags(), KoColorConversionTransformation::internalRenderingIntent(), KIS_ASSERT_RECOVER_RETURN, KoChannelInfo::name(), KisBaseConstIteratorNG::nextPixel(), KisHLineConstIteratorNG::nextRow(), KoColorSpace::normalisedChannelsValue(), KisBaseConstAccessor::oldRawData(), PHONG_HEIGHT_CHANNEL, PhongPixelProcessor::realheightmap, KoUpdater::setProgress(), USE_NORMALMAP_IS_ENABLED, and KisPaintDevice::writeBytes().


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