mirror of
https://github.com/overte-org/overte.git
synced 2025-04-15 17:20:12 +02:00
trying to fix the curvature artefact
This commit is contained in:
parent
0c882832bf
commit
bd28498833
3 changed files with 35 additions and 12 deletions
|
@ -50,6 +50,13 @@ mat4 getProjection(int side) {
|
|||
return frameTransform._projection[side];
|
||||
}
|
||||
|
||||
// positive near distance of the projection
|
||||
float getProjectionNear() {
|
||||
float planeC = frameTransform._projection[0][2][3] + frameTransform._projection[0][2][2];
|
||||
float planeD = frameTransform._projection[0][3][2];
|
||||
return planeD / planeC;
|
||||
}
|
||||
|
||||
mat4 getViewInverse() {
|
||||
return frameTransform._viewInverse;
|
||||
}
|
||||
|
|
|
@ -118,6 +118,8 @@ void main(void) {
|
|||
// Fetch the z under the pixel (stereo or not)
|
||||
float Zeye = getZEye(framePixelPos);
|
||||
|
||||
float nearPlaneScale = min(-Zeye / getCurvatureBasisScale(), 1.0);
|
||||
|
||||
vec3 worldNormal = getWorldNormal(frameTexcoordPos);
|
||||
|
||||
// The position of the pixel fragment in Eye space then in world space
|
||||
|
@ -125,26 +127,40 @@ void main(void) {
|
|||
vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz;
|
||||
|
||||
// Calculate the perspective scale.
|
||||
float perspectiveScale = (-getProjScaleEye() / Zeye);
|
||||
|
||||
vec2 viewportScale = perspectiveScale * getInvWidthHeight();
|
||||
// Clamp to 0.5
|
||||
float perspectiveScale = max(0.5, (-getProjScaleEye() / Zeye));
|
||||
// float perspectiveScale = max(0.5, (-getProjectionNear() / Zeye));
|
||||
|
||||
// Calculate dF/du and dF/dv
|
||||
float threshold = getCurvatureDepthThreshold();
|
||||
vec2 du = vec2( 1.0f, 0.0f ) * viewportScale.x;
|
||||
vec2 dv = vec2( 0.0f, 1.0f ) * viewportScale.y;
|
||||
vec2 viewportScale = perspectiveScale * getInvWidthHeight();
|
||||
vec2 du = vec2( viewportScale.x, 0.0f );
|
||||
vec2 dv = vec2( 0.0f, viewportScale.y );
|
||||
|
||||
vec4 dFdu = vec4(getWorldNormalDiff(frameTexcoordPos, du), getEyeDepthDiff(frameTexcoordPos, du));
|
||||
vec4 dFdv = vec4(getWorldNormalDiff(frameTexcoordPos, dv), getEyeDepthDiff(frameTexcoordPos, dv));
|
||||
|
||||
float threshold = getCurvatureDepthThreshold();
|
||||
dFdu *= step(abs(dFdu.w), threshold);
|
||||
dFdv *= step(abs(dFdv.w), threshold);
|
||||
|
||||
// outFragColor = vec4(dFdu.xyz, 1.0);
|
||||
|
||||
//outFragColor = vec4(du.x, du.y, 0.0, 1.0);
|
||||
// outFragColor = vec4(viewportScale, 0.0, 1.0);
|
||||
/* if (perspectiveScale < getCurvatureBasisScale()) {
|
||||
//outFragColor = vec4(0.0, 0.0, 4 * perspectiveScale, 1.0);
|
||||
} else if (perspectiveScale < 0.5) {
|
||||
outFragColor = vec4(0.0, 0.0, 2 * perspectiveScale, 1.0);
|
||||
return;
|
||||
} else if (perspectiveScale > 1.0) {
|
||||
outFragColor = vec4(perspectiveScale, 0.0, 0.0, 1.0);s
|
||||
return;
|
||||
} else {
|
||||
outFragColor = vec4(0.0, 0.5 * perspectiveScale, 0.0, 1.0);
|
||||
return;
|
||||
}*/
|
||||
// Calculate ( du/dx, du/dy, du/dz ) and ( dv/dx, dv/dy, dv/dz )
|
||||
|
||||
// Eval px, py, pz world positions of the basis centered on the world pos of the fragment
|
||||
float dist = getCurvatureBasisScale();
|
||||
float dist = getCurvatureBasisScale() * nearPlaneScale;
|
||||
vec4 px = vec4(worldPos, 1.0) + vec4(dist, 0.0f, 0.0f, 0.0f);
|
||||
vec4 py = vec4(worldPos, 1.0) + vec4(0.0f, dist, 0.0f, 0.0f);
|
||||
vec4 pz = vec4(worldPos, 1.0) + vec4(0.0f, 0.0f, dist, 0.0f);
|
||||
|
@ -183,8 +199,7 @@ void main(void) {
|
|||
return;
|
||||
*/
|
||||
|
||||
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale);
|
||||
//vec2 pixPerspectiveScaleInv = 1.0 / viewportScale;
|
||||
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale * nearPlaneScale);
|
||||
px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||
|
|
|
@ -49,6 +49,7 @@ Column {
|
|||
"Unlit",
|
||||
"Occlusion",
|
||||
"Lightmap",
|
||||
"Scattering",
|
||||
"Lighting",
|
||||
"Shadow",
|
||||
"Pyramid Depth",
|
||||
|
@ -56,7 +57,7 @@ Column {
|
|||
"NormalCurvature",
|
||||
"DiffusedCurvature",
|
||||
"DiffusedNormalCurvature",
|
||||
"Scattering",
|
||||
"Debug Scattering",
|
||||
"Ambient Occlusion",
|
||||
"Ambient Occlusion Blurred",
|
||||
"Custom Shader"
|
||||
|
|
Loading…
Reference in a new issue