From d527009cda74c4444e7c3b7d6417f038ee1a0f55 Mon Sep 17 00:00:00 2001 From: Perminder Date: Thu, 11 Apr 2024 07:53:40 +0530 Subject: [PATCH 01/11] Depth-blur Signed-off-by: Perminder --- avogadro/rendering/solid_first_fs.glsl | 60 +++++++++++++++++++++++--- avogadro/rendering/solidpipeline.h | 7 +++ 2 files changed, 62 insertions(+), 5 deletions(-) diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index b95274fdc6..741bd6c1db 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -25,6 +25,8 @@ uniform sampler2D inRGBTex; uniform sampler2D inDepthTex; // 1.0 if enabled, 0.0 if disabled uniform float inAoEnabled; +// 1.0 if enabled, 0.0 if disabled +uniform float inDofEnabled; // Shadow strength for SSAO uniform float inAoStrength; // 1.0 if enabled, 0.0 if disabled @@ -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); +} + +float depthToZ(float depth) { + float eyeZ = ((height * 0.57735) /2.0); + float near = eyeZ / 10.0; + float far = eyeZ * 10.0; + float depthNormalized = 2.0 * depth - 1.0; + return 2.0 * near * far / (far + near - depthNormalized * (far - near)); +} + +float calcBlur(float z, float pixelScale) { + return clamp(abs(z - 300.0), 0.0, 0.5*pixelScale); +} + +vec4 applyBlur(vec2 texCoord) { + float pixelScale = max(width, height); + float origZ = depthToZ(texture2D(inDepthTex, texCoord).x); + float blurAmt = calcBlur(origZ, pixelScale); + + float total = 1.0; + vec4 color = texture2D(inRGBTex, texCoord); + // number of samples can be optimized. + for (int i = 0; i < 64; i++) { + float t = (float(i) / float(64)); + float angle = (t * 4.0) * 6.28319; + float radius = (t * 2. - 1.); + angle += 1.0 * rand(gl_FragCoord.xy); + 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.)); + // weight *= 1.0 / radius; // multiplying weight by inverse of sample distribution + vec4 sample = texture2D(inRGBTex, texCoord + offset); + color += weight * sample; + total += weight; + } + return color / total; +} + const vec2 SSAOkernel[16] = vec2[16]( vec2(0.072170, 0.081556), vec2(-0.035126, 0.056701), @@ -113,13 +156,20 @@ float computeEdgeLuminosity(vec3 normal) return max(0.0, pow(normal.z - 0.1, 1.0 / 3.0)); } -void main() -{ +void main() { + // Some cleanups required. float luminosity = 1.0; luminosity *= max(1.2 * (1.0 - inAoEnabled), computeSSAOLuminosity(getNormalNear(UV))); luminosity *= max(1.0 - inEdStrength, computeEdgeLuminosity(getNormalAt(UV))); - vec4 color = texture2D(inRGBTex, UV); - gl_FragColor = vec4(color.xyz * luminosity, color.w); + if(inDofEnabled == 0.0){ + gl_FragColor = vec4(color.xyz * luminosity, color.w); + } + else { + // Apply blur to the color texture + vec4 blurredColor = applyBlur(UV); + vec4 blurColor = vec4(luminosity * blurredColor.xyz, blurredColor.w); + gl_FragColor = blurColor; + } gl_FragDepth = texture2D(inDepthTex, UV).x; -} +} \ No newline at end of file diff --git a/avogadro/rendering/solidpipeline.h b/avogadro/rendering/solidpipeline.h index 8c982bdc2d..fd00b488c4 100644 --- a/avogadro/rendering/solidpipeline.h +++ b/avogadro/rendering/solidpipeline.h @@ -52,6 +52,12 @@ class SolidPipeline bool getAoEnabled() { return m_aoEnabled; } void setAoEnabled(bool enabled) { m_aoEnabled = enabled; } + /** + * @brief Get or set whether Depth-of-feild is enabled. + */ + bool getDofEnabled() { return m_dofEnabled; } + void setDofEnabled(bool enabled) { m_dofEnabled = enabled; } + /** * @brief Get or set shadow strength for Ambient Occlusion. */ @@ -77,6 +83,7 @@ class SolidPipeline private: float m_pixelRatio; bool m_aoEnabled; + bool m_dofEnabled; float m_aoStrength; bool m_edEnabled; float m_edStrength; From d7e5b100acf5cf879612673fc49e89706c9bd591 Mon Sep 17 00:00:00 2001 From: Perminder Date: Thu, 11 Apr 2024 08:04:02 +0530 Subject: [PATCH 02/11] Uniforms Signed-off-by: Perminder --- avogadro/rendering/solidpipeline.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index a313d99b82..b8d6a48857 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -85,7 +85,7 @@ void initializeFramebuffer(GLuint* outFBO, GLuint* texRGB, GLuint* texDepth) } SolidPipeline::SolidPipeline() - : m_pixelRatio(1.0f), m_aoEnabled(true), m_aoStrength(1.0f), + : m_pixelRatio(1.0f), m_aoEnabled(true), m_dofEnabled(true), m_aoStrength(1.0f), m_edEnabled(true), m_edStrength(1.0f), m_width(0), m_height(0), d(new Private) { @@ -156,6 +156,7 @@ void SolidPipeline::end() d->attachStage(d->firstStageShaders, "inRGBTex", d->renderTexture, "inDepthTex", d->depthTexture, m_width, m_height); d->firstStageShaders.setUniformValue("inAoEnabled", m_aoEnabled ? 1.0f : 0.0f); + d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? 1.0f : 0.0f); d->firstStageShaders.setUniformValue("inAoStrength", m_aoStrength); d->firstStageShaders.setUniformValue("inEdStrength", m_edStrength); glDrawArrays(GL_TRIANGLES, 0, 6); From f99fbb728456cbc3deaf895754436f8248ddfc61 Mon Sep 17 00:00:00 2001 From: Perminder Date: Thu, 11 Apr 2024 21:58:33 +0530 Subject: [PATCH 03/11] not-close-blur Signed-off-by: Perminder --- avogadro/rendering/solid_first_fs.glsl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index 741bd6c1db..aa787fd61d 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -74,14 +74,14 @@ float rand(vec2 co){ float depthToZ(float depth) { float eyeZ = ((height * 0.57735) /2.0); - float near = eyeZ / 10.0; - float far = eyeZ * 10.0; + float near = 5.0; + float far = 600.0; float depthNormalized = 2.0 * depth - 1.0; return 2.0 * near * far / (far + near - depthNormalized * (far - near)); } float calcBlur(float z, float pixelScale) { - return clamp(abs(z - 300.0), 0.0, 0.5*pixelScale); + return clamp(abs(z - 39.0), 0.0, 0.5*pixelScale); } vec4 applyBlur(vec2 texCoord) { From cd7059a2a5f664e88e5a1d65e572310b2e1dd86a Mon Sep 17 00:00:00 2001 From: Perminder Date: Sat, 8 Jun 2024 07:45:35 +0530 Subject: [PATCH 04/11] Strength for blur added Signed-off-by: Perminder --- avogadro/rendering/glrenderer.cpp | 1 + avogadro/rendering/solid_first_fs.glsl | 12 +++++++++-- avogadro/rendering/solidpipeline.cpp | 28 ++++++++++++++++++++++++-- avogadro/rendering/solidpipeline.h | 14 ++++++++++++- 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/avogadro/rendering/glrenderer.cpp b/avogadro/rendering/glrenderer.cpp index 4035e7e3e9..b912db8708 100644 --- a/avogadro/rendering/glrenderer.cpp +++ b/avogadro/rendering/glrenderer.cpp @@ -105,6 +105,7 @@ void GLRenderer::render() glDisable(GL_BLEND); m_scene.rootNode().accept(visitor); m_solidPipeline.end(); + m_solidPipeline.adjustOffset(m_camera); // Setup for opaque geometry visitor.setRenderPass(OpaquePass); diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index aa787fd61d..c97da9b5c7 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -31,6 +31,10 @@ uniform float inDofEnabled; uniform float inAoStrength; // 1.0 if enabled, 0.0 if disabled uniform float inEdStrength; +// amount of offset when zoom-in or zoom-out. +uniform float uoffset; +// Dof strength +uniform float inDofStrength; // Rendering surface dimensions, in pixels uniform float width, height; @@ -88,7 +92,11 @@ vec4 applyBlur(vec2 texCoord) { float pixelScale = max(width, height); float origZ = depthToZ(texture2D(inDepthTex, texCoord).x); float blurAmt = calcBlur(origZ, pixelScale); - + float closeZThreshold = uoffset; + // Skip blurring if the original depth is less than the threshold + if (origZ < closeZThreshold) { + return texture2D(inRGBTex, texCoord); +} float total = 1.0; vec4 color = texture2D(inRGBTex, texCoord); // number of samples can be optimized. @@ -97,7 +105,7 @@ vec4 applyBlur(vec2 texCoord) { float angle = (t * 4.0) * 6.28319; float radius = (t * 2. - 1.); angle += 1.0 * rand(gl_FragCoord.xy); - vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * blurAmt) / pixelScale; + vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * inDofStrength) / pixelScale; float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x); float sampleBlur = calcBlur(z, pixelScale); float weight = float((z >= origZ) || (sampleBlur >= blurAmt * radius + 0.)); diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index b8d6a48857..ac8db041b7 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -8,6 +8,7 @@ #include "avogadrogl.h" #include "shader.h" #include "shaderprogram.h" +#include "camera.h" #include "solid_vs.h" @@ -86,7 +87,7 @@ void initializeFramebuffer(GLuint* outFBO, GLuint* texRGB, GLuint* texDepth) SolidPipeline::SolidPipeline() : m_pixelRatio(1.0f), m_aoEnabled(true), m_dofEnabled(true), m_aoStrength(1.0f), - m_edEnabled(true), m_edStrength(1.0f), m_width(0), m_height(0), + m_edEnabled(true), m_edStrength(1.0f), m_width(0), m_height(0), m_dofStrength(1.0f), d(new Private) { } @@ -157,13 +158,36 @@ void SolidPipeline::end() d->depthTexture, m_width, m_height); d->firstStageShaders.setUniformValue("inAoEnabled", m_aoEnabled ? 1.0f : 0.0f); d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? 1.0f : 0.0f); + d->firstStageShaders.setUniformValue("inDofStrength", ((m_dofStrength * 100.0f))); d->firstStageShaders.setUniformValue("inAoStrength", m_aoStrength); d->firstStageShaders.setUniformValue("inEdStrength", m_edStrength); glDrawArrays(GL_TRIANGLES, 0, 6); - + std::cout<<(m_dofStrength * 100.0f)< 200 && offSet < 700) { + offSet = std::pow(1.5, -zTranslation / 10) + 300; + } + if (offSet > 700) { + offSet = -zTranslation * 6; + } + // std::cout<firstStageShaders.setUniformValue("uoffset", offSet); + +} + void SolidPipeline::resize(int width, int height) { m_width = width * m_pixelRatio; diff --git a/avogadro/rendering/solidpipeline.h b/avogadro/rendering/solidpipeline.h index fd00b488c4..e503f3c9f4 100644 --- a/avogadro/rendering/solidpipeline.h +++ b/avogadro/rendering/solidpipeline.h @@ -6,6 +6,8 @@ #ifndef AVOGADRO_RENDERING_SOLIDPIPELINE_H #define AVOGADRO_RENDERING_SOLIDPIPELINE_H +#include "camera.h" + namespace Avogadro { namespace Rendering { @@ -30,7 +32,8 @@ class SolidPipeline * @brief Begin solid geometry rendering. */ void begin(); - + + void adjustOffset(const Camera& camera); /** * @brief End solid geometry rendering and apply screen-space shaders. */ @@ -74,6 +77,13 @@ class SolidPipeline m_edStrength = (m_edEnabled) ? 1.0 : 0.0; } + /** + * @brief Get or set dof strength. + */ + float getDofStrength() { return m_dofStrength; } + void setDofStrength(float strength) { m_dofStrength = strength; } + + /** * @brief Get or set the strength of the edge effect */ @@ -83,6 +93,8 @@ class SolidPipeline private: float m_pixelRatio; bool m_aoEnabled; + Eigen::Affine3f modelView; + float m_dofStrength; bool m_dofEnabled; float m_aoStrength; bool m_edEnabled; From 110d754bd234726144ec467aeb15b86dd3cfe4cf Mon Sep 17 00:00:00 2001 From: Perminder Date: Fri, 21 Jun 2024 02:29:54 +0530 Subject: [PATCH 05/11] dof-position added Signed-off-by: Perminder --- avogadro/rendering/solid_first_fs.glsl | 16 +++++++-------- avogadro/rendering/solidpipeline.cpp | 28 +++++++++++--------------- avogadro/rendering/solidpipeline.h | 6 ++++++ 3 files changed, 25 insertions(+), 25 deletions(-) diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index c97da9b5c7..d94d59eb36 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -35,6 +35,8 @@ uniform float inEdStrength; uniform float uoffset; // Dof strength uniform float inDofStrength; +// Dof position +uniform float inDofPosition; // Rendering surface dimensions, in pixels uniform float width, height; @@ -78,8 +80,8 @@ float rand(vec2 co){ float depthToZ(float depth) { float eyeZ = ((height * 0.57735) /2.0); - float near = 5.0; - float far = 600.0; + float near = 2.0; + float far = 8000.0; float depthNormalized = 2.0 * depth - 1.0; return 2.0 * near * far / (far + near - depthNormalized * (far - near)); } @@ -92,15 +94,13 @@ vec4 applyBlur(vec2 texCoord) { float pixelScale = max(width, height); float origZ = depthToZ(texture2D(inDepthTex, texCoord).x); float blurAmt = calcBlur(origZ, pixelScale); - float closeZThreshold = uoffset; // Skip blurring if the original depth is less than the threshold - if (origZ < closeZThreshold) { + if (origZ < uoffset * inDofPosition) { return texture2D(inRGBTex, texCoord); -} + } float total = 1.0; vec4 color = texture2D(inRGBTex, texCoord); - // number of samples can be optimized. - for (int i = 0; i < 64; i++) { + for (int i = 0; i < 32; i++) { float t = (float(i) / float(64)); float angle = (t * 4.0) * 6.28319; float radius = (t * 2. - 1.); @@ -109,7 +109,6 @@ vec4 applyBlur(vec2 texCoord) { float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x); float sampleBlur = calcBlur(z, pixelScale); float weight = float((z >= origZ) || (sampleBlur >= blurAmt * radius + 0.)); - // weight *= 1.0 / radius; // multiplying weight by inverse of sample distribution vec4 sample = texture2D(inRGBTex, texCoord + offset); color += weight * sample; total += weight; @@ -165,7 +164,6 @@ float computeEdgeLuminosity(vec3 normal) } void main() { - // Some cleanups required. float luminosity = 1.0; luminosity *= max(1.2 * (1.0 - inAoEnabled), computeSSAOLuminosity(getNormalNear(UV))); luminosity *= max(1.0 - inEdStrength, computeEdgeLuminosity(getNormalAt(UV))); diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index ac8db041b7..2cf80dbc1d 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -88,7 +88,7 @@ void initializeFramebuffer(GLuint* outFBO, GLuint* texRGB, GLuint* texDepth) SolidPipeline::SolidPipeline() : m_pixelRatio(1.0f), m_aoEnabled(true), m_dofEnabled(true), m_aoStrength(1.0f), m_edEnabled(true), m_edStrength(1.0f), m_width(0), m_height(0), m_dofStrength(1.0f), - d(new Private) + m_dofPosition(1.0), d(new Private) { } @@ -158,32 +158,28 @@ void SolidPipeline::end() d->depthTexture, m_width, m_height); d->firstStageShaders.setUniformValue("inAoEnabled", m_aoEnabled ? 1.0f : 0.0f); d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? 1.0f : 0.0f); - d->firstStageShaders.setUniformValue("inDofStrength", ((m_dofStrength * 100.0f))); + d->firstStageShaders.setUniformValue("inDofStrength", ((m_dofStrength) * 100.0f)); + d->firstStageShaders.setUniformValue("inDofPosition", ((m_dofPosition) /10.0f)); d->firstStageShaders.setUniformValue("inAoStrength", m_aoStrength); d->firstStageShaders.setUniformValue("inEdStrength", m_edStrength); glDrawArrays(GL_TRIANGLES, 0, 6); - std::cout<<(m_dofStrength * 100.0f)< 200 && offSet < 700) { - offSet = std::pow(1.5, -zTranslation / 10) + 300; - } - if (offSet > 700) { - offSet = -zTranslation * 6; + float offSet = 0.000102337 * pow(project,2) - 3.84689 * project + 36182.2; + if(project >= 21018.106 && project<21595.588){ + offSet = 2.63129 * project - 54768.4; + } + else if(project >= 21595.588 ){ + offSet = 9.952 * project - 212865; } - // std::cout<firstStageShaders.setUniformValue("uoffset", offSet); } diff --git a/avogadro/rendering/solidpipeline.h b/avogadro/rendering/solidpipeline.h index e503f3c9f4..31fee8f028 100644 --- a/avogadro/rendering/solidpipeline.h +++ b/avogadro/rendering/solidpipeline.h @@ -83,6 +83,11 @@ class SolidPipeline float getDofStrength() { return m_dofStrength; } void setDofStrength(float strength) { m_dofStrength = strength; } + /** + * @brief Set positon of dof + */ + float getDofPosition(){ return m_dofPosition;} + void setDofPosition(float position) { m_dofPosition = position; } /** * @brief Get or set the strength of the edge effect @@ -95,6 +100,7 @@ class SolidPipeline bool m_aoEnabled; Eigen::Affine3f modelView; float m_dofStrength; + float m_dofPosition; bool m_dofEnabled; float m_aoStrength; bool m_edEnabled; From 0c272248dae45b131d63eb882898facc007235f3 Mon Sep 17 00:00:00 2001 From: Perminder Date: Thu, 26 Sep 2024 04:37:17 +0530 Subject: [PATCH 06/11] seperating shaders for speed Signed-off-by: Perminder --- avogadro/rendering/CMakeLists.txt | 1 + avogadro/rendering/solid_first_fs.glsl | 36 ++++--------------- avogadro/rendering/solid_fog_fs.glsl | 34 ++++++++++++++++++ avogadro/rendering/solidpipeline.cpp | 48 ++++++++++++++++++++------ avogadro/rendering/solidpipeline.h | 4 +-- 5 files changed, 81 insertions(+), 42 deletions(-) create mode 100644 avogadro/rendering/solid_fog_fs.glsl diff --git a/avogadro/rendering/CMakeLists.txt b/avogadro/rendering/CMakeLists.txt index ddebfe8483..f3a57cc24f 100644 --- a/avogadro/rendering/CMakeLists.txt +++ b/avogadro/rendering/CMakeLists.txt @@ -108,6 +108,7 @@ set(shader_files "mesh_vs.glsl" "solid_vs.glsl" "solid_first_fs.glsl" + "solid_fog_fs.glsl" "spheres_fs.glsl" "spheres_vs.glsl" "sphere_ao_depth_vs.glsl" diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index 3e41fbebff..72fd1c5d32 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -22,32 +22,21 @@ varying vec2 UV; // RGB rendered texture uniform sampler2D inRGBTex; -// RGB color for applying fog -uniform float fogR; -uniform float fogG; -uniform float fogB; -uniform float offset; // Depth rendered texture uniform sampler2D inDepthTex; // 1.0 if enabled, 0.0 if disabled uniform float inAoEnabled; -// 1.0 if enabled, 0.0 if disabled -uniform float inDofEnabled; -// 0.0 if disabled -uniform float inFogStrength; // Shadow strength for SSAO uniform float inAoStrength; // 1.0 if enabled, 0.0 if disabled uniform float inEdStrength; // amount of offset when zoom-in or zoom-out. uniform float uoffset; -// Dof strength +// Dof strength 0.0 if dof is disabled. uniform float inDofStrength; // Dof position uniform float inDofPosition; -// position for other molecules. -uniform float inFogPosition; // Rendering surface dimensions, in pixels uniform float width, height; @@ -127,14 +116,6 @@ vec4 applyBlur(vec2 texCoord) { } return color / total; } -vec4 applyFog(vec2 texCoord) { - vec4 finalColor = mix( - texture2D(inRGBTex, texCoord), - vec4(vec3(fogR, fogG, fogB), 1.), - pow(texture2D(inDepthTex, texCoord.xy).r, uoffset * inFogPosition/10.0) - ) + inFogStrength / 100.0; -return finalColor; -} const vec2 SSAOkernel[16] = vec2[16]( vec2(0.072170, 0.081556), @@ -184,25 +165,20 @@ float computeEdgeLuminosity(vec3 normal) } void main() { - // Some cleanups required. + float luminosity = 1.0; luminosity *= max(1.2 * (1.0 - inAoEnabled), computeSSAOLuminosity(getNormalNear(UV))); luminosity *= max(1.0 - inEdStrength, computeEdgeLuminosity(getNormalAt(UV))); vec4 color = texture2D(inRGBTex, UV); - if (inFogStrength == 0.0 && inDofEnabled == 0.0) { + + if (inDofStrength == 0.0) { gl_FragColor = vec4(color.xyz * luminosity, color.w); - } - else if (inFogStrength != 0.0) { // apply fog since it's fast. - // Apply fog to the color texture - vec4 foggedColor = applyFog(UV); - vec4 fogColor = vec4(luminosity * foggedColor.xyz, foggedColor.w); - gl_FragColor = fogColor; - } - else { + } else { // Apply blur to the color texture vec4 blurredColor = applyBlur(UV); vec4 blurColor = vec4(luminosity * blurredColor.xyz, blurredColor.w); gl_FragColor = blurColor; } + gl_FragDepth = texture2D(inDepthTex, UV).x; } \ No newline at end of file diff --git a/avogadro/rendering/solid_fog_fs.glsl b/avogadro/rendering/solid_fog_fs.glsl new file mode 100644 index 0000000000..093b80560a --- /dev/null +++ b/avogadro/rendering/solid_fog_fs.glsl @@ -0,0 +1,34 @@ +#version 120 + +varying vec2 UV; + +uniform sampler2D inRGBTex; + +uniform float fogR; +uniform float fogG; +uniform float fogB; + +uniform sampler2D inDepthTex; +uniform float inFogStrength; +uniform float uoffset; +uniform float inFogPosition; + +vec4 applyFog(vec2 texCoord) { + vec4 finalColor = mix( + texture2D(inRGBTex, texCoord), + vec4(vec3(fogR, fogG, fogB), 1.), + pow(texture2D(inDepthTex, texCoord.xy).r, uoffset * inFogPosition/10.0) + ) + inFogStrength / 100.0; + +return finalColor; +} + + +void main() { + + vec4 foggedColor = applyFog(UV); + + gl_FragColor = foggedColor; + gl_FragDepth = texture2D(inDepthTex, UV).x; + +} \ No newline at end of file diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index ea6d450405..3deac9a74f 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -9,11 +9,10 @@ #include "shader.h" #include "camera.h" #include "shaderprogram.h" -#include "camera.h" - #include "solid_vs.h" #include "solid_first_fs.h" +#include "solid_fog_fs.h" #include @@ -53,8 +52,10 @@ class SolidPipeline::Private GLuint depthTexture; GLuint screenVBO; ShaderProgram firstStageShaders; + ShaderProgram fogStageShaders; Shader screenVertexShader; Shader firstFragmentShader; + Shader fogFragmentShader; }; static const GLfloat s_fullscreenQuad[] = { @@ -115,15 +116,30 @@ void SolidPipeline::initialize() if (!d->screenVertexShader.compile()) std::cout << d->screenVertexShader.error() << std::endl; + // shader program for fog. + d->fogFragmentShader.setType(Shader::Fragment); + d->fogFragmentShader.setSource(solid_fog_fs); + if(!d->fogFragmentShader.compile()) + std::cout << d->fogFragmentShader.error() << std::endl; + + // shader for ao and blur. d->firstFragmentShader.setType(Shader::Fragment); d->firstFragmentShader.setSource(solid_first_fs); if (!d->firstFragmentShader.compile()) std::cout << d->firstFragmentShader.error() << std::endl; + d->firstStageShaders.attachShader(d->screenVertexShader); d->firstStageShaders.attachShader(d->firstFragmentShader); if (!d->firstStageShaders.link()) std::cout << d->firstStageShaders.error() << std::endl; + + // shaderProgram for fog. + d->fogStageShaders.attachShader(d->screenVertexShader); + d->fogStageShaders.attachShader(d->fogFragmentShader); + if (!d->fogStageShaders.link()) + std::cout << d->fogStageShaders.error() << std::endl; + } void SolidPipeline::begin() @@ -158,20 +174,27 @@ void SolidPipeline::end() glBindFramebuffer(GL_FRAMEBUFFER, 0); glDrawBuffer(GL_BACK); } + + if(m_fogEnabled){ + // shader for fog. + d->attachStage(d->fogStageShaders, "inRGBTex", d->renderTexture, "inDepthTex", + d->depthTexture, m_width, m_height); + d->fogStageShaders.setUniformValue("inFogStrength", m_fogStrength); + d->fogStageShaders.setUniformValue("inFogPosition", m_fogPosition); + d->fogStageShaders.setUniformValue("fogR", (m_backgroundColor[0])/255.0f); + d->fogStageShaders.setUniformValue("fogG", (m_backgroundColor[1])/255.0f); + d->fogStageShaders.setUniformValue("fogB", (m_backgroundColor[2])/255.0f); + } else { d->attachStage(d->firstStageShaders, "inRGBTex", d->renderTexture, "inDepthTex", d->depthTexture, m_width, m_height); d->firstStageShaders.setUniformValue("inAoEnabled", m_aoEnabled ? 1.0f : 0.0f); - d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? 1.0f : 0.0f); + d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? m_dofStrength : 0.0f); d->firstStageShaders.setUniformValue("inDofStrength", ((m_dofStrength) * 100.0f)); d->firstStageShaders.setUniformValue("inDofPosition", ((m_dofPosition) /10.0f)); d->firstStageShaders.setUniformValue("inAoStrength", m_aoStrength); d->firstStageShaders.setUniformValue("inEdStrength", m_edStrength); - d->firstStageShaders.setUniformValue("inFogEnabled", m_fogEnabled ? 1.0f : 0.0f); - d->firstStageShaders.setUniformValue("inFogStrength", m_fogEnabled ? m_fogStrength : 0.0f); - d->firstStageShaders.setUniformValue("inFogPosition", m_fogPosition); - d->firstStageShaders.setUniformValue("fogR", (m_backgroundColor[0])/255.0f); - d->firstStageShaders.setUniformValue("fogG", (m_backgroundColor[1])/255.0f); - d->firstStageShaders.setUniformValue("fogB", (m_backgroundColor[2])/255.0f); + } + glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(0); } @@ -193,7 +216,12 @@ void SolidPipeline::adjustOffset(const Camera& cam) { else if(project >= 21595.588 ){ offSet = 9.952 * project - 212865; } + // setting uniforms. + if (m_fogEnabled){ + d->fogStageShaders.setUniformValue("uoffset", offSet); + } else { d->firstStageShaders.setUniformValue("uoffset", offSet); + } } @@ -216,4 +244,4 @@ void SolidPipeline::setPixelRatio(float ratio) m_pixelRatio = ratio; } -} // End namespace Avogadro::Rendering +} // End namespace Avogadro::Rendering \ No newline at end of file diff --git a/avogadro/rendering/solidpipeline.h b/avogadro/rendering/solidpipeline.h index f00d67a225..8afb534ca1 100644 --- a/avogadro/rendering/solidpipeline.h +++ b/avogadro/rendering/solidpipeline.h @@ -122,12 +122,12 @@ class SolidPipeline private: float m_pixelRatio; bool m_aoEnabled; - Eigen::Affine3f modelView; float m_dofStrength; float m_dofPosition; bool m_dofEnabled; float m_fogPosition; Vector4ub m_backgroundColor; + Eigen::Affine3f modelView; bool m_fogEnabled; float m_aoStrength; float m_fogStrength; @@ -143,4 +143,4 @@ class SolidPipeline } // End namespace Rendering } // End namespace Avogadro -#endif +#endif \ No newline at end of file From 2f53aa452e3897dde992a66ac55ed716939ba70d Mon Sep 17 00:00:00 2001 From: Perminder Singh <127239756+perminder-17@users.noreply.github.com> Date: Thu, 26 Sep 2024 04:51:52 +0530 Subject: [PATCH 07/11] adding smoothstep Signed-off-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com> --- avogadro/rendering/solid_first_fs.glsl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index 72fd1c5d32..4d54b44edc 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -109,7 +109,7 @@ vec4 applyBlur(vec2 texCoord) { vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * inDofStrength) / pixelScale; float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x); float sampleBlur = calcBlur(z, pixelScale); - float weight = float((z >= origZ) || (sampleBlur >= blurAmt * radius + 0.)); + float weight = 1.0 - smoothstep(0.0, 1.0, abs(z - origZ) / blurAmt); vec4 sample = texture2D(inRGBTex, texCoord + offset); color += weight * sample; total += weight; @@ -181,4 +181,4 @@ void main() { } gl_FragDepth = texture2D(inDepthTex, UV).x; -} \ No newline at end of file +} From 2ab576c7102b1b450cdf3e4411d8adf20e432593 Mon Sep 17 00:00:00 2001 From: Perminder Singh <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Sep 2024 06:01:02 +0530 Subject: [PATCH 08/11] cmake-file changes Signed-off-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com> --- avogadro/rendering/CMakeLists.txt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/avogadro/rendering/CMakeLists.txt b/avogadro/rendering/CMakeLists.txt index f3a57cc24f..8adfa070f3 100644 --- a/avogadro/rendering/CMakeLists.txt +++ b/avogadro/rendering/CMakeLists.txt @@ -108,7 +108,6 @@ set(shader_files "mesh_vs.glsl" "solid_vs.glsl" "solid_first_fs.glsl" - "solid_fog_fs.glsl" "spheres_fs.glsl" "spheres_vs.glsl" "sphere_ao_depth_vs.glsl" @@ -149,4 +148,4 @@ target_link_libraries(Rendering if(USE_3DCONNEXION AND (WIN32 OR APPLE)) target_compile_definitions(Rendering PUBLIC _3DCONNEXION) -endif() \ No newline at end of file +endif() From 1af7390c1d171f42cdbc3832a19c16f549a2cf31 Mon Sep 17 00:00:00 2001 From: Perminder Singh <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Sep 2024 06:22:00 +0530 Subject: [PATCH 09/11] applying condition to shader for seperating fog Signed-off-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com> --- avogadro/rendering/solid_first_fs.glsl | 272 +++++++++++++++---------- 1 file changed, 165 insertions(+), 107 deletions(-) diff --git a/avogadro/rendering/solid_first_fs.glsl b/avogadro/rendering/solid_first_fs.glsl index 4d54b44edc..b7295d00f8 100644 --- a/avogadro/rendering/solid_first_fs.glsl +++ b/avogadro/rendering/solid_first_fs.glsl @@ -22,51 +22,60 @@ varying vec2 UV; // RGB rendered texture uniform sampler2D inRGBTex; +// RGB color for applying fog +uniform float fogR; +uniform float fogG; +uniform float fogB; +uniform float offset; // Depth rendered texture uniform sampler2D inDepthTex; // 1.0 if enabled, 0.0 if disabled uniform float inAoEnabled; +// 0.0 if disabled +uniform float inFogStrength; // Shadow strength for SSAO uniform float inAoStrength; // 1.0 if enabled, 0.0 if disabled uniform float inEdStrength; // amount of offset when zoom-in or zoom-out. uniform float uoffset; -// Dof strength 0.0 if dof is disabled. +// Dof strength uniform float inDofStrength; // Dof position uniform float inDofPosition; +// position for other molecules. +uniform float inFogPosition; // Rendering surface dimensions, in pixels uniform float width, height; vec3 getNormalAt(vec2 normalUV) { - float xpos = texture2D(inDepthTex, normalUV + vec2(1.0 / width, 0.0)).x; - float xneg = texture2D(inDepthTex, normalUV - vec2(1.0 / width, 0.0)).x; - float ypos = texture2D(inDepthTex, normalUV + vec2(0.0, 1.0 / height)).x; - float yneg = texture2D(inDepthTex, normalUV - vec2(0.0, 1.0 / height)).x; - float xdelta = xpos - xneg; - float ydelta = ypos - yneg; - vec3 r = vec3(xdelta, ydelta, 1.0 / width + 1.0 / height); - return normalize(r); + float xpos = texture2D(inDepthTex, normalUV + vec2(1.0 / width, 0.0)).x; + float xneg = texture2D(inDepthTex, normalUV - vec2(1.0 / width, 0.0)).x; + float ypos = texture2D(inDepthTex, normalUV + vec2(0.0, 1.0 / height)).x; + float yneg = texture2D(inDepthTex, normalUV - vec2(0.0, 1.0 / height)).x; + float xdelta = xpos - xneg; + float ydelta = ypos - yneg; + vec3 r = vec3(xdelta, ydelta, 1.0 / width + 1.0 / height); + return normalize(r); } vec3 getNormalNear(vec2 normalUV) { - float cent = texture2D(inDepthTex, normalUV).x; - float xpos = texture2D(inDepthTex, normalUV + vec2(1.0 / width, 0.0)).x; - float xneg = texture2D(inDepthTex, normalUV - vec2(1.0 / width, 0.0)).x; - float ypos = texture2D(inDepthTex, normalUV + vec2(0.0, 1.0 / height)).x; - float yneg = texture2D(inDepthTex, normalUV - vec2(0.0, 1.0 / height)).x; - float xposdelta = xpos - cent; - float xnegdelta = cent - xneg; - float yposdelta = ypos - cent; - float ynegdelta = cent - yneg; - float xdelta = abs(xposdelta) > abs(xnegdelta) ? xnegdelta : xposdelta; - float ydelta = abs(yposdelta) > abs(ynegdelta) ? ynegdelta : yposdelta; - vec3 r = vec3(xdelta, ydelta, 0.5 / width + 0.5 / height); - return normalize(r); + float cent = texture2D(inDepthTex, normalUV).x; + float xpos = texture2D(inDepthTex, normalUV + vec2(1.0 / width, 0.0)).x; + float xneg = texture2D(inDepthTex, normalUV - vec2(1.0 / width, 0.0)).x; + float ypos = texture2D(inDepthTex, normalUV + vec2(0.0, 1.0 / height)).x; + float yneg = texture2D(inDepthTex, normalUV - vec2(0.0, 1.0 / height)).x; + float xposdelta = xpos - cent; + float xnegdelta = cent - xneg; + float yposdelta = ypos - cent; + float ynegdelta = cent - yneg; + float xdelta = abs(xposdelta) > abs(xnegdelta) ? xnegdelta : xposdelta; + float ydelta = abs(yposdelta) > abs(ynegdelta) ? ynegdelta : yposdelta; + vec3 r = vec3(xdelta, ydelta, 0.5 / width + 0.5 / height); + return normalize(r); } float lerp(float a, float b, float f) @@ -74,111 +83,160 @@ 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); +float rand(vec2 co) { + return fract(sin(dot(co.xy, vec2(12.9898, 78.233))) * 43758.5453); } float depthToZ(float depth) { - float eyeZ = ((height * 0.57735) /2.0); - float near = 2.0; - float far = 8000.0; - float depthNormalized = 2.0 * depth - 1.0; - return 2.0 * near * far / (far + near - depthNormalized * (far - near)); + float eyeZ = ((height * 0.57735) / 2.0); + float near = 2.0; + float far = 8000.0; + float depthNormalized = 2.0 * depth - 1.0; + return 2.0 * near * far / (far + near - depthNormalized * (far - near)); } float calcBlur(float z, float pixelScale) { - return clamp(abs(z - 39.0), 0.0, 0.5*pixelScale); + return clamp(abs(z - 39.0), 0.0, 0.5 * pixelScale); } vec4 applyBlur(vec2 texCoord) { - float pixelScale = max(width, height); - float origZ = depthToZ(texture2D(inDepthTex, texCoord).x); - float blurAmt = calcBlur(origZ, pixelScale); - // Skip blurring if the original depth is less than the threshold - if (origZ < uoffset * inDofPosition) { - return texture2D(inRGBTex, texCoord); - } - float total = 1.0; - vec4 color = texture2D(inRGBTex, texCoord); - for (int i = 0; i < 32; i++) { - float t = (float(i) / float(64)); - float angle = (t * 4.0) * 6.28319; - float radius = (t * 2. - 1.); - angle += 1.0 * rand(gl_FragCoord.xy); - vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * inDofStrength) / pixelScale; - float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x); - float sampleBlur = calcBlur(z, pixelScale); - float weight = 1.0 - smoothstep(0.0, 1.0, abs(z - origZ) / blurAmt); - vec4 sample = texture2D(inRGBTex, texCoord + offset); - color += weight * sample; - total += weight; - } - return color / total; + float pixelScale = max(width, height); + float origZ = depthToZ(texture2D(inDepthTex, texCoord).x); + float blurAmt = calcBlur(origZ, pixelScale); + // Skip blurring if the original depth is less than the threshold + if (origZ < uoffset * inDofPosition) { + return texture2D(inRGBTex, texCoord); + } + float total = 1.0; + vec4 color = texture2D(inRGBTex, texCoord); + for (int i = 0; i < 32; i++) { + float t = (float(i) / float(64)); + float angle = (t * 4.0) * 6.28319; + float radius = (t * 2. - 1.); + angle += 1.0 * rand(gl_FragCoord.xy); + vec2 offset = (vec2(cos(angle), sin(angle)) * radius * 0.05 * inDofStrength) / pixelScale; + float z = depthToZ(texture2D(inDepthTex, texCoord + offset).x); + float sampleBlur = calcBlur(z, pixelScale); + float weight = 1.0 - smoothstep(0.0, 1.0, abs(z - origZ) / blurAmt); + vec4 + sample = texture2D(inRGBTex, texCoord+offset); + color += weight * sample; + total += weight; +} +return color / total; +} + +vec4 applyFog(vec2 texCoord) { + vec4 finalColor = mix( + texture2D(inRGBTex, texCoord), + vec4(vec3(fogR, fogG, fogB), 1.), + pow(texture2D(inDepthTex, texCoord.xy).r, uoffset * inFogPosition / 10.0) + ) + inFogStrength / 100.0; + return finalColor; } const vec2 SSAOkernel[16] = vec2[16]( - vec2(0.072170, 0.081556), - vec2(-0.035126, 0.056701), - vec2(-0.034186, -0.083598), - vec2(-0.056102, -0.009235), - vec2(0.017487, -0.099822), - vec2(0.071065, 0.015921), - vec2(0.040950, 0.079834), - vec2(-0.087751, 0.065326), - vec2(0.061108, -0.025829), - vec2(0.081262, -0.025854), - vec2(-0.063816, 0.083857), - vec2(0.043747, -0.068586), - vec2(-0.089848, 0.049046), - vec2(-0.065370, 0.058761), - vec2(0.099581, -0.089322), - vec2(-0.032077, -0.042826) -); + vec2(0.072170, 0.081556), + vec2(-0.035126, 0.056701), + vec2(-0.034186, -0.083598), + vec2(-0.056102, -0.009235), + vec2(0.017487, -0.099822), + vec2(0.071065, 0.015921), + vec2(0.040950, 0.079834), + vec2(-0.087751, 0.065326), + vec2(0.061108, -0.025829), + vec2(0.081262, -0.025854), + vec2(-0.063816, 0.083857), + vec2(0.043747, -0.068586), + vec2(-0.089848, 0.049046), + vec2(-0.065370, 0.058761), + vec2(0.099581, -0.089322), + vec2(-0.032077, -0.042826) + ); float computeSSAOLuminosity(vec3 normal) { - float totalOcclusion = 0.0; - float depth = texture2D(inDepthTex, UV).x; - float A = (width * UV.x + 10 * height * UV.y) * 2.0 * 3.14159265358979 * 5.0 / 16.0; - float S = sin(A); - float C = cos(A); - mat2 rotation = mat2( - C, -S, - S, C - ); - for (int i = 0; i < 16; i++) { - vec2 samplePoint = rotation * SSAOkernel[i]; - float occluderDepth = texture2D(inDepthTex, UV + samplePoint).x; - vec3 occluder = vec3(samplePoint.xy, depth - occluderDepth); - float d = length(occluder); - float occlusion = max(0.0, dot(normal, occluder)) * (1.0 / (1.0 + d)); - totalOcclusion += occlusion; - } - - return max(0.0, 1.2 - inAoStrength * totalOcclusion); + float totalOcclusion = 0.0; + float depth = texture2D(inDepthTex, UV).x; + float A = (width * UV.x + 10 * height * UV.y) * 2.0 * 3.14159265358979 * 5.0 / 16.0; + float S = sin(A); + float C = cos(A); + mat2 rotation = mat2( + C, -S, + S, C + ); + for (int i = 0; i < 16; i++) { + vec2 samplePoint = rotation * SSAOkernel[i]; + float occluderDepth = texture2D(inDepthTex, UV + samplePoint).x; + vec3 occluder = vec3(samplePoint.xy, depth - occluderDepth); + float d = length(occluder); + float occlusion = max(0.0, dot(normal, occluder)) * (1.0 / (1.0 + d)); + totalOcclusion += occlusion; + } + + return max(0.0, 1.2 - inAoStrength * totalOcclusion); } float computeEdgeLuminosity(vec3 normal) { - return max(0.0, pow(normal.z - 0.1, 1.0 / 3.0)); + return max(0.0, pow(normal.z - 0.1, 1.0 / 3.0)); } void main() { - - float luminosity = 1.0; - luminosity *= max(1.2 * (1.0 - inAoEnabled), computeSSAOLuminosity(getNormalNear(UV))); - luminosity *= max(1.0 - inEdStrength, computeEdgeLuminosity(getNormalAt(UV))); - vec4 color = texture2D(inRGBTex, UV); - - if (inDofStrength == 0.0) { - gl_FragColor = vec4(color.xyz * luminosity, color.w); - } else { - // Apply blur to the color texture - vec4 blurredColor = applyBlur(UV); - vec4 blurColor = vec4(luminosity * blurredColor.xyz, blurredColor.w); - gl_FragColor = blurColor; - } - - gl_FragDepth = texture2D(inDepthTex, UV).x; + float luminosity = 1.0; + vec4 color = texture2D(inRGBTex, UV); + vec4 finalColor = color; // Initialize finalColor with base color + + // Compute luminosity based on Ambient Occlusion (AO) and Edge Detection + if (inAoEnabled != 0.0) { + luminosity *= max(1.2 * (1.0 - inAoEnabled), computeSSAOLuminosity(getNormalNear(UV))); + } + if (inEdStrength != 0.0) { + luminosity *= max(1.0 - inEdStrength, computeEdgeLuminosity(getNormalAt(UV))); + } + + // Compute foggedColor if Fog is enabled + vec4 foggedColor = color; + if (inFogStrength != 0.0) { + foggedColor = applyFog(UV); + } + + // Compute blurredColor if DOF is enabled + vec4 blurredColor = color; + if (inDofStrength != 0.0) { + blurredColor = applyBlur(UV); + } + + // Determine finalColor based on enabled effects + if (inAoEnabled != 0.0 || inEdStrength != 0.0 || inDofStrength != 0.0) { + if (inFogStrength != 0.0 && inDofStrength != 0.0) { + // Both Fog and DOF are enabled + vec4 mixedColor = mix(foggedColor, blurredColor, 0.5); + finalColor = vec4(mixedColor.rgb * luminosity, mixedColor.a); + } else if (inFogStrength != 0.0) { + // Only Fog is enabled with ao/edge-detection + finalColor = vec4(foggedColor.rgb * luminosity, foggedColor.a); + } else if (inDofStrength != 0.0) { + // Only DOF is enabled with/without ao/edge + finalColor = vec4(blurredColor.rgb * luminosity, blurredColor.a); + } else { + // Only AO and/or Edge Detection are enabled + finalColor = vec4(color.rgb * luminosity, color.a); + } + } else { + // Neither AO, DOF, nor Edge Detection is enabled + if (inFogStrength != 0.0) { + // Only Fog is enabled + finalColor = foggedColor; + } else { + // No effects are enabled + finalColor = color; + } + } + + // Set the final fragment color + gl_FragColor = finalColor; + + // Set fragment depth + gl_FragDepth = texture2D(inDepthTex, UV).x; } From 6fc981cbcb3e31be707e6522f13d8b7f090fd16c Mon Sep 17 00:00:00 2001 From: Perminder Singh <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Sep 2024 06:25:13 +0530 Subject: [PATCH 10/11] delete newly created shader for fog. Signed-off-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com> --- avogadro/rendering/solid_fog_fs.glsl | 34 ---------------------------- 1 file changed, 34 deletions(-) delete mode 100644 avogadro/rendering/solid_fog_fs.glsl diff --git a/avogadro/rendering/solid_fog_fs.glsl b/avogadro/rendering/solid_fog_fs.glsl deleted file mode 100644 index 093b80560a..0000000000 --- a/avogadro/rendering/solid_fog_fs.glsl +++ /dev/null @@ -1,34 +0,0 @@ -#version 120 - -varying vec2 UV; - -uniform sampler2D inRGBTex; - -uniform float fogR; -uniform float fogG; -uniform float fogB; - -uniform sampler2D inDepthTex; -uniform float inFogStrength; -uniform float uoffset; -uniform float inFogPosition; - -vec4 applyFog(vec2 texCoord) { - vec4 finalColor = mix( - texture2D(inRGBTex, texCoord), - vec4(vec3(fogR, fogG, fogB), 1.), - pow(texture2D(inDepthTex, texCoord.xy).r, uoffset * inFogPosition/10.0) - ) + inFogStrength / 100.0; - -return finalColor; -} - - -void main() { - - vec4 foggedColor = applyFog(UV); - - gl_FragColor = foggedColor; - gl_FragDepth = texture2D(inDepthTex, UV).x; - -} \ No newline at end of file From ef20d54ec41fbb4f484edb70fd14aeb8b2225b43 Mon Sep 17 00:00:00 2001 From: Perminder Singh <127239756+perminder-17@users.noreply.github.com> Date: Fri, 27 Sep 2024 06:27:23 +0530 Subject: [PATCH 11/11] fixing solidpipeline.cpp Signed-off-by: Perminder Singh <127239756+perminder-17@users.noreply.github.com> --- avogadro/rendering/solidpipeline.cpp | 49 ++++++---------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/avogadro/rendering/solidpipeline.cpp b/avogadro/rendering/solidpipeline.cpp index 3deac9a74f..eeec7ad0ac 100644 --- a/avogadro/rendering/solidpipeline.cpp +++ b/avogadro/rendering/solidpipeline.cpp @@ -9,10 +9,10 @@ #include "shader.h" #include "camera.h" #include "shaderprogram.h" + #include "solid_vs.h" #include "solid_first_fs.h" -#include "solid_fog_fs.h" #include @@ -52,10 +52,8 @@ class SolidPipeline::Private GLuint depthTexture; GLuint screenVBO; ShaderProgram firstStageShaders; - ShaderProgram fogStageShaders; Shader screenVertexShader; Shader firstFragmentShader; - Shader fogFragmentShader; }; static const GLfloat s_fullscreenQuad[] = { @@ -116,30 +114,15 @@ void SolidPipeline::initialize() if (!d->screenVertexShader.compile()) std::cout << d->screenVertexShader.error() << std::endl; - // shader program for fog. - d->fogFragmentShader.setType(Shader::Fragment); - d->fogFragmentShader.setSource(solid_fog_fs); - if(!d->fogFragmentShader.compile()) - std::cout << d->fogFragmentShader.error() << std::endl; - - // shader for ao and blur. d->firstFragmentShader.setType(Shader::Fragment); d->firstFragmentShader.setSource(solid_first_fs); if (!d->firstFragmentShader.compile()) std::cout << d->firstFragmentShader.error() << std::endl; - d->firstStageShaders.attachShader(d->screenVertexShader); d->firstStageShaders.attachShader(d->firstFragmentShader); if (!d->firstStageShaders.link()) std::cout << d->firstStageShaders.error() << std::endl; - - // shaderProgram for fog. - d->fogStageShaders.attachShader(d->screenVertexShader); - d->fogStageShaders.attachShader(d->fogFragmentShader); - if (!d->fogStageShaders.link()) - std::cout << d->fogStageShaders.error() << std::endl; - } void SolidPipeline::begin() @@ -174,27 +157,20 @@ void SolidPipeline::end() glBindFramebuffer(GL_FRAMEBUFFER, 0); glDrawBuffer(GL_BACK); } - - if(m_fogEnabled){ - // shader for fog. - d->attachStage(d->fogStageShaders, "inRGBTex", d->renderTexture, "inDepthTex", - d->depthTexture, m_width, m_height); - d->fogStageShaders.setUniformValue("inFogStrength", m_fogStrength); - d->fogStageShaders.setUniformValue("inFogPosition", m_fogPosition); - d->fogStageShaders.setUniformValue("fogR", (m_backgroundColor[0])/255.0f); - d->fogStageShaders.setUniformValue("fogG", (m_backgroundColor[1])/255.0f); - d->fogStageShaders.setUniformValue("fogB", (m_backgroundColor[2])/255.0f); - } else { d->attachStage(d->firstStageShaders, "inRGBTex", d->renderTexture, "inDepthTex", d->depthTexture, m_width, m_height); d->firstStageShaders.setUniformValue("inAoEnabled", m_aoEnabled ? 1.0f : 0.0f); - d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? m_dofStrength : 0.0f); - d->firstStageShaders.setUniformValue("inDofStrength", ((m_dofStrength) * 100.0f)); + d->firstStageShaders.setUniformValue("inDofEnabled", m_dofEnabled ? 1.0f : 0.0f); + d->firstStageShaders.setUniformValue("inDofStrength", m_dofEnabled ? (m_dofStrength * 100.0f) : 0.0f); d->firstStageShaders.setUniformValue("inDofPosition", ((m_dofPosition) /10.0f)); d->firstStageShaders.setUniformValue("inAoStrength", m_aoStrength); d->firstStageShaders.setUniformValue("inEdStrength", m_edStrength); - } - + d->firstStageShaders.setUniformValue("inFogEnabled", m_fogEnabled ? 1.0f : 0.0f); + d->firstStageShaders.setUniformValue("inFogStrength", m_fogEnabled ? m_fogStrength : 0.0f); + d->firstStageShaders.setUniformValue("inFogPosition", m_fogPosition); + d->firstStageShaders.setUniformValue("fogR", (m_backgroundColor[0])/255.0f); + d->firstStageShaders.setUniformValue("fogG", (m_backgroundColor[1])/255.0f); + d->firstStageShaders.setUniformValue("fogB", (m_backgroundColor[2])/255.0f); glDrawArrays(GL_TRIANGLES, 0, 6); glDisableVertexAttribArray(0); } @@ -216,12 +192,7 @@ void SolidPipeline::adjustOffset(const Camera& cam) { else if(project >= 21595.588 ){ offSet = 9.952 * project - 212865; } - // setting uniforms. - if (m_fogEnabled){ - d->fogStageShaders.setUniformValue("uoffset", offSet); - } else { d->firstStageShaders.setUniformValue("uoffset", offSet); - } } @@ -244,4 +215,4 @@ void SolidPipeline::setPixelRatio(float ratio) m_pixelRatio = ratio; } -} // End namespace Avogadro::Rendering \ No newline at end of file +} // End namespace Avogadro::Rendering