mirror of
https://github.com/overte-org/overte.git
synced 2025-08-08 13:58:51 +02:00
Added shared header
This commit is contained in:
parent
9141be9124
commit
3d096d0644
7 changed files with 87 additions and 64 deletions
|
@ -30,9 +30,6 @@
|
||||||
#include "DependencyManager.h"
|
#include "DependencyManager.h"
|
||||||
#include "ViewFrustum.h"
|
#include "ViewFrustum.h"
|
||||||
|
|
||||||
// Should match value in ssao_makeOcclusion.slf
|
|
||||||
#define SSAO_USE_HORIZON_BASED 1
|
|
||||||
|
|
||||||
gpu::PipelinePointer AmbientOcclusionEffect::_occlusionPipeline;
|
gpu::PipelinePointer AmbientOcclusionEffect::_occlusionPipeline;
|
||||||
gpu::PipelinePointer AmbientOcclusionEffect::_hBlurPipeline;
|
gpu::PipelinePointer AmbientOcclusionEffect::_hBlurPipeline;
|
||||||
gpu::PipelinePointer AmbientOcclusionEffect::_vBlurPipeline;
|
gpu::PipelinePointer AmbientOcclusionEffect::_vBlurPipeline;
|
||||||
|
@ -203,13 +200,12 @@ AmbientOcclusionEffectConfig::AmbientOcclusionEffectConfig() :
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AmbientOcclusionEffect::AOParameters::AOParameters() :
|
AmbientOcclusionEffect::AOParameters::AOParameters() {
|
||||||
resolutionInfo{ -1.0f, 0.0f, 1.0f, 0.0f },
|
_resolutionInfo = { -1.0f, 0.0f, 1.0f, 0.0f };
|
||||||
radiusInfo{ 0.5f, 0.5f * 0.5f, 1.0f / (0.25f * 0.25f * 0.25f), 1.0f },
|
_radiusInfo = { 0.5f, 0.5f * 0.5f, 1.0f / (0.25f * 0.25f * 0.25f), 1.0f };
|
||||||
ditheringInfo{ 0.0f, 0.0f, 0.01f, 1.0f },
|
_ditheringInfo = { 0.0f, 0.0f, 0.01f, 1.0f };
|
||||||
sampleInfo{ 11.0f, 1.0f / 11.0f, 7.0f, 1.0f },
|
_sampleInfo = { 11.0f, 1.0f / 11.0f, 7.0f, 1.0f };
|
||||||
blurInfo{ 1.0f, 3.0f, 2.0f, 0.0f } {
|
_blurInfo = { 1.0f, 3.0f, 2.0f, 0.0f };
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AmbientOcclusionEffect::AmbientOcclusionEffect() {
|
AmbientOcclusionEffect::AmbientOcclusionEffect() {
|
||||||
|
@ -224,7 +220,7 @@ void AmbientOcclusionEffect::configure(const Config& config) {
|
||||||
const double RADIUS_POWER = 6.0;
|
const double RADIUS_POWER = 6.0;
|
||||||
const auto& radius = config.radius;
|
const auto& radius = config.radius;
|
||||||
if (radius != _aoParametersBuffer->getRadius()) {
|
if (radius != _aoParametersBuffer->getRadius()) {
|
||||||
auto& current = _aoParametersBuffer.edit().radiusInfo;
|
auto& current = _aoParametersBuffer.edit()._radiusInfo;
|
||||||
current.x = radius;
|
current.x = radius;
|
||||||
current.y = radius * radius;
|
current.y = radius * radius;
|
||||||
current.z = 10.0f;
|
current.z = 10.0f;
|
||||||
|
@ -234,40 +230,40 @@ void AmbientOcclusionEffect::configure(const Config& config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.obscuranceLevel != _aoParametersBuffer->getObscuranceLevel()) {
|
if (config.obscuranceLevel != _aoParametersBuffer->getObscuranceLevel()) {
|
||||||
auto& current = _aoParametersBuffer.edit().radiusInfo;
|
auto& current = _aoParametersBuffer.edit()._radiusInfo;
|
||||||
current.w = config.obscuranceLevel;
|
current.w = config.obscuranceLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.falloffAngle != _aoParametersBuffer->getFalloffAngle()) {
|
if (config.falloffAngle != _aoParametersBuffer->getFalloffAngle()) {
|
||||||
auto& current = _aoParametersBuffer.edit().ditheringInfo;
|
auto& current = _aoParametersBuffer.edit()._ditheringInfo;
|
||||||
current.z = config.falloffAngle;
|
current.z = config.falloffAngle;
|
||||||
current.y = 1.0f / (1.0f - config.falloffAngle);
|
current.y = 1.0f / (1.0f - config.falloffAngle);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.edgeSharpness != _aoParametersBuffer->getEdgeSharpness()) {
|
if (config.edgeSharpness != _aoParametersBuffer->getEdgeSharpness()) {
|
||||||
auto& current = _aoParametersBuffer.edit().blurInfo;
|
auto& current = _aoParametersBuffer.edit()._blurInfo;
|
||||||
current.x = config.edgeSharpness;
|
current.x = config.edgeSharpness;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.blurDeviation != _aoParametersBuffer->getBlurDeviation()) {
|
if (config.blurDeviation != _aoParametersBuffer->getBlurDeviation()) {
|
||||||
auto& current = _aoParametersBuffer.edit().blurInfo;
|
auto& current = _aoParametersBuffer.edit()._blurInfo;
|
||||||
current.z = config.blurDeviation;
|
current.z = config.blurDeviation;
|
||||||
shouldUpdateGaussian = true;
|
shouldUpdateGaussian = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.numSpiralTurns != _aoParametersBuffer->getNumSpiralTurns()) {
|
if (config.numSpiralTurns != _aoParametersBuffer->getNumSpiralTurns()) {
|
||||||
auto& current = _aoParametersBuffer.edit().sampleInfo;
|
auto& current = _aoParametersBuffer.edit()._sampleInfo;
|
||||||
current.z = config.numSpiralTurns;
|
current.z = config.numSpiralTurns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.numSamples != _aoParametersBuffer->getNumSamples()) {
|
if (config.numSamples != _aoParametersBuffer->getNumSamples()) {
|
||||||
auto& current = _aoParametersBuffer.edit().sampleInfo;
|
auto& current = _aoParametersBuffer.edit()._sampleInfo;
|
||||||
current.x = config.numSamples;
|
current.x = config.numSamples;
|
||||||
current.y = 1.0f / config.numSamples;
|
current.y = 1.0f / config.numSamples;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.fetchMipsEnabled != _aoParametersBuffer->isFetchMipsEnabled()) {
|
if (config.fetchMipsEnabled != _aoParametersBuffer->isFetchMipsEnabled()) {
|
||||||
auto& current = _aoParametersBuffer.edit().sampleInfo;
|
auto& current = _aoParametersBuffer.edit()._sampleInfo;
|
||||||
current.w = (float)config.fetchMipsEnabled;
|
current.w = (float)config.fetchMipsEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,28 +273,28 @@ void AmbientOcclusionEffect::configure(const Config& config) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.perspectiveScale != _aoParametersBuffer->getPerspectiveScale()) {
|
if (config.perspectiveScale != _aoParametersBuffer->getPerspectiveScale()) {
|
||||||
_aoParametersBuffer.edit().resolutionInfo.z = config.perspectiveScale;
|
_aoParametersBuffer.edit()._resolutionInfo.z = config.perspectiveScale;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.resolutionLevel != _aoParametersBuffer->getResolutionLevel()) {
|
if (config.resolutionLevel != _aoParametersBuffer->getResolutionLevel()) {
|
||||||
auto& current = _aoParametersBuffer.edit().resolutionInfo;
|
auto& current = _aoParametersBuffer.edit()._resolutionInfo;
|
||||||
current.x = (float) config.resolutionLevel;
|
current.x = (float) config.resolutionLevel;
|
||||||
shouldUpdateBlurs = true;
|
shouldUpdateBlurs = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.blurRadius != _aoParametersBuffer->getBlurRadius()) {
|
if (config.blurRadius != _aoParametersBuffer->getBlurRadius()) {
|
||||||
auto& current = _aoParametersBuffer.edit().blurInfo;
|
auto& current = _aoParametersBuffer.edit()._blurInfo;
|
||||||
current.y = (float)config.blurRadius;
|
current.y = (float)config.blurRadius;
|
||||||
shouldUpdateGaussian = true;
|
shouldUpdateGaussian = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.ditheringEnabled != _aoParametersBuffer->isDitheringEnabled()) {
|
if (config.ditheringEnabled != _aoParametersBuffer->isDitheringEnabled()) {
|
||||||
auto& current = _aoParametersBuffer.edit().ditheringInfo;
|
auto& current = _aoParametersBuffer.edit()._ditheringInfo;
|
||||||
current.x = (float)config.ditheringEnabled;
|
current.x = (float)config.ditheringEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (config.borderingEnabled != _aoParametersBuffer->isBorderingEnabled()) {
|
if (config.borderingEnabled != _aoParametersBuffer->isBorderingEnabled()) {
|
||||||
auto& current = _aoParametersBuffer.edit().ditheringInfo;
|
auto& current = _aoParametersBuffer.edit()._ditheringInfo;
|
||||||
current.w = (float)config.borderingEnabled;
|
current.w = (float)config.borderingEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -377,7 +373,7 @@ const gpu::PipelinePointer& AmbientOcclusionEffect::getMipCreationPipeline() {
|
||||||
|
|
||||||
void AmbientOcclusionEffect::updateGaussianDistribution() {
|
void AmbientOcclusionEffect::updateGaussianDistribution() {
|
||||||
auto coefs = _aoParametersBuffer.edit()._gaussianCoefs;
|
auto coefs = _aoParametersBuffer.edit()._gaussianCoefs;
|
||||||
GaussianDistribution::evalSampling(coefs, AOParameters::GAUSSIAN_COEFS_LENGTH, _aoParametersBuffer->getBlurRadius(), _aoParametersBuffer->getBlurDeviation());
|
GaussianDistribution::evalSampling(coefs, SSAO_BLUR_GAUSSIAN_COEFS_COUNT, _aoParametersBuffer->getBlurRadius(), _aoParametersBuffer->getBlurDeviation());
|
||||||
}
|
}
|
||||||
|
|
||||||
void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
|
void AmbientOcclusionEffect::run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs) {
|
||||||
|
|
|
@ -115,42 +115,30 @@ public:
|
||||||
|
|
||||||
void configure(const Config& config);
|
void configure(const Config& config);
|
||||||
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
|
void run(const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
|
||||||
|
|
||||||
|
#include "ssao_shared.h"
|
||||||
|
|
||||||
// Class describing the uniform buffer with all the parameters common to the AO shaders
|
// Class describing the uniform buffer with all the parameters common to the AO shaders
|
||||||
class AOParameters {
|
class AOParameters : public AmbientOcclusionParams {
|
||||||
public:
|
public:
|
||||||
// Resolution info
|
|
||||||
glm::vec4 resolutionInfo;
|
|
||||||
// radius info is { R, R^2, 1 / R^6, ObscuranceScale}
|
|
||||||
glm::vec4 radiusInfo;
|
|
||||||
// Dithering info
|
|
||||||
glm::vec4 ditheringInfo;
|
|
||||||
// Sampling info
|
|
||||||
glm::vec4 sampleInfo;
|
|
||||||
// Blurring info
|
|
||||||
glm::vec4 blurInfo;
|
|
||||||
// gaussian distribution coefficients first is the sampling radius (max is 6)
|
|
||||||
const static int GAUSSIAN_COEFS_LENGTH = 16;
|
|
||||||
float _gaussianCoefs[GAUSSIAN_COEFS_LENGTH];
|
|
||||||
|
|
||||||
AOParameters();
|
AOParameters();
|
||||||
|
|
||||||
int getResolutionLevel() const { return resolutionInfo.x; }
|
int getResolutionLevel() const { return _resolutionInfo.x; }
|
||||||
float getRadius() const { return radiusInfo.x; }
|
float getRadius() const { return _radiusInfo.x; }
|
||||||
float getPerspectiveScale() const { return resolutionInfo.z; }
|
float getPerspectiveScale() const { return _resolutionInfo.z; }
|
||||||
float getObscuranceLevel() const { return radiusInfo.w; }
|
float getObscuranceLevel() const { return _radiusInfo.w; }
|
||||||
float getFalloffAngle() const { return (float)ditheringInfo.z; }
|
float getFalloffAngle() const { return (float)_ditheringInfo.z; }
|
||||||
float getEdgeSharpness() const { return (float)blurInfo.x; }
|
float getEdgeSharpness() const { return (float)_blurInfo.x; }
|
||||||
float getBlurDeviation() const { return blurInfo.z; }
|
float getBlurDeviation() const { return _blurInfo.z; }
|
||||||
|
|
||||||
float getNumSpiralTurns() const { return sampleInfo.z; }
|
float getNumSpiralTurns() const { return _sampleInfo.z; }
|
||||||
int getNumSamples() const { return (int)sampleInfo.x; }
|
int getNumSamples() const { return (int)_sampleInfo.x; }
|
||||||
bool isFetchMipsEnabled() const { return sampleInfo.w; }
|
bool isFetchMipsEnabled() const { return _sampleInfo.w; }
|
||||||
|
|
||||||
int getBlurRadius() const { return (int)blurInfo.y; }
|
int getBlurRadius() const { return (int)_blurInfo.y; }
|
||||||
bool isDitheringEnabled() const { return ditheringInfo.x; }
|
bool isDitheringEnabled() const { return _ditheringInfo.x; }
|
||||||
bool isBorderingEnabled() const { return ditheringInfo.w; }
|
bool isBorderingEnabled() const { return _ditheringInfo.w; }
|
||||||
};
|
};
|
||||||
using AOParametersBuffer = gpu::StructBuffer<AOParameters>;
|
using AOParametersBuffer = gpu::StructBuffer<AOParameters>;
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<@def SSAO_SLH@>
|
<@def SSAO_SLH@>
|
||||||
|
|
||||||
<@include render-utils/ShaderConstants.h@>
|
<@include render-utils/ShaderConstants.h@>
|
||||||
|
<@include ssao_shared.h@>
|
||||||
|
|
||||||
<@func declarePackOcclusionDepth()@>
|
<@func declarePackOcclusionDepth()@>
|
||||||
|
|
||||||
|
@ -35,15 +36,6 @@ vec2 unpackOcclusionDepth(vec3 raw) {
|
||||||
<@include DeferredTransform.slh@>
|
<@include DeferredTransform.slh@>
|
||||||
<$declareDeferredFrameTransform()$>
|
<$declareDeferredFrameTransform()$>
|
||||||
|
|
||||||
struct AmbientOcclusionParams {
|
|
||||||
vec4 _resolutionInfo;
|
|
||||||
vec4 _radiusInfo;
|
|
||||||
vec4 _ditheringInfo;
|
|
||||||
vec4 _sampleInfo;
|
|
||||||
vec4 _blurInfo;
|
|
||||||
float _gaussianCoefs[16];
|
|
||||||
};
|
|
||||||
|
|
||||||
layout(binding=RENDER_UTILS_BUFFER_SSAO_PARAMS) uniform ambientOcclusionParamsBuffer {
|
layout(binding=RENDER_UTILS_BUFFER_SSAO_PARAMS) uniform ambientOcclusionParamsBuffer {
|
||||||
AmbientOcclusionParams params;
|
AmbientOcclusionParams params;
|
||||||
};
|
};
|
||||||
|
@ -456,4 +448,4 @@ vec3 getBlurredOcclusion(ivec2 destPixelCoord, vec2 scaledTexCoord, vec2 fullTex
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
|
|
||||||
<@include ssao.slh@>
|
<@include ssao.slh@>
|
||||||
|
|
||||||
|
// Hack comment
|
||||||
|
|
||||||
const ivec2 horizontal = ivec2(1,0);
|
const ivec2 horizontal = ivec2(1,0);
|
||||||
<$declareBlurPass(horizontal)$>
|
<$declareBlurPass(horizontal)$>
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,6 @@
|
||||||
|
|
||||||
<$declarePackOcclusionDepth()$>
|
<$declarePackOcclusionDepth()$>
|
||||||
|
|
||||||
#define SSAO_USE_HORIZON_BASED 1
|
|
||||||
#define SSAO_HBAO_MAX_RADIUS 100.0
|
#define SSAO_HBAO_MAX_RADIUS 100.0
|
||||||
|
|
||||||
layout(location=0) out vec4 outFragColor;
|
layout(location=0) out vec4 outFragColor;
|
||||||
|
|
|
@ -12,6 +12,8 @@
|
||||||
//
|
//
|
||||||
<@include ssao.slh@>
|
<@include ssao.slh@>
|
||||||
|
|
||||||
|
// Hack comment
|
||||||
|
|
||||||
const ivec2 vertical = ivec2(0,1);
|
const ivec2 vertical = ivec2(0,1);
|
||||||
<$declareBlurPass(vertical)$>
|
<$declareBlurPass(vertical)$>
|
||||||
|
|
||||||
|
|
44
libraries/render-utils/src/ssao_shared.h
Normal file
44
libraries/render-utils/src/ssao_shared.h
Normal file
|
@ -0,0 +1,44 @@
|
||||||
|
// <!
|
||||||
|
// Created by Olivier Prat on 2018/09/18
|
||||||
|
// Copyright 2013-2018 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
// !>
|
||||||
|
|
||||||
|
// <@if not RENDER_UTILS_SSAO_SHARED_H@>
|
||||||
|
// <@def RENDER_UTILS_SSAO_SHARED_H@>
|
||||||
|
|
||||||
|
// Hack comment to absorb the extra '//' scribe prepends
|
||||||
|
|
||||||
|
#ifndef RENDER_UTILS_SSAO_SHARED_H
|
||||||
|
#define RENDER_UTILS_SSAO_SHARED_H
|
||||||
|
|
||||||
|
#define SSAO_USE_HORIZON_BASED 1
|
||||||
|
#define SSAO_BLUR_GAUSSIAN_COEFS_COUNT 16
|
||||||
|
|
||||||
|
// glsl / C++ compatible source as interface for Shadows
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# define SSAO_VEC4 glm::vec4
|
||||||
|
#else
|
||||||
|
# define SSAO_VEC4 vec4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
struct AmbientOcclusionParams {
|
||||||
|
SSAO_VEC4 _resolutionInfo;
|
||||||
|
SSAO_VEC4 _radiusInfo;
|
||||||
|
SSAO_VEC4 _ditheringInfo;
|
||||||
|
SSAO_VEC4 _sampleInfo;
|
||||||
|
SSAO_VEC4 _blurInfo;
|
||||||
|
float _gaussianCoefs[SSAO_BLUR_GAUSSIAN_COEFS_COUNT];
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // RENDER_UTILS_SHADER_CONSTANTS_H
|
||||||
|
|
||||||
|
// <@if 1@>
|
||||||
|
// Trigger Scribe include
|
||||||
|
// <@endif@> <!def that !>
|
||||||
|
|
||||||
|
// <@endif@>
|
||||||
|
|
||||||
|
// Hack Comment
|
Loading…
Reference in a new issue