Merge pull request #943 from OpenSpace/feature/hdrOS

HDR Rendering Branch
This commit is contained in:
Alexander Bock
2019-08-20 02:05:42 -06:00
committed by GitHub
31 changed files with 935 additions and 756 deletions
@@ -147,7 +147,7 @@ AtmosphereDeferredcaster::AtmosphereDeferredcaster()
, _ozoneHeightScale(0.f)
, _mieHeightScale(0.f)
, _miePhaseConstant(0.f)
, _sunRadianceIntensity(50.0f)
, _sunRadianceIntensity(5.f)
, _rayleighScatteringCoeff(glm::vec3(0.f))
, _ozoneExtinctionCoeff(glm::vec3(0.f))
, _mieScatteringCoeff(glm::vec3(0.f))
@@ -265,7 +265,8 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
, _ozoneHeightScale(0.f)
, _mieHeightScale(0.f)
, _miePhaseConstant(0.f)
, _sunRadianceIntensity(50.f)
, _sunRadianceIntensity(5.f)
, _mieScattExtPropCoefProp(1.f)
, _mieExtinctionCoeff(glm::vec3(0.f))
, _rayleighScatteringCoeff(glm::vec3(0.f))
, _ozoneExtinctionCoeff(glm::vec3(0.f))
@@ -403,6 +404,17 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
"Atmosphere Effects. Disabling atmosphere effects for this planet."
);
}
if (atmosphereDictionary.hasKey(SunIntensityInfo.identifier)) {
_sunRadianceIntensity =
atmosphereDictionary.value<float>(SunIntensityInfo.identifier);
}
if (atmosphereDictionary.hasKey(MieScatteringExtinctionPropCoeffInfo.identifier)) {
_mieScattExtPropCoefProp = atmosphereDictionary.value<float>(
MieScatteringExtinctionPropCoeffInfo.identifier
);
}
if (!atmosphereDictionary.getValue(
GroundRadianceEmittioninfo.identifier,
@@ -628,8 +640,10 @@ RenderableAtmosphere::RenderableAtmosphere(const ghoul::Dictionary& dictionary)
_mieScatteringCoeffZP.onChange(updateAtmosphere);
addProperty(_mieScatteringCoeffZP);
_mieScatteringExtinctionPropCoefficientP =
_mieScatteringExtinctionPropCoefficientP =
_mieScattExtPropCoefProp != 1.f ? _mieScattExtPropCoefProp :
_mieScatteringCoeff.x / _mieExtinctionCoeff.x;
_mieScatteringExtinctionPropCoefficientP.onChange(updateAtmosphere);
addProperty(_mieScatteringExtinctionPropCoefficientP);
@@ -122,6 +122,7 @@ private:
float _mieHeightScale;
float _miePhaseConstant;
float _sunRadianceIntensity;
float _mieScattExtPropCoefProp;
glm::vec3 _mieExtinctionCoeff;
glm::vec3 _rayleighScatteringCoeff;
@@ -61,23 +61,14 @@
#include "floatoperations.glsl"
#include "hdr.glsl"
#include "atmosphere_common.glsl"
out vec4 renderTarget;
in vec3 interpolatedNDCPos;
uniform int nAaSamples;
uniform double msaaSamplePatter[48];
uniform int cullAtmosphere;
// The following uniforms are
// set into the current Renderer
// Background exposure hack
uniform float backgroundConstant;
uniform bool firstPaint;
uniform float atmExposure;
uniform sampler2D irradianceTexture;
uniform sampler3D inscatterTexture;
uniform sampler2DMS mainPositionTexture;
@@ -92,8 +83,6 @@ uniform dmat4 dSgctProjectionToModelTransformMatrix;
uniform dvec4 dCamPosObj;
uniform dvec3 sunDirectionObj;
uniform float blackoutFactor;
/*******************************************************************************
***** ALL CALCULATIONS FOR ECLIPSE ARE IN METERS AND IN WORLD SPACE SYSTEM ****
*******************************************************************************/
@@ -244,13 +233,6 @@ bool dAtmosphereIntersection(const dvec3 planetPosition, const dRay ray, const d
void dCalculateRayRenderableGlobe(in int mssaSample, out dRay ray,
out dvec4 planetPositionObjectCoords,
out dvec4 cameraPositionInObject) {
// ======================================
// ======= Avoiding Some Matrices =======
// Compute positions and directions in object space.
dvec2 samplePos = dvec2(msaaSamplePatter[mssaSample],
msaaSamplePatter[mssaSample+1]);
dvec4 clipCoords = dvec4(interpolatedNDCPos.xy, 1.0, 1.0);
// Clip to Object Coords
@@ -317,7 +299,7 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
// through the atmosphere. If this ray hits something inside the atmosphere,
// we will subtract the attenuated scattering light from that path in the
// current path.
vec4 inscatterRadiance = max(texture4D(inscatterTexture, r, mu, muSun, nu), 0.0);
vec4 inscatterRadiance = max(texture4D(inscatterTexture, r, mu, muSun, nu), 0.0);
// After removing the initial path from camera pos to top of atmosphere (for an
// observer in the space) we test if the light ray is hitting the atmosphere
@@ -365,7 +347,7 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
if (abs(mu - muHorizon) < INTERPOLATION_EPS) {
// We want an interpolation value close to 1/2, so the
// contribution of each radiance value is almost the same
// or it has a havey weight if from above or below horizon
// or it has a heavy weight if from above or below horizon
float interpolationValue = ((mu - muHorizon) + INTERPOLATION_EPS) / (2.0f * INTERPOLATION_EPS);
//float t2 = t * t;
@@ -426,10 +408,14 @@ vec3 inscatterRadiance(inout vec3 x, inout float t, inout float irradianceFactor
// we can change it on the fly with no precomputations)
// return radiance * sunRadiance;
vec3 finalScatteringRadiance = radiance * sunIntensity;
if (groundHit) {
return finalScatteringRadiance;
} else {
return ((r-Rg) * invRtMinusRg)*spaceColor.rgb * backgroundConstant + finalScatteringRadiance;
//return ((r-Rg) * invRtMinusRg)*spaceColor.rgb + finalScatteringRadiance;
return attenuation * spaceColor.rgb + finalScatteringRadiance;
// return attenuation * spaceColor.rgb +
// (vec3(1.0) - attenuation) * finalScatteringRadiance;
}
}
@@ -536,9 +522,10 @@ vec3 sunColor(const vec3 x, const float t, const vec3 v, const vec3 s, const flo
vec3(0.0f) : transmittanceLUT(r, mu)) : vec3(1.0f);
// JCC: Change this function to a impostor texture with gaussian decay color weighted
// by tge sunRadiance, transmittance and irradianceColor (11/03/2017)
float sunFinalColor = step(cos(M_PI / 650.0f), dot(v, s)) * sunRadiance * (1.0f- irradianceFactor);
float sunFinalColor = smoothstep(cos(M_PI / 500.0f), cos(M_PI / 900.0f), dot(v, s)) *
sunRadiance * (1.0f - irradianceFactor);
return transmittance * sunFinalColor;
return transmittance * sunFinalColor;
}
void main() {
@@ -562,16 +549,9 @@ void main() {
}
nSamples = complex ? nAaSamples / 2 : 1;
// Performance variables:
//float Rt2 = Rt * Rt; // in Km
//float Rg2 = Rg * Rg; // in Km
for (int i = 0; i < nSamples; i++) {
// Color from G-Buffer
//vec4 color = texelFetch(mainColorTexture, fragCoords, i);
vec4 color = colorArray[i];
// Ray in object space
dRay ray;
dvec4 planetPositionObjectCoords = dvec4(0.0);
@@ -635,9 +615,9 @@ void main() {
pixelDepth *= 0.001;
positionObjectsCoords.xyz *= 0.001;
if (position.xyz != vec3(0.0) && (pixelDepth < offset)) {
if (pixelDepth < offset) {
// ATM Occluded - Something in fron of ATM.
atmosphereFinalColor += vec4(HDR(color.xyz * backgroundConstant, atmExposure), color.a);
atmosphereFinalColor += color;
} else {
// Following paper nomenclature
double t = offset;
@@ -686,35 +666,26 @@ void main() {
}
// Final Color of ATM plus terrain:
vec4 finalRadiance = vec4(HDR(inscatterColor + groundColorV + sunColorV, atmExposure), 1.0);
vec4 finalRadiance = vec4(inscatterColor + groundColorV + sunColorV, 1.0);
atmosphereFinalColor += finalRadiance;
}
}
else { // no intersection
atmosphereFinalColor += vec4(HDR(color.xyz * backgroundConstant, atmExposure), color.a);
// Buffer color
atmosphereFinalColor += color;
}
}
renderTarget = atmosphereFinalColor / float(nSamples);
renderTarget.a *= blackoutFactor;
// if (complex)
// renderTarget = vec4(1.0, 0.0, 0.0, 1.0);
renderTarget = atmosphereFinalColor / float(nSamples);
}
else { // culling
if (firstPaint) {
vec4 bColor = vec4(0.0f);
for (int f = 0; f < nAaSamples; f++) {
bColor += texelFetch(mainColorTexture, fragCoords, f);
}
bColor /= float(nAaSamples);
renderTarget = vec4(HDR(bColor.xyz * backgroundConstant, atmExposure), bColor.a * blackoutFactor);
}
else {
discard;
vec4 bColor = vec4(0.0f);
for (int f = 0; f < nAaSamples; f++) {
bColor += texelFetch(mainColorTexture, fragCoords, f);
}
//renderTarget = vec4(1.0, 0.0, 0.0, 1.0);
bColor /= float(nAaSamples);
renderTarget = bColor;
}
}
+7 -1
View File
@@ -127,7 +127,7 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
_blendMode.onChange([&]() {
switch (_blendMode) {
case BlendModeNormal:
setRenderBin(Renderable::RenderBin::Opaque);
setRenderBinFromOpacity();
break;
case BlendModeAdditive:
setRenderBin(Renderable::RenderBin::Transparent);
@@ -137,6 +137,12 @@ RenderablePlane::RenderablePlane(const ghoul::Dictionary& dictionary)
}
});
_opacity.onChange([&]() {
if (_blendMode == BlendModeNormal) {
setRenderBinFromOpacity();
}
});
if (dictionary.hasKey(BlendModeInfo.identifier)) {
const std::string v = dictionary.value<std::string>(BlendModeInfo.identifier);
if (v == "Normal") {
+3 -1
View File
@@ -67,12 +67,14 @@ protected:
virtual void bindTexture();
virtual void unbindTexture();
protected:
properties::OptionProperty _blendMode;
private:
void createPlane();
properties::BoolProperty _billboard;
properties::FloatProperty _size;
properties::OptionProperty _blendMode;
ghoul::opengl::ProgramObject* _shader = nullptr;
@@ -85,6 +85,8 @@ RenderablePlaneImageLocal::RenderablePlaneImageLocal(const ghoul::Dictionary& di
"RenderablePlaneImageLocal"
);
addProperty(_blendMode);
_texturePath = absPath(dictionary.value<std::string>(TextureInfo.identifier));
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
+3 -2
View File
@@ -202,8 +202,9 @@ RenderableTrail::Appearance::Appearance()
RenderableTrail::RenderableTrail(const ghoul::Dictionary& dictionary)
: Renderable(dictionary)
{
setRenderBin(RenderBin::Overlay);
addProperty(_opacity);
registerUpdateRenderBinFromOpacity();
_translation = Translation::createFromDictionary(
dictionary.value<ghoul::Dictionary>(KeyTranslation)
@@ -313,7 +314,7 @@ void RenderableTrail::render(const RenderData& data, RendererTasks&) {
if (usingFramebufferRenderer) {
glDepthMask(false);
//glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
}
const bool renderLines = (_appearance.renderingModes == RenderingModeLines) |
@@ -100,8 +100,8 @@ namespace {
constexpr openspace::properties::Property::PropertyInfo RenderableTypeInfo = {
"RenderableType",
"RenderableType",
"This value specifies if the plane should be rendered in the Background,"
"Opaque, Transparent, or Overlay rendering step."
"This value specifies if the orbit should be rendered in the Background,"
"Opaque, Transparent, or Overlay rendering step. Default is Transparent."
};
} // namespace
@@ -192,7 +192,7 @@ RenderableTrailOrbit::RenderableTrailOrbit(const ghoul::Dictionary& dictionary)
}
}
else {
setRenderBin(Renderable::RenderBin::Opaque);
setRenderBin(Renderable::RenderBin::Overlay);
}
}
+2 -8
View File
@@ -46,8 +46,6 @@ Fragment getFragment() {
frag.depth = vs_positionScreenSpace.w;
frag.blend = BLEND_MODE_ADDITIVE;
vec4 depthCorrection = vec4(0.0, 0.0, 100.0, 0.0);
if (renderPhase == RenderPhasePoints) {
// Use the length of the vector (dot(circCoord, circCoord)) as factor in the
// smoothstep to gradually decrease the alpha on the edges of the point
@@ -60,13 +58,9 @@ Fragment getFragment() {
}
frag.color.a = transparencyCorrection;
}
}
// G-Buffer
// JCC: The depthCorrection here is a temporary tweak
// to fix precision problems.
frag.gPosition = vs_gPosition + depthCorrection;
frag.gPosition = vs_gPosition;
// There is no normal here
frag.gNormal = vec4(0.0, 0.0, -1.0, 1.0);