mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-06 12:23:09 +02:00
Curvature is looking correct now without artefact, moving on to the lighting
This commit is contained in:
parent
3ec14fd746
commit
884b9211c6
16 changed files with 224 additions and 81 deletions
|
@ -157,6 +157,7 @@ vec3 evalLightmappedColor(mat4 invViewMat, float shadowAttenuation, float obscur
|
||||||
<$declareDeferredCurvature()$>
|
<$declareDeferredCurvature()$>
|
||||||
<@include SubsurfaceScattering.slh@>
|
<@include SubsurfaceScattering.slh@>
|
||||||
<$declareSubsurfaceScatteringResource()$>
|
<$declareSubsurfaceScatteringResource()$>
|
||||||
|
<!<$declareEvalGlobalSpecularIrradiance(0, 1, 0)$>!>
|
||||||
|
|
||||||
vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec4 blurredCurvature, vec4 diffusedCurvature, float roughness) {
|
vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, float obscurance, vec3 position, vec3 normal, vec3 albedo, vec4 blurredCurvature, vec4 diffusedCurvature, float roughness) {
|
||||||
// prepareGlobalLight
|
// prepareGlobalLight
|
||||||
|
@ -169,7 +170,7 @@ vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, f
|
||||||
// Get light
|
// Get light
|
||||||
Light light = getLight();
|
Light light = getLight();
|
||||||
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
|
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
|
||||||
float metallic = 1.0;
|
float metallic = 0.0;
|
||||||
|
|
||||||
vec3 fragLightDir = -normalize(getLightDirection(light));
|
vec3 fragLightDir = -normalize(getLightDirection(light));
|
||||||
|
|
||||||
|
@ -184,14 +185,52 @@ vec3 evalSkyboxGlobalColorScattering(mat4 invViewMat, float shadowAttenuation, f
|
||||||
vec3 rN = normalize(mix(normal, bentNormalLow, bendFactorSpectrum.x));
|
vec3 rN = normalize(mix(normal, bentNormalLow, bendFactorSpectrum.x));
|
||||||
vec3 gN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.y));
|
vec3 gN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.y));
|
||||||
vec3 bN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.z));
|
vec3 bN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.z));
|
||||||
|
|
||||||
|
|
||||||
|
/* vec3 rN = normalize(mix(normal, bentNormalHigh, bendFactorSpectrum.x));
|
||||||
|
vec3 gN = normalize(mix(normal, bentNormalHigh, bendFactorSpectrum.y));
|
||||||
|
vec3 bN = normalize(mix(normal, bentNormalHigh, bendFactorSpectrum.z));
|
||||||
|
*/
|
||||||
vec3 NdotLSpectrum = vec3(dot(rN, fragLightDir), dot(gN, fragLightDir), dot(bN, fragLightDir));
|
vec3 NdotLSpectrum = vec3(dot(rN, fragLightDir), dot(gN, fragLightDir), dot(bN, fragLightDir));
|
||||||
|
|
||||||
// --> Look up the pre-integrated curvature-dependent BDRF textures
|
// --> Look up the pre-integrated curvature-dependent BDRF textures
|
||||||
vec3 bdrf = fetchBRDFSpectrum(NdotLSpectrum, curvature);
|
vec3 brdf = fetchBRDFSpectrum(NdotLSpectrum, curvature);
|
||||||
|
|
||||||
|
// The position of the pixel fragment in Eye space then in world space
|
||||||
|
|
||||||
|
float scatteringLevel = getScatteringLevel();
|
||||||
|
|
||||||
|
vec4 shading;
|
||||||
|
float standardDiffuse = clamp(dot(normal, fragLightDir), 0.0, 1.0);
|
||||||
|
{ // Key Sun Lighting
|
||||||
|
// Diffuse Lighting
|
||||||
|
//float diffuse = clamp(dot(normal, fragLightDir), 0.0, 1.0);
|
||||||
|
|
||||||
|
// Specular Lighting
|
||||||
|
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
|
||||||
|
vec3 fresnelColor = fresnelSchlick(fresnel, fragLightDir,halfDir);
|
||||||
|
float power = specularDistribution(roughness, fragNormal, halfDir);
|
||||||
|
vec3 specular = power * fresnelColor * standardDiffuse;
|
||||||
|
|
||||||
|
shading = vec4(specular, (1 - fresnelColor.x));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (scatteringLevel < 0.1) {
|
||||||
|
brdf = vec3(standardDiffuse);
|
||||||
|
}
|
||||||
|
vec3 color = vec3(albedo * vec3(brdf.xyz) * shading.w + shading.rgb) * getLightColor(light) * getLightIntensity(light);
|
||||||
|
|
||||||
|
|
||||||
return vec3(bdrf);
|
// Diffuse from ambient
|
||||||
|
// color += albedo * evalSphericalLight(getLightAmbientSphere(light), bentNormalHigh).xyz *getLightAmbientIntensity(light);
|
||||||
|
|
||||||
|
// Specular highlight from ambient
|
||||||
|
vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, roughness, fresnel, 1.0);
|
||||||
|
// color += specularLighting;
|
||||||
|
|
||||||
|
if ( showBRDF())
|
||||||
|
return brdf;
|
||||||
|
return vec3(color);
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
|
@ -350,7 +350,10 @@ void PrepareDeferred::run(const SceneContextPointer& sceneContext, const RenderC
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) {
|
void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext,
|
||||||
|
const DeferredFrameTransformPointer& frameTransform,
|
||||||
|
const gpu::TexturePointer& diffusedCurvature2,
|
||||||
|
const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource) {
|
||||||
|
|
||||||
auto args = renderContext->args;
|
auto args = renderContext->args;
|
||||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
|
@ -390,7 +393,7 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c
|
||||||
|
|
||||||
// Subsurface scattering specific
|
// Subsurface scattering specific
|
||||||
batch.setResourceTexture(DEFERRED_BUFFER_CURVATURE_UNIT, framebufferCache->getCurvatureTexture());
|
batch.setResourceTexture(DEFERRED_BUFFER_CURVATURE_UNIT, framebufferCache->getCurvatureTexture());
|
||||||
batch.setResourceTexture(DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT, framebufferCache->getCurvatureTexture());
|
batch.setResourceTexture(DEFERRED_BUFFER_DIFFUSED_CURVATURE_UNIT, diffusedCurvature2);
|
||||||
|
|
||||||
batch.setUniformBuffer(SCATTERING_PARAMETERS_BUFFER_SLOT, subsurfaceScatteringResource->getParametersBuffer());
|
batch.setUniformBuffer(SCATTERING_PARAMETERS_BUFFER_SLOT, subsurfaceScatteringResource->getParametersBuffer());
|
||||||
|
|
||||||
|
@ -621,17 +624,21 @@ void RenderDeferred::configure(const Config& config) {
|
||||||
glm::vec2 curvatureInfo(config.curvatureOffset, config.curvatureScale);
|
glm::vec2 curvatureInfo(config.curvatureOffset, config.curvatureScale);
|
||||||
_subsurfaceScatteringResource->setCurvatureFactors(curvatureInfo);
|
_subsurfaceScatteringResource->setCurvatureFactors(curvatureInfo);
|
||||||
|
|
||||||
|
_subsurfaceScatteringResource->setLevel((float)config.enableScattering);
|
||||||
|
_subsurfaceScatteringResource->setShowBRDF(config.showScatteringBRDF);
|
||||||
|
|
||||||
_enablePointLights = config.enablePointLights;
|
_enablePointLights = config.enablePointLights;
|
||||||
_enableSpotLights = config.enableSpotLights;
|
_enableSpotLights = config.enableSpotLights;
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const DeferredFrameTransformPointer& deferredTransform) {
|
void RenderDeferred::run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext, const Inputs& inputs) {
|
||||||
if (!_subsurfaceScatteringResource->getScatteringTable()) {
|
if (!_subsurfaceScatteringResource->getScatteringTable()) {
|
||||||
_subsurfaceScatteringResource->generateScatteringTable(renderContext->args);
|
_subsurfaceScatteringResource->generateScatteringTable(renderContext->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupJob.run(sceneContext, renderContext, deferredTransform, _subsurfaceScatteringResource);
|
auto& deferredTransform = inputs.get0();
|
||||||
|
auto& diffusedCurvature2 = inputs.get2()->getRenderBuffer(0);
|
||||||
|
setupJob.run(sceneContext, renderContext, deferredTransform, diffusedCurvature2, _subsurfaceScatteringResource);
|
||||||
|
|
||||||
lightsJob.run(sceneContext, renderContext, deferredTransform, _enablePointLights, _enableSpotLights);
|
lightsJob.run(sceneContext, renderContext, deferredTransform, _enablePointLights, _enableSpotLights);
|
||||||
|
|
||||||
|
|
|
@ -115,7 +115,9 @@ class RenderDeferredSetup {
|
||||||
public:
|
public:
|
||||||
// using JobModel = render::Job::ModelI<RenderDeferredSetup, DeferredFrameTransformPointer>;
|
// using JobModel = render::Job::ModelI<RenderDeferredSetup, DeferredFrameTransformPointer>;
|
||||||
|
|
||||||
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource);
|
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform,
|
||||||
|
const gpu::TexturePointer& diffusedCurvature2,
|
||||||
|
const SubsurfaceScatteringResourcePointer& subsurfaceScatteringResource);
|
||||||
};
|
};
|
||||||
|
|
||||||
class RenderDeferredLocals {
|
class RenderDeferredLocals {
|
||||||
|
@ -144,9 +146,13 @@ class RenderDeferredConfig : public render::Job::Config {
|
||||||
Q_PROPERTY(float curvatureOffset MEMBER curvatureOffset NOTIFY dirty)
|
Q_PROPERTY(float curvatureOffset MEMBER curvatureOffset NOTIFY dirty)
|
||||||
Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty)
|
Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty)
|
||||||
|
|
||||||
|
Q_PROPERTY(bool enableScattering MEMBER enableScattering NOTIFY dirty)
|
||||||
|
Q_PROPERTY(bool showScatteringBRDF MEMBER showScatteringBRDF NOTIFY dirty)
|
||||||
|
|
||||||
Q_PROPERTY(bool enablePointLights MEMBER enablePointLights NOTIFY dirty)
|
Q_PROPERTY(bool enablePointLights MEMBER enablePointLights NOTIFY dirty)
|
||||||
Q_PROPERTY(bool enableSpotLights MEMBER enableSpotLights NOTIFY dirty)
|
Q_PROPERTY(bool enableSpotLights MEMBER enableSpotLights NOTIFY dirty)
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
RenderDeferredConfig() : render::Job::Config(true) {}
|
RenderDeferredConfig() : render::Job::Config(true) {}
|
||||||
|
|
||||||
|
@ -158,6 +164,9 @@ public:
|
||||||
float curvatureOffset{ 0.08f };
|
float curvatureOffset{ 0.08f };
|
||||||
float curvatureScale{ 0.8f };
|
float curvatureScale{ 0.8f };
|
||||||
|
|
||||||
|
bool enableScattering{ true };
|
||||||
|
bool showScatteringBRDF{ false };
|
||||||
|
|
||||||
bool enablePointLights{ true };
|
bool enablePointLights{ true };
|
||||||
bool enableSpotLights{ true };
|
bool enableSpotLights{ true };
|
||||||
|
|
||||||
|
@ -168,14 +177,15 @@ signals:
|
||||||
|
|
||||||
class RenderDeferred {
|
class RenderDeferred {
|
||||||
public:
|
public:
|
||||||
|
using Inputs = render::VaryingSet3 < DeferredFrameTransformPointer, gpu::FramebufferPointer, gpu::FramebufferPointer >;
|
||||||
using Config = RenderDeferredConfig;
|
using Config = RenderDeferredConfig;
|
||||||
using JobModel = render::Job::ModelI<RenderDeferred, DeferredFrameTransformPointer, Config>;
|
using JobModel = render::Job::ModelI<RenderDeferred, Inputs, Config>;
|
||||||
|
|
||||||
RenderDeferred();
|
RenderDeferred();
|
||||||
|
|
||||||
void configure(const Config& config);
|
void configure(const Config& config);
|
||||||
|
|
||||||
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform);
|
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs);
|
||||||
|
|
||||||
RenderDeferredSetup setupJob;
|
RenderDeferredSetup setupJob;
|
||||||
RenderDeferredLocals lightsJob;
|
RenderDeferredLocals lightsJob;
|
||||||
|
|
|
@ -107,7 +107,7 @@ void FramebufferCache::createPrimaryFramebuffer() {
|
||||||
|
|
||||||
// For AO:
|
// For AO:
|
||||||
auto pointMipSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_POINT);
|
auto pointMipSampler = gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_POINT);
|
||||||
_depthPyramidTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::RGB), width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_MIP_LINEAR)));
|
_depthPyramidTexture = gpu::TexturePointer(gpu::Texture::create2D(gpu::Element(gpu::SCALAR, gpu::FLOAT, gpu::RGB), width, height, gpu::Sampler(gpu::Sampler::FILTER_MIN_MAG_LINEAR_MIP_POINT)));
|
||||||
_depthPyramidFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
|
_depthPyramidFramebuffer = gpu::FramebufferPointer(gpu::Framebuffer::create());
|
||||||
_depthPyramidFramebuffer->setRenderBuffer(0, _depthPyramidTexture);
|
_depthPyramidFramebuffer->setRenderBuffer(0, _depthPyramidTexture);
|
||||||
_depthPyramidFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
|
_depthPyramidFramebuffer->setDepthStencilBuffer(_primaryDepthTexture, depthFormat);
|
||||||
|
|
|
@ -123,11 +123,11 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
|
||||||
// Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now.
|
// Draw Lights just add the lights to the current list of lights to deal with. NOt really gpu job for now.
|
||||||
addJob<DrawLight>("DrawLight", lights);
|
addJob<DrawLight>("DrawLight", lights);
|
||||||
|
|
||||||
// const auto scatteringInputs = render::Varying(SubsurfaceScattering::Inputs(deferredFrameTransform, curvatureFramebuffer, diffusedCurvatureFramebuffer));
|
const auto deferredLightingInputs = render::Varying(RenderDeferred::Inputs(deferredFrameTransform, curvatureFramebuffer, diffusedCurvatureFramebuffer));
|
||||||
// const auto scatteringFramebuffer = addJob<SubsurfaceScattering>("Scattering", scatteringInputs);
|
// const auto scatteringFramebuffer = addJob<SubsurfaceScattering>("Scattering", scatteringInputs);
|
||||||
|
|
||||||
// DeferredBuffer is complete, now let's shade it into the LightingBuffer
|
// DeferredBuffer is complete, now let's shade it into the LightingBuffer
|
||||||
addJob<RenderDeferred>("RenderDeferred", deferredFrameTransform);
|
addJob<RenderDeferred>("RenderDeferred", deferredLightingInputs);
|
||||||
|
|
||||||
|
|
||||||
// AA job to be revisited
|
// AA job to be revisited
|
||||||
|
|
|
@ -64,6 +64,26 @@ glm::vec2 SubsurfaceScatteringResource::getCurvatureFactors() const {
|
||||||
return _parametersBuffer.get<Parameters>().curvatureInfo;
|
return _parametersBuffer.get<Parameters>().curvatureInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void SubsurfaceScatteringResource::setLevel(float level) {
|
||||||
|
if (level != getLevel()) {
|
||||||
|
_parametersBuffer.edit<Parameters>().level = level;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
float SubsurfaceScatteringResource::getLevel() const {
|
||||||
|
return _parametersBuffer.get<Parameters>().level;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SubsurfaceScatteringResource::setShowBRDF(bool show) {
|
||||||
|
if (show != isShowBRDF()) {
|
||||||
|
_parametersBuffer.edit<Parameters>().showBRDF = show;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
bool SubsurfaceScatteringResource::isShowBRDF() const {
|
||||||
|
return (bool)_parametersBuffer.get<Parameters>().showBRDF;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void SubsurfaceScatteringResource::generateScatteringTable(RenderArgs* args) {
|
void SubsurfaceScatteringResource::generateScatteringTable(RenderArgs* args) {
|
||||||
if (!_scatteringTable) {
|
if (!_scatteringTable) {
|
||||||
_scatteringTable = generatePreIntegratedScattering(args);
|
_scatteringTable = generatePreIntegratedScattering(args);
|
||||||
|
|
|
@ -29,6 +29,14 @@ public:
|
||||||
void setCurvatureFactors(const glm::vec2& sbCurvatureFactors);
|
void setCurvatureFactors(const glm::vec2& sbCurvatureFactors);
|
||||||
glm::vec2 getCurvatureFactors() const;
|
glm::vec2 getCurvatureFactors() const;
|
||||||
|
|
||||||
|
void setLevel(float level);
|
||||||
|
float getLevel() const;
|
||||||
|
|
||||||
|
|
||||||
|
void setShowBRDF(bool show);
|
||||||
|
bool isShowBRDF() const;
|
||||||
|
|
||||||
|
|
||||||
UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
|
UniformBufferView getParametersBuffer() const { return _parametersBuffer; }
|
||||||
|
|
||||||
gpu::TexturePointer getScatteringTable() const { return _scatteringTable; }
|
gpu::TexturePointer getScatteringTable() const { return _scatteringTable; }
|
||||||
|
@ -45,7 +53,8 @@ protected:
|
||||||
public:
|
public:
|
||||||
glm::vec4 normalBentInfo{ 1.5f, 0.8f, 0.3f, 1.5f };
|
glm::vec4 normalBentInfo{ 1.5f, 0.8f, 0.3f, 1.5f };
|
||||||
glm::vec2 curvatureInfo{ 0.08f, 0.8f };
|
glm::vec2 curvatureInfo{ 0.08f, 0.8f };
|
||||||
glm::vec2 spare{ 0.0f };
|
float level{ 1.0f };
|
||||||
|
float showBRDF{ 0.0f };
|
||||||
|
|
||||||
Parameters() {}
|
Parameters() {}
|
||||||
};
|
};
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
uniform sampler2D scatteringLUT;
|
uniform sampler2D scatteringLUT;
|
||||||
|
|
||||||
vec3 fetchBRDF(float LdotN, float curvature) {
|
vec3 fetchBRDF(float LdotN, float curvature) {
|
||||||
return texture(scatteringLUT, vec2( LdotN * 0.5 + 0.5, curvature)).xyz;
|
return texture(scatteringLUT, vec2( clamp(LdotN * 0.5 + 0.5, 0.0, 1.0), curvature)).xyz;
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) {
|
vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) {
|
||||||
|
@ -27,7 +27,7 @@ vec3 fetchBRDFSpectrum(vec3 LdotNSpectrum, float curvature) {
|
||||||
// Subsurface Scattering parameters
|
// Subsurface Scattering parameters
|
||||||
struct ScatteringParameters {
|
struct ScatteringParameters {
|
||||||
vec4 normalBendInfo; // R, G, B, factor
|
vec4 normalBendInfo; // R, G, B, factor
|
||||||
vec4 curvatureInfo;// Offset, Scale
|
vec4 curvatureInfo;// Offset, Scale, level
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform subsurfaceScatteringParametersBuffer {
|
uniform subsurfaceScatteringParametersBuffer {
|
||||||
|
@ -38,8 +38,16 @@ vec3 getBendFactor() {
|
||||||
return parameters.normalBendInfo.xyz * parameters.normalBendInfo.w;
|
return parameters.normalBendInfo.xyz * parameters.normalBendInfo.w;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float getScatteringLevel() {
|
||||||
|
return parameters.curvatureInfo.z;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool showBRDF() {
|
||||||
|
return parameters.curvatureInfo.w > 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
float unpackCurvature(float packedCurvature) {
|
float unpackCurvature(float packedCurvature) {
|
||||||
return abs(packedCurvature * 2 - 1) * 0.5f * parameters.curvatureInfo.y + parameters.curvatureInfo.x;
|
return abs(packedCurvature * 2 - 1) * parameters.curvatureInfo.y + parameters.curvatureInfo.x;
|
||||||
}
|
}
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
|
@ -28,7 +28,7 @@ public:
|
||||||
|
|
||||||
float depthThreshold{ 0.1f };
|
float depthThreshold{ 0.1f };
|
||||||
float basisScale{ 1.0f };
|
float basisScale{ 1.0f };
|
||||||
float curvatureScale{ 1.0f }; // Mean curvature value scaling (SI SI Dimension is [1/meters])
|
float curvatureScale{ 10.0f };
|
||||||
|
|
||||||
double getGpuTime() { return gpuTime; }
|
double getGpuTime() { return gpuTime; }
|
||||||
|
|
||||||
|
@ -63,16 +63,7 @@ private:
|
||||||
glm::vec4 resolutionInfo { -1.0f, 0.0f, 0.0f, 0.0f };
|
glm::vec4 resolutionInfo { -1.0f, 0.0f, 0.0f, 0.0f };
|
||||||
// Curvature algorithm
|
// Curvature algorithm
|
||||||
glm::vec4 curvatureInfo{ 0.0f };
|
glm::vec4 curvatureInfo{ 0.0f };
|
||||||
// Dithering info
|
|
||||||
glm::vec4 ditheringInfo { 0.0f, 0.0f, 0.01f, 1.0f };
|
|
||||||
// Sampling info
|
|
||||||
glm::vec4 sampleInfo { 11.0f, 1.0f/11.0f, 7.0f, 1.0f };
|
|
||||||
// Blurring info
|
|
||||||
glm::vec4 blurInfo { 1.0f, 3.0f, 2.0f, 0.0f };
|
|
||||||
// gaussian distribution coefficients first is the sampling radius (max is 6)
|
|
||||||
const static int GAUSSIAN_COEFS_LENGTH = 8;
|
|
||||||
float _gaussianCoefs[GAUSSIAN_COEFS_LENGTH];
|
|
||||||
|
|
||||||
Parameters() {}
|
Parameters() {}
|
||||||
};
|
};
|
||||||
gpu::BufferView _parametersBuffer;
|
gpu::BufferView _parametersBuffer;
|
||||||
|
|
|
@ -17,14 +17,6 @@ struct SurfaceGeometryParams {
|
||||||
vec4 resolutionInfo;
|
vec4 resolutionInfo;
|
||||||
// Curvature algorithm
|
// Curvature algorithm
|
||||||
vec4 curvatureInfo;
|
vec4 curvatureInfo;
|
||||||
// Dithering info
|
|
||||||
vec4 ditheringInfo;
|
|
||||||
// Sampling info
|
|
||||||
vec4 sampleInfo;
|
|
||||||
// Blurring info
|
|
||||||
vec4 blurInfo;
|
|
||||||
// gaussian distribution coefficients first is the sampling radius (max is 6)
|
|
||||||
vec4 _gaussianCoefs[2];
|
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform surfaceGeometryParamsBuffer {
|
uniform surfaceGeometryParamsBuffer {
|
||||||
|
@ -114,14 +106,12 @@ void main(void) {
|
||||||
// Fetch the z under the pixel (stereo or not)
|
// Fetch the z under the pixel (stereo or not)
|
||||||
float Zeye = getZEye(framePixelPos);
|
float Zeye = getZEye(framePixelPos);
|
||||||
|
|
||||||
// float nearPlaneScale = min(-Zeye / getCurvatureBasisScale(), 1.0);
|
|
||||||
float nearPlaneScale = 0.5 * getProjectionNear();
|
float nearPlaneScale = 0.5 * getProjectionNear();
|
||||||
|
|
||||||
vec3 worldNormal = getWorldNormal(frameTexcoordPos);
|
vec3 worldNormal = getWorldNormal(frameTexcoordPos);
|
||||||
|
|
||||||
// The position of the pixel fragment in Eye space then in world space
|
// The position of the pixel fragment in Eye space then in world space
|
||||||
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
|
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
|
||||||
// vec3 worldPos = (frameTransform._viewInverse * vec4(eyePos, 1.0)).xyz;
|
|
||||||
|
|
||||||
// Calculate the perspective scale.
|
// Calculate the perspective scale.
|
||||||
// Clamp to 0.5
|
// Clamp to 0.5
|
||||||
|
@ -140,24 +130,9 @@ void main(void) {
|
||||||
dFdu *= step(abs(dFdu.w), threshold);
|
dFdu *= step(abs(dFdu.w), threshold);
|
||||||
dFdv *= step(abs(dFdv.w), threshold);
|
dFdv *= step(abs(dFdv.w), threshold);
|
||||||
|
|
||||||
//outFragColor = vec4(du.x, du.y, 0.0, 1.0);
|
|
||||||
// outFragColor = vec4(viewportScale, 0.0, 1.0);
|
|
||||||
/* if (perspectiveScale < getCurvatureBasisScale()) {
|
|
||||||
//outFragColor = vec4(0.0, 0.0, 4 * perspectiveScale, 1.0);
|
|
||||||
} else if (perspectiveScale < 0.5) {
|
|
||||||
outFragColor = vec4(0.0, 0.0, 2 * perspectiveScale, 1.0);
|
|
||||||
return;
|
|
||||||
} else if (perspectiveScale > 1.0) {
|
|
||||||
outFragColor = vec4(perspectiveScale, 0.0, 0.0, 1.0);s
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
outFragColor = vec4(0.0, 0.5 * perspectiveScale, 0.0, 1.0);
|
|
||||||
return;
|
|
||||||
}*/
|
|
||||||
// Calculate ( du/dx, du/dy, du/dz ) and ( dv/dx, dv/dy, dv/dz )
|
// Calculate ( du/dx, du/dy, du/dz ) and ( dv/dx, dv/dy, dv/dz )
|
||||||
|
|
||||||
// Eval px, py, pz world positions of the basis centered on the world pos of the fragment
|
// Eval px, py, pz world positions of the basis centered on the world pos of the fragment
|
||||||
float axeLength = /*getCurvatureBasisScale() * */ nearPlaneScale;
|
float axeLength = nearPlaneScale;
|
||||||
|
|
||||||
vec3 ax = (frameTransform._view[0].xyz * axeLength);
|
vec3 ax = (frameTransform._view[0].xyz * axeLength);
|
||||||
vec3 ay = (frameTransform._view[1].xyz * axeLength);
|
vec3 ay = (frameTransform._view[1].xyz * axeLength);
|
||||||
|
@ -176,21 +151,7 @@ void main(void) {
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float nearZ = -getProjectionNear();
|
/* IN case the axis end point goes behind mid way near plane, this shouldn't happen
|
||||||
vec3 axeSign = vec3(1.0);
|
|
||||||
/* if (px.z >= nearZ) {
|
|
||||||
px = vec4(eyePos - ax, 0.0);
|
|
||||||
axeSign.x = -1.0;
|
|
||||||
}
|
|
||||||
if (py.z >= nearZ) {
|
|
||||||
py = vec4(eyePos - ay, 0.0);
|
|
||||||
axeSign.y = -1.0;
|
|
||||||
}
|
|
||||||
if (pz.z >= nearZ) {
|
|
||||||
pz = vec4(eyePos - az, 0.0);
|
|
||||||
axeSign.z = -1.0;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
if (px.z >= -nearPlaneScale) {
|
if (px.z >= -nearPlaneScale) {
|
||||||
outFragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
outFragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
return;
|
return;
|
||||||
|
@ -200,7 +161,7 @@ void main(void) {
|
||||||
} else if (pz.z >= -nearPlaneScale) {
|
} else if (pz.z >= -nearPlaneScale) {
|
||||||
outFragColor = vec4(0.0, 0.0, 1.0, 1.0);
|
outFragColor = vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
return;
|
return;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
|
|
||||||
// Project px, py pz to homogeneous clip space
|
// Project px, py pz to homogeneous clip space
|
||||||
|
@ -215,6 +176,7 @@ void main(void) {
|
||||||
pz.xy /= pz.w;
|
pz.xy /= pz.w;
|
||||||
|
|
||||||
vec2 nclipPos = (texcoordPos - 0.5) * 2.0;
|
vec2 nclipPos = (texcoordPos - 0.5) * 2.0;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (texcoordPos.y > 0.5) {
|
if (texcoordPos.y > 0.5) {
|
||||||
outFragColor = vec4(px.xy * 0.5 + 0.5, 0.0, 1.0);
|
outFragColor = vec4(px.xy * 0.5 + 0.5, 0.0, 1.0);
|
||||||
|
@ -224,10 +186,10 @@ void main(void) {
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale * nearPlaneScale);
|
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale);
|
||||||
px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.x;
|
px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||||
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.y;
|
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||||
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.z;
|
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv;
|
||||||
|
|
||||||
// Calculate dF/dx, dF/dy and dF/dz using chain rule
|
// Calculate dF/dx, dF/dy and dF/dz using chain rule
|
||||||
vec4 dFdx = dFdu * px.x + dFdv * px.y;
|
vec4 dFdx = dFdu * px.x + dFdv * px.y;
|
||||||
|
|
|
@ -73,10 +73,12 @@ public:
|
||||||
|
|
||||||
class BlurGaussianConfig : public Job::Config {
|
class BlurGaussianConfig : public Job::Config {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(bool enabled MEMBER enabled NOTIFY dirty) // expose enabled flag
|
Q_PROPERTY(bool enabled WRITE setEnabled READ isEnabled NOTIFY dirty) // expose enabled flag
|
||||||
Q_PROPERTY(float filterScale MEMBER filterScale NOTIFY dirty) // expose enabled flag
|
Q_PROPERTY(float filterScale MEMBER filterScale NOTIFY dirty) // expose enabled flag
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
BlurGaussianConfig() : Job::Config(true) {}
|
||||||
|
|
||||||
float filterScale{ 1.2f };
|
float filterScale{ 1.2f };
|
||||||
signals :
|
signals :
|
||||||
void dirty();
|
void dirty();
|
||||||
|
@ -112,6 +114,7 @@ class BlurGaussianDepthAwareConfig : public BlurGaussianConfig {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
Q_PROPERTY(float depthThreshold MEMBER depthThreshold NOTIFY dirty) // expose enabled flag
|
Q_PROPERTY(float depthThreshold MEMBER depthThreshold NOTIFY dirty) // expose enabled flag
|
||||||
public:
|
public:
|
||||||
|
BlurGaussianDepthAwareConfig() : BlurGaussianConfig() {}
|
||||||
|
|
||||||
float depthThreshold{ 2.0f };
|
float depthThreshold{ 2.0f };
|
||||||
signals:
|
signals:
|
||||||
|
|
|
@ -216,6 +216,7 @@ public:
|
||||||
JobConfig(bool enabled) : alwaysEnabled{ false }, enabled{ enabled } {}
|
JobConfig(bool enabled) : alwaysEnabled{ false }, enabled{ enabled } {}
|
||||||
|
|
||||||
bool isEnabled() { return alwaysEnabled || enabled; }
|
bool isEnabled() { return alwaysEnabled || enabled; }
|
||||||
|
void setEnabled(bool enable) { enabled = enable; }
|
||||||
|
|
||||||
bool alwaysEnabled{ true };
|
bool alwaysEnabled{ true };
|
||||||
bool enabled{ true };
|
bool enabled{ true };
|
||||||
|
@ -344,7 +345,7 @@ public:
|
||||||
|
|
||||||
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
void run(const SceneContextPointer& sceneContext, const RenderContextPointer& renderContext) {
|
||||||
renderContext->jobConfig = std::static_pointer_cast<Config>(_config);
|
renderContext->jobConfig = std::static_pointer_cast<Config>(_config);
|
||||||
if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->enabled) {
|
if (renderContext->jobConfig->alwaysEnabled || renderContext->jobConfig->isEnabled()) {
|
||||||
jobRun(_data, sceneContext, renderContext, _input.get<I>(), _output.edit<O>());
|
jobRun(_data, sceneContext, renderContext, _input.get<I>(), _output.edit<O>());
|
||||||
}
|
}
|
||||||
renderContext->jobConfig.reset();
|
renderContext->jobConfig.reset();
|
||||||
|
|
|
@ -39,8 +39,8 @@ Item {
|
||||||
|
|
||||||
Label {
|
Label {
|
||||||
text: sliderControl.value.toFixed(root.integral ? 0 : 2)
|
text: sliderControl.value.toFixed(root.integral ? 0 : 2)
|
||||||
anchors.left: root.left
|
anchors.left: root.labelControl.right
|
||||||
anchors.leftMargin: 140
|
anchors.leftMargin: 8
|
||||||
anchors.top: root.top
|
anchors.top: root.top
|
||||||
anchors.topMargin: 7
|
anchors.topMargin: 7
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ Item {
|
||||||
Slider {
|
Slider {
|
||||||
id: sliderControl
|
id: sliderControl
|
||||||
stepSize: root.integral ? 1.0 : 0.0
|
stepSize: root.integral ? 1.0 : 0.0
|
||||||
width: 192
|
width: 150
|
||||||
height: 20
|
height: 20
|
||||||
anchors.right: root.right
|
anchors.right: root.right
|
||||||
anchors.rightMargin: 8
|
anchors.rightMargin: 8
|
||||||
|
|
20
scripts/developer/utilities/render/debugDeferredLighting.js
Normal file
20
scripts/developer/utilities/render/debugDeferredLighting.js
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
//
|
||||||
|
// debugSurfaceGeometryPass.js
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 6/6/2016
|
||||||
|
// Copyright 2016 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
|
||||||
|
// Set up the qml ui
|
||||||
|
var qml = Script.resolvePath('deferredLighting.qml');
|
||||||
|
var window = new OverlayWindow({
|
||||||
|
title: 'Deferred Lighting Pass',
|
||||||
|
source: qml,
|
||||||
|
width: 400, height: 400,
|
||||||
|
});
|
||||||
|
window.setPosition(250, 750);
|
||||||
|
window.closed.connect(function() { Script.stop(); });
|
||||||
|
|
62
scripts/developer/utilities/render/deferredLighting.qml
Normal file
62
scripts/developer/utilities/render/deferredLighting.qml
Normal file
|
@ -0,0 +1,62 @@
|
||||||
|
//
|
||||||
|
// deferredLighting.qml
|
||||||
|
//
|
||||||
|
// Created by Sam Gateau on 6/6/2016
|
||||||
|
// Copyright 2016 High Fidelity, Inc.
|
||||||
|
//
|
||||||
|
// Distributed under the Apache License, Version 2.0.
|
||||||
|
// See the accompanying file LICENSE or https://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
//
|
||||||
|
import QtQuick 2.5
|
||||||
|
import QtQuick.Controls 1.4
|
||||||
|
import "configSlider"
|
||||||
|
|
||||||
|
Column {
|
||||||
|
spacing: 8
|
||||||
|
Column {
|
||||||
|
id: deferredLighting
|
||||||
|
spacing: 10
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
text: "Point Lights"
|
||||||
|
checked: true
|
||||||
|
onCheckedChanged: { Render.getConfig("RenderDeferred").enablePointLights = checked }
|
||||||
|
}
|
||||||
|
CheckBox {
|
||||||
|
text: "Spot Lights"
|
||||||
|
checked: true
|
||||||
|
onCheckedChanged: { Render.getConfig("RenderDeferred").enableSpotLights = checked }
|
||||||
|
}
|
||||||
|
|
||||||
|
Column{
|
||||||
|
CheckBox {
|
||||||
|
text: "Scattering"
|
||||||
|
checked: true
|
||||||
|
onCheckedChanged: { Render.getConfig("RenderDeferred").enableScattering = checked }
|
||||||
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
text: "Show Scattering BRDF"
|
||||||
|
checked: Render.getConfig("RenderDeferred").showScatteringBRDF
|
||||||
|
onCheckedChanged: { Render.getConfig("RenderDeferred").showScatteringBRDF = checked }
|
||||||
|
}
|
||||||
|
Repeater {
|
||||||
|
model: [ "Scattering Bent Red:RenderDeferred:bentRed:2.0",
|
||||||
|
"Scattering Bent Green:RenderDeferred:bentGreen:2.0",
|
||||||
|
"Scattering Bent Blue:RenderDeferred:bentBlue:2.0",
|
||||||
|
"Scattering Bent Scale:RenderDeferred:bentScale:5.0",
|
||||||
|
"Scattering Curvature Offset:RenderDeferred:curvatureOffset:1.0",
|
||||||
|
"Scattering Curvature Scale:RenderDeferred:curvatureScale:2.0",
|
||||||
|
]
|
||||||
|
ConfigSlider {
|
||||||
|
label: qsTr(modelData.split(":")[0])
|
||||||
|
integral: false
|
||||||
|
config: Render.getConfig(modelData.split(":")[1])
|
||||||
|
property: modelData.split(":")[2]
|
||||||
|
max: modelData.split(":")[3]
|
||||||
|
min: 0.0
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,7 +19,7 @@ Column {
|
||||||
|
|
||||||
Column{
|
Column{
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [ "Depth Threshold:depthThreshold:0.1", "Basis Scale:basisScale:2.0", "Curvature Scale:curvatureScale:10.0" ]
|
model: [ "Depth Threshold:depthThreshold:0.1", "Basis Scale:basisScale:2.0", "Curvature Scale:curvatureScale:100.0" ]
|
||||||
ConfigSlider {
|
ConfigSlider {
|
||||||
label: qsTr(modelData.split(":")[0])
|
label: qsTr(modelData.split(":")[0])
|
||||||
integral: false
|
integral: false
|
||||||
|
@ -32,6 +32,11 @@ Column {
|
||||||
}
|
}
|
||||||
|
|
||||||
Column{
|
Column{
|
||||||
|
CheckBox {
|
||||||
|
text: "Diffuse Curvature 1"
|
||||||
|
checked: true
|
||||||
|
onCheckedChanged: { Render.getConfig("DiffuseCurvature").enabled = checked }
|
||||||
|
}
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [ "Blur Scale:DiffuseCurvature:filterScale:2.0", "Blur Depth Threshold:DiffuseCurvature:depthThreshold:10.0", "Blur Scale2:DiffuseCurvature2:filterScale:2.0", "Blur Depth Threshold 2:DiffuseCurvature2:depthThreshold:10.0"]
|
model: [ "Blur Scale:DiffuseCurvature:filterScale:2.0", "Blur Depth Threshold:DiffuseCurvature:depthThreshold:10.0", "Blur Scale2:DiffuseCurvature2:filterScale:2.0", "Blur Depth Threshold 2:DiffuseCurvature2:depthThreshold:10.0"]
|
||||||
ConfigSlider {
|
ConfigSlider {
|
||||||
|
@ -43,6 +48,12 @@ Column {
|
||||||
min: 0.0
|
min: 0.0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CheckBox {
|
||||||
|
text: "Diffuse Curvature 2"
|
||||||
|
checked: true
|
||||||
|
onCheckedChanged: { Render.getConfig("DiffuseCurvature2").enabled = checked }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue