Skip to content

Commit

Permalink
m
Browse files Browse the repository at this point in the history
  • Loading branch information
Tobias Kozel committed Jul 11, 2020
1 parent e78ee74 commit 17c1c6c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
5 changes: 2 additions & 3 deletions src/DemoScenePost.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

class DemoScenePost : public Scene {

// Model sceneModel = { "assets/littlest_tokyo/scene.gltf" };
Shader &gShader = getGBufferShader();
Model model = { platformPath("assets/littlest_tokyo/scene.obj") };
Quad billboard;
Expand Down Expand Up @@ -58,7 +57,7 @@ class DemoScenePost : public Scene {
float debugScale = 1.0;
public:
DemoScenePost(int w, int h) {
camera = getSkateboardCam();
// camera = getSkateboardCam();
DemoScenePost::onResize(w, h);
}

Expand Down Expand Up @@ -178,7 +177,7 @@ class DemoScenePost : public Scene {
if (ImGui::TreeNode("Depth of Field")) {
ImGui::SliderFloat(
"Focus distance", &camera.focusDistance,
camera.nearPlane, camera.farPlane
camera.nearPlane, 25
);
ImGui::SliderFloat("Focus Scale", &camera.focusScale, 0.0f, 30.0f);
helpMaker("Strength of the depth of field");
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void init() {
glfwSetFramebufferSizeCallback(window, resizeCallback);
glfwSetCursorPosCallback(window, mouseCallback);
glfwSetScrollCallback(window, scrollCallback);
glfwSwapInterval(0);
glfwSwapInterval(1);

if (!gladLoadGL()) {
std::cout << "Error loading glad!\n";
Expand Down
13 changes: 11 additions & 2 deletions src/shaders/DOFShaderAdvanced.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ inline Shader& getDOFShaderAdvanced() {
return abs(coc) * MAX_BLUR_SIZE;
}

float rand(vec2 co) {
return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453);
}

vec2 rand2(vec2 co) {
return vec2(rand(co), rand(co * 20.0)) * 2.0 - 1.0;
}

vec3 depthOfField(float focusPoint, float focusScale) {
float centerDepth = texture(zBufferLinear, TexCoords).r;
float centerSize = getBlurSize(centerDepth, focusPoint, focusScale);
Expand All @@ -37,7 +45,8 @@ inline Shader& getDOFShaderAdvanced() {
float radius = RAD_SCALE;
float ang = 0.0;
for (int i = 0; i < iterations; i++) {
vec2 tc = TexCoords + vec2(cos(ang), sin(ang)) * pixelSize * radius;
// vec2 tc = TexCoords + vec2(cos(ang), sin(ang)) * pixelSize * radius;
vec2 tc = TexCoords + rand2(TexCoords + vec2(i , -i)) * pixelSize * radius;

vec3 sampleColor = texture(gColor, tc).rgb;
float sampleDepth = texture(zBufferLinear, tc).r;
Expand All @@ -52,7 +61,7 @@ inline Shader& getDOFShaderAdvanced() {
tot += 1.0;
radius += RAD_SCALE / radius;
ang += GOLDEN_ANGLE;
// if (radius > MAX_BLUR_SIZE) { break; }
if (radius > MAX_BLUR_SIZE) { break; }
}
return color /= tot;
}
Expand Down
6 changes: 3 additions & 3 deletions src/shaders/DOFShaderSimple.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ inline Shader &getDofShaderSimple() {
void main() {
float depth = texture(zBufferLinear, TexCoords).r;

depth = (depth - focus) * 0.0002 * focusScale;
depth = (depth - focus) * 0.05 * focusScale;
vec3 color = vec3(0);
for (int i = 0; i < iterations; i++) {
vec2 offset = rand2(TexCoords + i) * depth;
color += texture(gColor, TexCoords + offset).rgb;
vec2 offset = rand2(TexCoords + i) * depth ;
color += texture(gColor, TexCoords + offset * pixelSize).rgb;
}
color /= float(iterations);
FragColor = vec4(color, 1.0);
Expand Down
4 changes: 2 additions & 2 deletions src/util/Camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@

class Camera {
public:
float fieldOfView = 45; // Fov in degrees
float fieldOfView = 53.1; // Fov in degrees
float focusDistance = 14.0; // focus distance in linear space
float focusScale = 1.0; // Strength of the depth of field
int dofSamples = 32; // samples per pixel

float vignetteStrength = 0.95;
float vignetteStrength = 0.2;
float vignetteFalloff = 3.0;
float aspectRatio = 1.0;
float vignetteDesaturation = 0.0;
Expand Down

0 comments on commit 17c1c6c

Please sign in to comment.