Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add depth-of-field (Blurring rendering options) #1662

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

perminder-17
Copy link

issue : #347
Signed-off by : permindersingh089@gmail.com
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
have the right to submit it under the open source license
indicated in the file; or

(b) The contribution is based upon previous work that, to the best
of my knowledge, is covered under an appropriate open source
license and I have the right under that license to submit that
work with modifications, whether created in whole or in part
by me, under the same open source license (unless I am
permitted to submit under a different license), as indicated
in the file; or

(c) The contribution was provided directly to me by some other
person who certified (a), (b) or (c) and I have not modified
it.

(d) I understand and agree that this project and the contribution
are public and that a record of the contribution (including all
personal information I submit with it, including my sign-off) is
maintained indefinitely and may be redistributed consistent with
this project or the open source license(s) involved.

Signed-off-by: Perminder <permindersingh089@gmail.com>
Signed-off-by: Perminder <permindersingh089@gmail.com>
@perminder-17
Copy link
Author

perminder-17 commented Apr 11, 2024

Hi @ghutchis code is functioning correctly, but there are a couple of concerns I'd like your help with. Also I am thinking to add visual tests when the all the requirements will be done. Here's the other PR OpenChemistry/avogadroapp#492

  1. The code currently uses 64 samples for blurring, following the number of samples from Speck. However, this reduces frame rates a bit. I'm considering reducing the number of samples, but I'm concerned about compromising the quality of the blur. Do you think decreasing the samples would be advisable?
  2. When we zoom in or out, the blur changes, which differs from the behavior in Speck. While this deviation could mimic real-world effects, such as objects appearing blurry when they're too close or too far. Considering potential future features like VR, this behavior might actually enhance realism. What's your take on this? Should we maintain or adjust the blur behavior?
  3. Your feedback is invaluable, and I'm committed to optimizing and tidying up the code. I'd greatly appreciate your input on any minor cleanups or optimizations you think are necessary.
  4. I was thinking about adding blur and fog effects to a new file, but I believe combining all rendering options into one would be better.
  5. I'll include the ability to adjust the strength of blur, allowing users to control how blurry they want things to be. Will be setting some other uniforms for that.

Screenshot from 2024-04-10 06-10-04

@avo-bot
Copy link

avo-bot commented Apr 11, 2024

This pull request has been mentioned on Avogadro Discussion. There might be relevant details there:

https://discuss.avogadro.cc/t/add-depth-of-field-fog-or-blurring-rendering-options/5332/9

Signed-off-by: Perminder <permindersingh089@gmail.com>
@perminder-17
Copy link
Author

perminder-17 commented Apr 11, 2024

Have a look, In the above commit I changed as you told("does not blur when camera is too close")

BEFORE (without BLUR)

Screenshot from 2024-04-11 21-50-41

AFTER-BLUR (THE INTENSITY CAN BE INCREASED)

Screenshot from 2024-04-11 21-50-28

BEFORE (without blur)

Screenshot from 2024-04-11 22-10-23

AFTER-BLUR

Screenshot from 2024-04-11 22-10-10

Copy link

@vinayakjeet vinayakjeet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review of Shader Code Enhancements

The proposed changes to the shader code, including enhanced randomness in the rand function, dynamic sample adjustment, and smoother weight transitions using smoothstep, significantly improve performance and visual quality. These updates are well-aligned with best practices for rendering optimizations.

@ghutchis , could you please review these enhancements and provide your feedback?


float total = 1.0;
vec4 color = texture2D(inRGBTex, texCoord);
// number of samples can be optimized.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int numSamples = int(clamp(blurAmt * 64.0, 16.0, 64.0));
// dynamically reduce number of samples based on blur amount

for (int i = 0; i < numSamples; i++) {
// Remaining loop code of blur application...
}
@ghutchis your reviews for the changes proposed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the review. I'll definitely make time to address the suggestions. However, regarding this issue, the loop index can't be compared with a non-constant expression. Therefore, adding numSamples to the for loop won't function since its value isn't constant. Could also leads to error. Are you sure about this one??

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, and I appreciate your careful consideration. While GLSL 1.2 does support dynamic looping, the behavior can indeed vary based on the GPU and driver support. Sticking with your current approach to ensure compatibility and stability is wise. Thank you for pointing this out, @guthichs, and your reviews and help are greatly appreciated!

@@ -66,6 +68,47 @@ float lerp(float a, float b, float f)
return a + f * (b - a);
}

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float rand(vec2 co) {
return fract(sin(dot(co.xy ,vec2(12.9898,78.233)) + cos(dot(co.xy, vec2(93.9898,50.233)))) * 43758.5453);
}
//more complex pattern produced which helps in reducing the noise. @ghutchis your insights ?

vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * blurAmt) / pixelScale;
float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x);
float sampleBlur = calcBlur(z, pixelScale);
float weight = float((z >= origZ) || (sampleBlur >= blurAmt * radius + 0.));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

float weight = 1.0 - smoothstep(0.0, 1.0, abs(z - origZ) / blurAmt);
// using smoothstep to soften weight transitions
This modification uses smoothstep to create a more gradual transition in weights applied to sampled colors, potentially reducing artifacts like banding. Reviews @ghutchis

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants