mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 18:36:45 +02:00
a bit better making the curvature and diffusion passes
This commit is contained in:
parent
cfa51ae1f5
commit
378f4576fa
4 changed files with 21 additions and 20 deletions
|
@ -143,7 +143,7 @@ void LinearDepthPass::run(const render::SceneContextPointer& sceneContext, const
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
|
|
||||||
// batch.setResourceTexture(DepthLinearPass_DepthMapSlot, nullptr);
|
// batch.setResourceTexture(DepthLinearPass_DepthMapSlot, nullptr);
|
||||||
batch.generateTextureMips(linearDepthFBO->getRenderBuffer(0));
|
// batch.generateTextureMips(linearDepthFBO->getRenderBuffer(0));
|
||||||
|
|
||||||
_gpuTimer.end(batch);
|
_gpuTimer.end(batch);
|
||||||
});
|
});
|
||||||
|
@ -293,7 +293,7 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
|
||||||
if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
|
if (curvatureFBO->getDepthStencilBuffer() != deferredFramebuffer->getPrimaryDepthTexture()) {
|
||||||
curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
|
curvatureFBO->setDepthStencilBuffer(deferredFramebuffer->getPrimaryDepthTexture(), deferredFramebuffer->getPrimaryDepthTexture()->getTexelFormat());
|
||||||
}
|
}
|
||||||
auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
|
auto curvatureTexture = _surfaceGeometryFramebuffer->getCurvatureTexture();
|
||||||
|
|
||||||
outputs.edit0() = _surfaceGeometryFramebuffer;
|
outputs.edit0() = _surfaceGeometryFramebuffer;
|
||||||
outputs.edit1() = curvatureFBO;
|
outputs.edit1() = curvatureFBO;
|
||||||
|
@ -318,7 +318,9 @@ void SurfaceGeometryPass::run(const render::SceneContextPointer& sceneContext, c
|
||||||
|
|
||||||
// Curvature pass
|
// Curvature pass
|
||||||
batch.setFramebuffer(curvatureFBO);
|
batch.setFramebuffer(curvatureFBO);
|
||||||
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
|
|
||||||
|
// We can avoid the clear by drawing the same clear vallue from the makeCUrvature shader. slightly better than adding the clear
|
||||||
|
// batch.clearColorFramebuffer(gpu::Framebuffer::BUFFER_COLOR0, glm::vec4(0.0));
|
||||||
|
|
||||||
batch.setPipeline(curvaturePipeline);
|
batch.setPipeline(curvaturePipeline);
|
||||||
batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture);
|
batch.setResourceTexture(SurfaceGeometryPass_DepthMapSlot, linearDepthTexture);
|
||||||
|
|
|
@ -110,9 +110,8 @@ void main(void) {
|
||||||
// Fetch the z under the pixel (stereo or not)
|
// Fetch the z under the pixel (stereo or not)
|
||||||
float Zeye = getZEye(framePixelPos);
|
float Zeye = getZEye(framePixelPos);
|
||||||
if (Zeye <= -getPosLinearDepthFar()) {
|
if (Zeye <= -getPosLinearDepthFar()) {
|
||||||
// outFragColor = vec4(0.0);
|
outFragColor = vec4(0.0);
|
||||||
// return;
|
return;
|
||||||
discard;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float nearPlaneScale = 0.5 * getProjectionNear();
|
float nearPlaneScale = 0.5 * getProjectionNear();
|
||||||
|
@ -121,13 +120,13 @@ void main(void) {
|
||||||
|
|
||||||
// The position of the pixel fragment in Eye space then in world space
|
// The position of the pixel fragment in Eye space then in world space
|
||||||
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
|
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
|
||||||
vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz;
|
// vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz;
|
||||||
|
|
||||||
if (texcoordPos.y > 0.5) {
|
/* if (texcoordPos.y > 0.5) {
|
||||||
outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
||||||
} else {
|
} else {
|
||||||
outFragColor = vec4(fract(10.0 * eyePos.xyz), 1.0);
|
outFragColor = vec4(fract(10.0 * eyePos.xyz), 1.0);
|
||||||
}
|
}*/
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
// Calculate the perspective scale.
|
// Calculate the perspective scale.
|
||||||
|
@ -160,11 +159,11 @@ void main(void) {
|
||||||
vec4 pz = vec4(eyePos + az, 0.0);
|
vec4 pz = vec4(eyePos + az, 0.0);
|
||||||
|
|
||||||
|
|
||||||
if (texcoordPos.y > 0.5) {
|
/* if (texcoordPos.y > 0.5) {
|
||||||
outFragColor = vec4(fract(px.xyz), 1.0);
|
outFragColor = vec4(fract(px.xyz), 1.0);
|
||||||
} else {
|
} else {
|
||||||
outFragColor = vec4(fract(eyePos.xyz), 1.0);
|
outFragColor = vec4(fract(eyePos.xyz), 1.0);
|
||||||
}
|
}*/
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
|
|
||||||
|
@ -201,14 +200,14 @@ void main(void) {
|
||||||
vec4 clipPos = getProjectionMono() * vec4(eyePos, 1.0);
|
vec4 clipPos = getProjectionMono() * vec4(eyePos, 1.0);
|
||||||
nclipPos = clipPos.xy / clipPos.w;
|
nclipPos = clipPos.xy / clipPos.w;
|
||||||
|
|
||||||
if (texcoordPos.y > 0.5) {
|
/* if (texcoordPos.y > 0.5) {
|
||||||
// outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
// outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
||||||
outFragColor = vec4(fract(10.0 * (nclipPos)), 0.0, 1.0);
|
outFragColor = vec4(fract(10.0 * (nclipPos)), 0.0, 1.0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
outFragColor = vec4(fract(10.0 * (clipPos.xy / clipPos.w)), 0.0, 1.0);
|
outFragColor = vec4(fract(10.0 * (clipPos.xy / clipPos.w)), 0.0, 1.0);
|
||||||
// outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0);
|
// outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0);
|
||||||
}
|
}*/
|
||||||
//return;
|
//return;
|
||||||
|
|
||||||
|
|
||||||
|
@ -217,14 +216,14 @@ void main(void) {
|
||||||
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv;
|
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||||
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv;
|
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||||
|
|
||||||
if (texcoordPos.y > 0.5) {
|
/* if (texcoordPos.y > 0.5) {
|
||||||
// outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
// outFragColor = vec4(fract(10.0 * worldPos.xyz), 1.0);
|
||||||
outFragColor = vec4(fract(10.0 * (px.xy)), 0.0, 1.0);
|
outFragColor = vec4(fract(10.0 * (px.xy)), 0.0, 1.0);
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
outFragColor = vec4(fract(10.0 * (py.xy)), 0.0, 1.0);
|
outFragColor = vec4(fract(10.0 * (py.xy)), 0.0, 1.0);
|
||||||
// outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0);
|
// outFragColor = vec4(nclipPos * 0.5 + 0.5, 0.0, 1.0);
|
||||||
}
|
}*/
|
||||||
// return;
|
// return;
|
||||||
|
|
||||||
// Calculate dF/dx, dF/dy and dF/dz using chain rule
|
// Calculate dF/dx, dF/dy and dF/dz using chain rule
|
||||||
|
@ -234,10 +233,10 @@ void main(void) {
|
||||||
|
|
||||||
vec3 trace = vec3(dFdx.x, dFdy.y, dFdz.z);
|
vec3 trace = vec3(dFdx.x, dFdy.y, dFdz.z);
|
||||||
|
|
||||||
if (dot(trace, trace) > params.curvatureInfo.w) {
|
/*if (dot(trace, trace) > params.curvatureInfo.w) {
|
||||||
outFragColor = vec4(dFdx.x, dFdy.y, dFdz.z, 1.0);
|
outFragColor = vec4(dFdx.x, dFdy.y, dFdz.z, 1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
// Calculate the mean curvature
|
// Calculate the mean curvature
|
||||||
float meanCurvature = ((trace.x + trace.y + trace.z) * 0.33333333333333333) * params.curvatureInfo.w;
|
float meanCurvature = ((trace.x + trace.y + trace.z) * 0.33333333333333333) * params.curvatureInfo.w;
|
||||||
|
|
|
@ -228,7 +228,6 @@ void BlurGaussian::run(const SceneContextPointer& sceneContext, const RenderCont
|
||||||
_parameters->setWidthHeight(args->_viewport.z, args->_viewport.w, args->_context->isStereo());
|
_parameters->setWidthHeight(args->_viewport.z, args->_viewport.w, args->_context->isStereo());
|
||||||
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
||||||
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
||||||
_parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
|
|
||||||
|
|
||||||
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
|
||||||
batch.enableStereo(false);
|
batch.enableStereo(false);
|
||||||
|
@ -341,6 +340,7 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const
|
||||||
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
glm::ivec2 textureSize(blurringResources.sourceTexture->getDimensions());
|
||||||
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
_parameters->setTexcoordTransform(gpu::Framebuffer::evalSubregionTexcoordTransformCoefficients(textureSize, args->_viewport));
|
||||||
_parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
_parameters->setDepthPerspective(args->getViewFrustum().getProjection()[1][1]);
|
||||||
|
_parameters->setLinearDepthPosFar(args->getViewFrustum().getFarClip());
|
||||||
|
|
||||||
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
|
||||||
batch.enableStereo(false);
|
batch.enableStereo(false);
|
||||||
|
|
|
@ -97,9 +97,9 @@ uniform sampler2D depthMap;
|
||||||
|
|
||||||
vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep) {
|
vec4 pixelShaderGaussianDepthAware(vec2 texcoord, vec2 direction, vec2 pixelStep) {
|
||||||
texcoord = evalTexcoordTransformed(texcoord);
|
texcoord = evalTexcoordTransformed(texcoord);
|
||||||
float sampleDepth = -texture(depthMap, texcoord).x;
|
float sampleDepth = texture(depthMap, texcoord).x;
|
||||||
vec4 sampleCenter = texture(sourceMap, texcoord);
|
vec4 sampleCenter = texture(sourceMap, texcoord);
|
||||||
if (sampleDepth <= getPosLinearDepthFar()) {
|
if (sampleDepth >= getPosLinearDepthFar()) {
|
||||||
discard;
|
discard;
|
||||||
//return sampleCenter;
|
//return sampleCenter;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue