Scene for Bloom effect and some variable adjustments
This commit is contained in:
parent
9b07411ebd
commit
e4305190ea
6 changed files with 91 additions and 47 deletions
|
@ -78,6 +78,9 @@ endif()
|
|||
add_executable(fancy1 fancy1.cpp)
|
||||
target_link_libraries(fancy1 tracey)
|
||||
|
||||
add_executable(bloom bloom.cpp)
|
||||
target_link_libraries(bloom tracey)
|
||||
|
||||
add_executable(DOFScene DOFScene.cpp)
|
||||
target_link_libraries(DOFScene tracey)
|
||||
|
||||
|
|
|
@ -90,10 +90,10 @@ int main() {
|
|||
|
||||
// initialize renderer: aperture = lens thickness, secondaryRayCount = how many rays per pixel are created
|
||||
// focalLength = the area which is in focus
|
||||
DOFRenderer renderer(0.2, 100, 10.0f);
|
||||
DOFRenderer renderer(0.2, 50, 10.0f);
|
||||
|
||||
// Use DOFRenderer to raytrace !!! careful more pixels lead to insane rendering times
|
||||
int width = 1920;
|
||||
int width = 600;
|
||||
Texture image = renderer.renderImage(scene, camera, width, width / 16 * 9);
|
||||
|
||||
// Use post-processing Bloom effect
|
||||
|
|
60
bloom.cpp
Normal file
60
bloom.cpp
Normal file
|
@ -0,0 +1,60 @@
|
|||
#include <iostream>
|
||||
#include <string>
|
||||
#include <post_processing/bloom.h>
|
||||
#include <shader/phongshader.h>
|
||||
#include <shader/simpleshadowshader.h>
|
||||
#include <light/pointlight.h>
|
||||
|
||||
#include "camera/perspectivecamera.h"
|
||||
|
||||
#include "renderer/simplerenderer.h"
|
||||
|
||||
#include "scene/simplescene.h"
|
||||
|
||||
#include "primitive/box.h"
|
||||
#include "primitive/infiniteplane.h"
|
||||
#include "primitive/sphere.h"
|
||||
#include "primitive/triangle.h"
|
||||
|
||||
|
||||
int main() {
|
||||
SimpleScene scene;
|
||||
|
||||
scene.setBackgroundColor(Color(0, 0, 0));
|
||||
|
||||
// Add shaders
|
||||
auto red = std::make_shared<SimpleShadowShader>(Color(1.0f, 0.3f, 0.2f));
|
||||
auto gray = std::make_shared<SimpleShadowShader>(Color(0.78f, 0.78f, 0.78f));
|
||||
auto blue = std::make_shared<SimpleShadowShader>(Color(0.2f, 0.3f, 1.0f));
|
||||
auto orange = std::make_shared<PhongShader>(Color(1.0f, 0.64f, 0.0f), 1.0f, Color(1.0f, 1.0f, 1.0f), 1.0f, 25.0f);
|
||||
|
||||
|
||||
scene.add(std::make_shared<Box>(Vector3d(5.0f, -5.0f, 0.0f), Vector3d(4.0f, 4.0f, 4.0f), red));
|
||||
scene.add(std::make_shared<Box>(Vector3d(-5.0f, -3.0f, 1.0f), Vector3d(1.0f, 6.0f, 1.0f), blue));
|
||||
scene.add(std::make_shared<Box>(Vector3d(-3.5f, 4.0f, -2.0f), Vector3d(2.0f, 2.0f, 2.0f), orange));
|
||||
scene.add(std::make_shared<Sphere>(Vector3d(2.0f, 4.0f, 0.0f), 1.0f, orange));
|
||||
|
||||
scene.add(std::make_shared<PointLight>(Vector3d(0.0f, 0.0f, -11.0f), 100.0f));
|
||||
|
||||
|
||||
|
||||
// Set up the camera
|
||||
PerspectiveCamera camera;
|
||||
camera.setFovAngle(90.0f);
|
||||
camera.setPosition(Vector3d(0.0f, 0.0f, -10.0f));
|
||||
camera.setForwardDirection(Vector3d(0.0f, 0.0f, 1.0f));
|
||||
camera.setUpDirection(Vector3d(0.0f, 1.0f, 0.0f));
|
||||
|
||||
// Render the scene
|
||||
SimpleRenderer renderer;
|
||||
Texture img = renderer.renderImage(scene, camera, 512, 512);
|
||||
|
||||
img.save("beforeBloom.png");
|
||||
|
||||
Bloom bloom = Bloom(img.getImage(), 0.88f, img);
|
||||
img.setTexture(bloom.bloom(100, 300.0f, 1.5f));
|
||||
|
||||
img.save("afterBloom.png");
|
||||
|
||||
return 0;
|
||||
}
|
|
@ -86,14 +86,10 @@ int main() {
|
|||
// Use DOFRenderer to raytrace !!! careful more pixels lead to insane rendering times
|
||||
Texture image = renderer.renderImage(scene, camera, 1024, 1024);
|
||||
|
||||
// Use post-processing Bloom effect
|
||||
Bloom bloomEffect = Bloom(image.getImage());
|
||||
Texture imageWithBloom = image;
|
||||
imageWithBloom.setTexture(bloomEffect.bloom(0.55f, 5, 10.0f, 0.06f));
|
||||
|
||||
|
||||
// save images
|
||||
image.save("result.png");
|
||||
image.save("resultWithBloom");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -2,22 +2,17 @@
|
|||
#include <iostream>
|
||||
#include "bloom.h"
|
||||
|
||||
Bloom::Bloom(CImg<float> image) : image(image) {}
|
||||
Bloom::Bloom(CImg<float> &image, float threshold, Texture& thresholdImg) : image(image), threshold(threshold) {}
|
||||
|
||||
|
||||
CImg<float> Bloom::bloom(float threshold, int kernelSize, float sigma, float intensity) {
|
||||
// Apply threshold to image
|
||||
//CImg<float> brightPixels = image_.get_threshold(threshold);
|
||||
//brightPixels.save("brightpixels.png");
|
||||
CImg<float> Bloom::bloom(int kernelSize, float sigma, float intensity) {
|
||||
|
||||
CImg<float> brightPixels = image.get_threshold(threshold);
|
||||
|
||||
// Apply gaussian blur to bright pixels
|
||||
CImg<float> kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
CImg<float> blurred = convolution(image, kernel);
|
||||
for(int i = 0; i < 3; i++){
|
||||
kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
blurred = convolution(image, kernel);
|
||||
blurred *= intensity;
|
||||
}
|
||||
|
||||
// Add blurred image back to original image
|
||||
cimg_forXYC(image, x, y, c) {
|
||||
|
@ -28,10 +23,6 @@ CImg<float> Bloom::bloom(float threshold, int kernelSize, float sigma, float int
|
|||
return image;
|
||||
}
|
||||
|
||||
void Bloom::gaussianBlur(int kernelSize, float sigma) {
|
||||
CImg<float> kernel = computeGaussianKernel(kernelSize, sigma);
|
||||
image = convolution(image, kernel);
|
||||
}
|
||||
|
||||
// Function to compute Gaussian kernel
|
||||
CImg<float> Bloom::computeGaussianKernel(int kernelSize, float sigma) {
|
||||
|
@ -82,7 +73,3 @@ CImg<float> Bloom::convolution(CImg<float> &img, CImg<float> &kernel) {
|
|||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void Bloom::scaleBrightness(float scale) {
|
||||
image *= scale;
|
||||
}
|
||||
|
|
|
@ -8,19 +8,17 @@
|
|||
class Bloom {
|
||||
|
||||
public:
|
||||
Bloom(CImg<float> image);
|
||||
CImg<float> bloom(float threshold, int kernelSize, float sigma, float intensity);
|
||||
Bloom(CImg<float>& image, float threshold, Texture& thresholdImg);
|
||||
CImg<float> bloom(int kernelSize, float sigma, float intensity);
|
||||
|
||||
private:
|
||||
void scaleBrightness(float scale);
|
||||
void gaussianBlur(int kernelSize, float sigma);
|
||||
|
||||
CImg<float> convolution(CImg<float> &img, CImg<float> &kernel);
|
||||
CImg<float> computeGaussianKernel(int kernelSize, float sigma);
|
||||
|
||||
|
||||
|
||||
CImg<float> image;
|
||||
|
||||
float threshold;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue