This commit is contained in:
Jonathas Costa
2019-08-22 17:35:19 -04:00
6 changed files with 22 additions and 63 deletions

View File

@@ -568,8 +568,18 @@ void main() {
// Fragments positions into G-Buffer are written in SGCT Eye Space (View plus Camera Rig Coords)
// when using their positions later, one must convert them to the planet's coords
// =======================
// Get data from G-Buffer
vec4 normal = texture(mainNormalTexture, texCoord);
// =======================
// Normal is stored in SGCT View Space and transformed to the current object space
vec4 normalViewSpaceAndWaterReflectance = texture(mainNormalTexture, texCoord);
dvec4 normalViewSpace = vec4(normalViewSpaceAndWaterReflectance.xyz, 0.0);
dvec4 normalWorldSpace = dSGCTViewToWorldMatrix * normalViewSpace;
vec4 normal = vec4(dInverseModelTransformMatrix * normalWorldSpace);
normal.xyz = normalize(normal.xyz);
normal.w = normalViewSpaceAndWaterReflectance.w;
// Data in the mainPositionTexture are written in view space (view plus camera rig)
vec4 position = texture(mainPositionTexture, texCoord);

View File

@@ -84,10 +84,11 @@ Fragment getFragment() {
frag.color.rgb = diffuseAlbedo;
}
frag.color.a = opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionCameraSpace;
frag.gNormal = vec4(vs_normalViewSpace, 1.0);
frag.color.a = opacity;
frag.depth = vs_screenSpaceDepth;
frag.gPosition = vs_positionCameraSpace;
frag.gNormal = vec4(vs_normalViewSpace, 0.0);
frag.disableLDR2HDR = true;
return frag;

View File

@@ -33,7 +33,6 @@
layout(location = 1) in vec2 in_uv;
out vec4 fs_position;
out vec3 fs_normal;
out vec2 fs_uv;
out vec3 ellipsoidNormalCameraSpace;
out vec3 levelWeights;
@@ -126,7 +125,6 @@ void main() {
fs_position = z_normalization(positionClippingSpace);
gl_Position = fs_position;
ellipsoidNormalCameraSpace = mat3(modelViewTransform) * pair.normal;
fs_normal = pair.normal;
positionCameraSpace = vec3(modelViewTransform * vec4(pair.position, 1.0));
#if USE_ECLIPSE_SHADOWS

View File

@@ -34,7 +34,6 @@ layout(location = 1) in vec2 in_uv;
out vec2 fs_uv;
out vec4 fs_position;
out vec3 fs_normal;
out vec3 ellipsoidNormalCameraSpace;
out vec3 levelWeights;
out vec3 positionCameraSpace;
@@ -56,7 +55,6 @@ uniform vec3 p10;
uniform vec3 p01;
uniform vec3 p11;
uniform vec3 patchNormalCameraSpace;
uniform vec3 patchNormalModelSpace;
uniform float chunkMinHeight;
uniform float distanceScaleFactor;
@@ -110,7 +108,6 @@ void main() {
fs_position = z_normalization(positionClippingSpace);
gl_Position = fs_position;
ellipsoidNormalCameraSpace = patchNormalCameraSpace;
fs_normal = patchNormalModelSpace;
positionCameraSpace = p;
#if USE_ECLIPSE_SHADOWS

View File

@@ -129,7 +129,6 @@ vec4 calcShadow(const ShadowRenderingStruct shadowInfoArray[numberOfShadows],
#endif
in vec4 fs_position;
in vec3 fs_normal;
in vec2 fs_uv;
in vec3 ellipsoidNormalCameraSpace;
in vec3 levelWeights;
@@ -138,10 +137,6 @@ in vec3 positionCameraSpace;
#if USE_ACCURATE_NORMALS
in vec3 ellipsoidTangentThetaCameraSpace;
in vec3 ellipsoidTangentPhiCameraSpace;
// Once deferred light calculations are done in view space this can be removed
// so that we only need one normal; in view space.
uniform mat4 invViewModelTransform;
#endif // USE_ACCURATE_NORMALS
#if USE_ECLIPSE_SHADOWS
@@ -152,11 +147,10 @@ in vec3 positionWorldSpace;
Fragment getFragment() {
Fragment frag;
frag.color = vec4(0.3, 0.3, 0.3, 1.0);
vec3 normal = normalize(ellipsoidNormalCameraSpace);
vec3 normalModelSpace = normalize(fs_normal);
#if USE_ACCURATE_NORMALS
normal = getTileNormal(
fs_uv,
@@ -165,9 +159,6 @@ Fragment getFragment() {
normalize(ellipsoidTangentThetaCameraSpace),
normalize(ellipsoidTangentPhiCameraSpace)
);
// Once deferred light calculations are done in view space this can be removed
// so that we only need one normal; in view space.
normalModelSpace = normalize(mat3(invViewModelTransform) * normal);
#endif /// USE_ACCURATE_NORMALS
#if USE_COLORTEXTURE
@@ -243,11 +234,8 @@ Fragment getFragment() {
#else
frag.gNormal.w = 0;
#endif
// Normal is written Object Space.
// Right now the only renderable using this info is the atm and,
// because all calculation for light interactions are done in Object
// Space, we avoid a new computation saving the normals in Object Space.
frag.gNormal.xyz = normalModelSpace;
// Normal is written View Space (Including SGCT View Matrix).
frag.gNormal.xyz = normal;
if (dot(positionCameraSpace, vec3(1.0)) != 0.0) {
frag.gPosition = vec4(positionCameraSpace, 1.0); // in Camera Rig Space

View File

@@ -761,8 +761,7 @@ void RenderableGlobe::update(const UpdateData& data) {
ghoul::opengl::updateUniformLocations(
*_localRenderer.program,
_localRenderer.uniformCache,
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace",
"patchNormalCameraSpace" }
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" }
);
}
@@ -1024,27 +1023,6 @@ void RenderableGlobe::renderChunks(const RenderData& data, RendererTasks&) {
);
}
if (_generalProperties.useAccurateNormals &&
!_layerManager.layerGroup(layergroupid::HeightLayers).activeLayers().empty())
{
// This should not be needed once the light calculations for the atmosphere
// is performed in view space..
_localRenderer.program->setUniform(
"invViewModelTransform",
glm::inverse(
glm::mat4(data.camera.combinedViewMatrix()) *
glm::mat4(_cachedModelTransform)
)
);
_globalRenderer.program->setUniform(
"invViewModelTransform",
glm::inverse(
glm::mat4(data.camera.combinedViewMatrix()) *
glm::mat4(_cachedModelTransform)
)
);
}
constexpr const int ChunkBufferSize = 2048;
std::array<const Chunk*, ChunkBufferSize> global;
int globalCount = 0;
@@ -1274,6 +1252,7 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
// TODO: Patch normal can be calculated for all corners and then linearly
// interpolated on the GPU to avoid cracks for high altitudes.
// JCC: Camera space includes the SGCT View transformation.
const glm::vec3 patchNormalCameraSpace = normalize(
cross(
cornersCameraSpace[Quad::SOUTH_EAST] - cornersCameraSpace[Quad::SOUTH_WEST],
@@ -1281,19 +1260,6 @@ void RenderableGlobe::renderChunkLocally(const Chunk& chunk, const RenderData& d
)
);
// In order to improve performance, lets use the normal in object space (model space)
// for deferred rendering.
const glm::vec3 patchNormalModelSpace = normalize(
cross(
cornersModelSpace[Quad::SOUTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST],
cornersModelSpace[Quad::NORTH_EAST] - cornersModelSpace[Quad::SOUTH_WEST]
)
);
program.setUniform(
_localRenderer.uniformCache.patchNormalModelSpace,
patchNormalModelSpace
);
program.setUniform(
_localRenderer.uniformCache.patchNormalCameraSpace,
patchNormalCameraSpace
@@ -1598,8 +1564,7 @@ void RenderableGlobe::recompileShaders() {
ghoul::opengl::updateUniformLocations(
*_localRenderer.program,
_localRenderer.uniformCache,
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalModelSpace",
"patchNormalCameraSpace" }
{ "skirtLength", "p01", "p11", "p00", "p10", "patchNormalCameraSpace" }
);