MCPcopy Create free account
hub / github.com/Theverat/NormalmapGenerator / calcNormal

Method calcNormal

src_gui/mainwindow.cpp:287–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

285}
286
287void MainWindow::calcNormal() {
288 if(input.isNull())
289 return;
290
291 //normalmap parameters
292 double strength = ui->doubleSpinBox_strength->value();
293 bool invert = ui->checkBox_invertHeight->isChecked();
294 bool tileable = ui->checkBox_tileable->isChecked();
295
296 //color channel mode
297 IntensityMap::Mode mode = IntensityMap::AVERAGE;
298 if(ui->comboBox_mode_normal->currentIndex() == 0)
299 mode = IntensityMap::AVERAGE;
300 else if(ui->comboBox_mode_normal->currentIndex() == 1)
301 mode = IntensityMap::MAX;
302
303 //color channels to use
304 bool useRed = ui->checkBox_useRed_normal->isChecked();
305 bool useGreen = ui->checkBox_useGreen_normal->isChecked();
306 bool useBlue = ui->checkBox_useBlue_normal->isChecked();
307 bool useAlpha = ui->checkBox_useAlpha_normal->isChecked();
308
309 //kernel to use
310 NormalmapGenerator::Kernel kernel = NormalmapGenerator::SOBEL;
311 if(ui->comboBox_method->currentIndex() == 0)
312 kernel = NormalmapGenerator::SOBEL;
313 else if(ui->comboBox_method->currentIndex() == 1)
314 kernel = NormalmapGenerator::PREWITT;
315
316 //keep large detail settings
317 bool keepLargeDetail = ui->checkBox_keepLargeDetail->isChecked();
318 int largeDetailScale = ui->spinBox_largeDetailScale->value();
319 double largeDetailHeight = ui->doubleSpinBox_largeDetailHeight->value();
320
321 //scale input image if not 100%
322 QImage inputScaled = input;
323 int sizePercent = ui->spinBox_normalmapSize->value();
324 if(sizePercent != 100) {
325 int scaledWidth = calcPercentage(input.width(), sizePercent);
326 int scaledHeight = calcPercentage(input.height(), sizePercent);
327
328 inputScaled = input.scaled(scaledWidth, scaledHeight, Qt::KeepAspectRatio, Qt::SmoothTransformation);
329 }
330
331 //setup generator and calculate map
332 NormalmapGenerator normalmapGenerator(mode, useRed, useGreen, useBlue, useAlpha);
333 normalmap = normalmapGenerator.calculateNormalmap(inputScaled, kernel, strength, invert, tileable, keepLargeDetail, largeDetailScale, largeDetailHeight);
334 normalmapRawIntensity = normalmapGenerator.getIntensityMap().convertToQImage();
335}
336
337void MainWindow::calcSpec() {
338 if(input.isNull())

Callers

nothing calls this directly

Calls 2

calculateNormalmapMethod · 0.80
convertToQImageMethod · 0.80

Tested by

no test coverage detected