I’m doing highmap dependant rendering in a fragment shader.
I switch to tangent space, cast a ray from camera position and stop where it gets below highmap.
So I calculate my tangent coord like this:
tangentSpacePosition = (_toTangentSpaceMatrix * vec4(ViewPosition, 1.0));
This works fine.
In fragment shader by ray tracing I find the tangent space position, where the ray hits the highmap.
THe Object really shows up 3D as intended.
I need to set the gl_FragDepth from this position.
That’s how I do it:
`
mat4 backTransformMatrix = inverseOrthogonalMatrix(_toTangentSpaceMatrix); // Back to viewspace
mat4 backToProjectionMatrix = osg_ProjectionMatrix * backTransformMatrix; // Projection
vec4 hitPoint = backToProjectionMatrix * vec4(hitPointTangent, 1);
float fragDepth = (hitPoint.z / hitPoint.w + 1.0) * 0.5;
If I use this for export in a highmap and/or set it to
gl_FragDepth = fragDepth;
it gives non satisfying results. Setting gl_FragDepth like that results in a fragmented object. Her my optical test:
outFragment[0] = vec4(vec3(fragDepth), 1.0f);
`
shows me a depth varying with the zoom of the sceene. So obviously I’m missing something important.
Thanks for any hints.
user26601718 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.