mirror of
https://github.com/overte-org/overte.git
synced 2025-08-11 01:23:17 +02:00
Fixing haze bug on Mac, and potentially AMD
This commit is contained in:
parent
58f004352a
commit
4a25090a23
7 changed files with 27 additions and 33 deletions
|
@ -235,15 +235,14 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
|
|
||||||
// Haze
|
// Haze
|
||||||
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
||||||
vec4 colorV4 = computeHazeColor(
|
vec4 hazeColor = computeHazeColor(
|
||||||
vec4(color, 1.0), // fragment original color
|
|
||||||
positionES, // fragment position in eye coordinates
|
positionES, // fragment position in eye coordinates
|
||||||
fragPositionWS, // fragment position in world coordinates
|
fragPositionWS, // fragment position in world coordinates
|
||||||
invViewMat[3].xyz, // eye position in world coordinates
|
invViewMat[3].xyz, // eye position in world coordinates
|
||||||
lightDirection // keylight direction vector in world coordinates
|
lightDirection // keylight direction vector in world coordinates
|
||||||
);
|
);
|
||||||
|
|
||||||
color = colorV4.rgb;
|
color = mix(color.rgb, hazeColor.rgb, hazeColor.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
@ -273,15 +272,14 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
|
|
||||||
// Haze
|
// Haze
|
||||||
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
if ((isHazeEnabled() > 0.0) && (hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
||||||
vec4 colorV4 = computeHazeColor(
|
vec4 hazeColor = computeHazeColor(
|
||||||
vec4(color, 1.0), // fragment original color
|
|
||||||
positionES, // fragment position in eye coordinates
|
positionES, // fragment position in eye coordinates
|
||||||
positionWS, // fragment position in world coordinates
|
positionWS, // fragment position in world coordinates
|
||||||
invViewMat[3].xyz, // eye position in world coordinates
|
invViewMat[3].xyz, // eye position in world coordinates
|
||||||
lightDirection // keylight direction vector
|
lightDirection // keylight direction vector
|
||||||
);
|
);
|
||||||
|
|
||||||
color = colorV4.rgb;
|
color = mix(color.rgb, hazeColor.rgb, hazeColor.a);
|
||||||
}
|
}
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
|
|
@ -109,7 +109,6 @@ void MakeHaze::run(const render::RenderContextPointer& renderContext, graphics::
|
||||||
|
|
||||||
const int HazeEffect_ParamsSlot = 0;
|
const int HazeEffect_ParamsSlot = 0;
|
||||||
const int HazeEffect_TransformBufferSlot = 1;
|
const int HazeEffect_TransformBufferSlot = 1;
|
||||||
const int HazeEffect_ColorMapSlot = 2;
|
|
||||||
const int HazeEffect_LinearDepthMapSlot = 3;
|
const int HazeEffect_LinearDepthMapSlot = 3;
|
||||||
const int HazeEffect_LightingMapSlot = 4;
|
const int HazeEffect_LightingMapSlot = 4;
|
||||||
|
|
||||||
|
@ -122,12 +121,10 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto inputBuffer = inputs.get1()->getRenderBuffer(0);
|
const auto outputBuffer = inputs.get1();
|
||||||
const auto framebuffer = inputs.get2();
|
const auto framebuffer = inputs.get2();
|
||||||
const auto transformBuffer = inputs.get3();
|
const auto transformBuffer = inputs.get3();
|
||||||
|
|
||||||
auto outputBuffer = inputs.get4();
|
|
||||||
|
|
||||||
auto depthBuffer = framebuffer->getLinearDepthTexture();
|
auto depthBuffer = framebuffer->getLinearDepthTexture();
|
||||||
|
|
||||||
RenderArgs* args = renderContext->args;
|
RenderArgs* args = renderContext->args;
|
||||||
|
@ -139,6 +136,10 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
gpu::ShaderPointer program = gpu::Shader::createProgram(vs, ps);
|
||||||
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
|
||||||
|
|
||||||
|
state->setBlendFunction(true,
|
||||||
|
gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA,
|
||||||
|
gpu::State::FACTOR_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::ONE);
|
||||||
|
|
||||||
// Mask out haze on the tablet
|
// Mask out haze on the tablet
|
||||||
PrepareStencil::testMask(*state);
|
PrepareStencil::testMask(*state);
|
||||||
|
|
||||||
|
@ -148,7 +149,6 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
gpu::Shader::BindingSet slotBindings;
|
gpu::Shader::BindingSet slotBindings;
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("hazeBuffer"), HazeEffect_ParamsSlot));
|
slotBindings.insert(gpu::Shader::Binding(std::string("hazeBuffer"), HazeEffect_ParamsSlot));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), HazeEffect_TransformBufferSlot));
|
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), HazeEffect_TransformBufferSlot));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("colorMap"), HazeEffect_ColorMapSlot));
|
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("linearDepthMap"), HazeEffect_LinearDepthMapSlot));
|
slotBindings.insert(gpu::Shader::Binding(std::string("linearDepthMap"), HazeEffect_LinearDepthMapSlot));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), HazeEffect_LightingMapSlot));
|
slotBindings.insert(gpu::Shader::Binding(std::string("keyLightBuffer"), HazeEffect_LightingMapSlot));
|
||||||
gpu::Shader::makeProgram(*program, slotBindings);
|
gpu::Shader::makeProgram(*program, slotBindings);
|
||||||
|
@ -156,7 +156,7 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
auto sourceFramebufferSize = glm::ivec2(inputBuffer->getDimensions());
|
auto outputFramebufferSize = glm::ivec2(outputBuffer->getSize());
|
||||||
|
|
||||||
gpu::doInBatch("DrawHaze::run", args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch("DrawHaze::run", args->_context, [&](gpu::Batch& batch) {
|
||||||
batch.enableStereo(false);
|
batch.enableStereo(false);
|
||||||
|
@ -165,7 +165,7 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
batch.setViewportTransform(args->_viewport);
|
batch.setViewportTransform(args->_viewport);
|
||||||
batch.setProjectionTransform(glm::mat4());
|
batch.setProjectionTransform(glm::mat4());
|
||||||
batch.resetViewTransform();
|
batch.resetViewTransform();
|
||||||
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(sourceFramebufferSize, args->_viewport));
|
batch.setModelTransform(gpu::Framebuffer::evalSubregionTexcoordTransform(outputFramebufferSize, args->_viewport));
|
||||||
|
|
||||||
batch.setPipeline(_hazePipeline);
|
batch.setPipeline(_hazePipeline);
|
||||||
|
|
||||||
|
@ -191,7 +191,6 @@ void DrawHaze::run(const render::RenderContextPointer& renderContext, const Inpu
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
batch.setResourceTexture(HazeEffect_ColorMapSlot, inputBuffer);
|
|
||||||
batch.setResourceTexture(HazeEffect_LinearDepthMapSlot, depthBuffer);
|
batch.setResourceTexture(HazeEffect_LinearDepthMapSlot, depthBuffer);
|
||||||
|
|
||||||
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
batch.draw(gpu::TRIANGLE_STRIP, 4);
|
||||||
|
|
|
@ -159,7 +159,7 @@ public:
|
||||||
|
|
||||||
class DrawHaze {
|
class DrawHaze {
|
||||||
public:
|
public:
|
||||||
using Inputs = render::VaryingSet5<graphics::HazePointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, DeferredFrameTransformPointer, gpu::FramebufferPointer>;
|
using Inputs = render::VaryingSet4<graphics::HazePointer, gpu::FramebufferPointer, LinearDepthFramebufferPointer, DeferredFrameTransformPointer>;
|
||||||
using Config = HazeConfig;
|
using Config = HazeConfig;
|
||||||
using JobModel = render::Job::ModelI<DrawHaze, Inputs, Config>;
|
using JobModel = render::Job::ModelI<DrawHaze, Inputs, Config>;
|
||||||
|
|
||||||
|
|
|
@ -228,15 +228,14 @@ vec3 evalGlobalLightingAlphaBlendedWithHaze(
|
||||||
// Haze
|
// Haze
|
||||||
// FIXME - temporarily removed until we support it for forward...
|
// FIXME - temporarily removed until we support it for forward...
|
||||||
/* if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
/* if ((hazeParams.hazeMode & HAZE_MODE_IS_ACTIVE) == HAZE_MODE_IS_ACTIVE) {
|
||||||
vec4 colorV4 = computeHazeColor(
|
vec4 hazeColor = computeHazeColor(
|
||||||
vec4(color, 1.0), // fragment original color
|
|
||||||
positionES, // fragment position in eye coordinates
|
positionES, // fragment position in eye coordinates
|
||||||
fragPositionWS, // fragment position in world coordinates
|
fragPositionWS, // fragment position in world coordinates
|
||||||
invViewMat[3].xyz, // eye position in world coordinates
|
invViewMat[3].xyz, // eye position in world coordinates
|
||||||
lightDirection // keylight direction vector
|
lightDirection // keylight direction vector
|
||||||
);
|
);
|
||||||
|
|
||||||
color = colorV4.rgb;
|
color = mix(color.rgb, hazeColor.rgb, hazeColor.a);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
return color;
|
return color;
|
||||||
|
|
|
@ -22,7 +22,6 @@
|
||||||
|
|
||||||
<@include Haze.slh@>
|
<@include Haze.slh@>
|
||||||
|
|
||||||
uniform sampler2D colorMap;
|
|
||||||
uniform sampler2D linearDepthMap;
|
uniform sampler2D linearDepthMap;
|
||||||
|
|
||||||
vec4 unpackPositionFromZeye(vec2 texcoord) {
|
vec4 unpackPositionFromZeye(vec2 texcoord) {
|
||||||
|
@ -46,7 +45,6 @@ void main(void) {
|
||||||
discard;
|
discard;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec4 fragColor = texture(colorMap, varTexCoord0);
|
|
||||||
vec4 fragPositionES = unpackPositionFromZeye(varTexCoord0);
|
vec4 fragPositionES = unpackPositionFromZeye(varTexCoord0);
|
||||||
|
|
||||||
mat4 viewInverse = getViewInverse();
|
mat4 viewInverse = getViewInverse();
|
||||||
|
@ -56,5 +54,8 @@ void main(void) {
|
||||||
Light light = getKeyLight();
|
Light light = getKeyLight();
|
||||||
vec3 lightDirectionWS = getLightDirection(light);
|
vec3 lightDirectionWS = getLightDirection(light);
|
||||||
|
|
||||||
outFragColor = computeHazeColor(fragColor, fragPositionES.xyz, fragPositionWS.xyz, eyePositionWS.xyz, lightDirectionWS);
|
outFragColor = computeHazeColor(fragPositionES.xyz, fragPositionWS.xyz, eyePositionWS.xyz, lightDirectionWS);
|
||||||
|
if (outFragColor.a < 1e-4) {
|
||||||
|
discard;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -92,22 +92,21 @@ vec3 computeHazeColorKeyLightAttenuation(vec3 color, vec3 lightDirectionWS, vec3
|
||||||
}
|
}
|
||||||
|
|
||||||
// Input:
|
// Input:
|
||||||
// fragColor - fragment original color
|
|
||||||
// fragPositionES - fragment position in eye coordinates
|
// fragPositionES - fragment position in eye coordinates
|
||||||
// fragPositionWS - fragment position in world coordinates
|
// fragPositionWS - fragment position in world coordinates
|
||||||
// eyePositionWS - eye position in world coordinates
|
// eyePositionWS - eye position in world coordinates
|
||||||
// Output:
|
// Output:
|
||||||
// fragment colour after haze effect
|
// haze colour and alpha contains haze blend factor
|
||||||
//
|
//
|
||||||
// General algorithm taken from http://www.iquilezles.org/www/articles/fog/fog.htm, with permission
|
// General algorithm taken from http://www.iquilezles.org/www/articles/fog/fog.htm, with permission
|
||||||
//
|
//
|
||||||
vec4 computeHazeColor(vec4 fragColor, vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePositionWS, vec3 lightDirectionWS) {
|
vec4 computeHazeColor(vec3 fragPositionES, vec3 fragPositionWS, vec3 eyePositionWS, vec3 lightDirectionWS) {
|
||||||
// Distance to fragment
|
// Distance to fragment
|
||||||
float distance = length(fragPositionES);
|
float distance = length(fragPositionES);
|
||||||
float eyeWorldHeight = eyePositionWS.y;
|
float eyeWorldHeight = eyePositionWS.y;
|
||||||
|
|
||||||
// Convert haze colour from uniform into a vec4
|
// Convert haze colour from uniform into a vec4
|
||||||
vec4 hazeColor = vec4(hazeParams.hazeColor, 1.0);
|
vec4 hazeColor = vec4(hazeParams.hazeColor, 1.0);
|
||||||
|
|
||||||
// Use the haze colour for the glare colour, if blend is not enabled
|
// Use the haze colour for the glare colour, if blend is not enabled
|
||||||
vec4 blendedHazeColor;
|
vec4 blendedHazeColor;
|
||||||
|
@ -149,13 +148,13 @@ vec4 computeHazeColor(vec4 fragColor, vec3 fragPositionES, vec3 fragPositionWS,
|
||||||
vec3 hazeAmount = 1.0 - exp(-hazeIntegral);
|
vec3 hazeAmount = 1.0 - exp(-hazeIntegral);
|
||||||
|
|
||||||
// Compute color after haze effect
|
// Compute color after haze effect
|
||||||
potentialFragColor = mix(fragColor, vec4(1.0, 1.0, 1.0, 1.0), vec4(hazeAmount, 1.0));
|
potentialFragColor = vec4(1.0, 1.0, 1.0, hazeAmount);
|
||||||
} else if ((hazeParams.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) {
|
} else if ((hazeParams.hazeMode & HAZE_MODE_IS_ALTITUDE_BASED) != HAZE_MODE_IS_ALTITUDE_BASED) {
|
||||||
// Haze is based only on range
|
// Haze is based only on range
|
||||||
float hazeAmount = 1.0 - exp(-distance * hazeParams.hazeRangeFactor);
|
float hazeAmount = 1.0 - exp(-distance * hazeParams.hazeRangeFactor);
|
||||||
|
|
||||||
// Compute color after haze effect
|
// Compute color after haze effect
|
||||||
potentialFragColor = mix(fragColor, blendedHazeColor, hazeAmount);
|
potentialFragColor = vec4(blendedHazeColor.rgb, hazeAmount);
|
||||||
} else {
|
} else {
|
||||||
// Haze is based on both range and altitude
|
// Haze is based on both range and altitude
|
||||||
// Taken from www.crytek.com/download/GDC2007_RealtimeAtmoFxInGamesRev.ppt
|
// Taken from www.crytek.com/download/GDC2007_RealtimeAtmoFxInGamesRev.ppt
|
||||||
|
@ -181,16 +180,14 @@ vec4 computeHazeColor(vec4 fragColor, vec3 fragPositionES, vec3 fragPositionWS,
|
||||||
float hazeAmount = 1.0 - exp(-hazeIntegral);
|
float hazeAmount = 1.0 - exp(-hazeIntegral);
|
||||||
|
|
||||||
// Compute color after haze effect
|
// Compute color after haze effect
|
||||||
potentialFragColor = mix(fragColor, blendedHazeColor, hazeAmount);
|
potentialFragColor = vec4(blendedHazeColor.rgb, hazeAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mix with background at far range
|
// Mix with background at far range
|
||||||
const float BLEND_DISTANCE = 27000.0f;
|
const float BLEND_DISTANCE = 27000.0f;
|
||||||
vec4 outFragColor;
|
vec4 outFragColor = potentialFragColor;
|
||||||
if (distance > BLEND_DISTANCE) {
|
if (distance > BLEND_DISTANCE) {
|
||||||
outFragColor = mix(potentialFragColor, fragColor, hazeParams.backgroundBlend);
|
outFragColor.a = 1.0 - hazeParams.backgroundBlend;
|
||||||
} else {
|
|
||||||
outFragColor = potentialFragColor;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return outFragColor;
|
return outFragColor;
|
||||||
|
|
|
@ -174,7 +174,7 @@ void RenderDeferredTask::build(JobModel& task, const render::Varying& input, ren
|
||||||
// Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job
|
// Similar to light stage, background stage has been filled by several potential render items and resolved for the frame in this job
|
||||||
task.addJob<DrawBackgroundStage>("DrawBackgroundDeferred", lightingModel);
|
task.addJob<DrawBackgroundStage>("DrawBackgroundDeferred", lightingModel);
|
||||||
|
|
||||||
const auto drawHazeInputs = render::Varying(DrawHaze::Inputs(hazeModel, lightingFramebuffer, linearDepthTarget, deferredFrameTransform, lightingFramebuffer));
|
const auto drawHazeInputs = render::Varying(DrawHaze::Inputs(hazeModel, lightingFramebuffer, linearDepthTarget, deferredFrameTransform));
|
||||||
task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs);
|
task.addJob<DrawHaze>("DrawHazeDeferred", drawHazeInputs);
|
||||||
|
|
||||||
// Render transparent objects forward in LightingBuffer
|
// Render transparent objects forward in LightingBuffer
|
||||||
|
|
Loading…
Reference in a new issue