mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 12:54:30 +02:00
MErging and still trying to understand the curvature isssue
This commit is contained in:
parent
90e5697940
commit
3ec14fd746
16 changed files with 186 additions and 65 deletions
|
@ -167,6 +167,7 @@ public:
|
||||||
FBXTexture metallicTexture;
|
FBXTexture metallicTexture;
|
||||||
FBXTexture emissiveTexture;
|
FBXTexture emissiveTexture;
|
||||||
FBXTexture occlusionTexture;
|
FBXTexture occlusionTexture;
|
||||||
|
FBXTexture scatteringTexture;
|
||||||
FBXTexture lightmapTexture;
|
FBXTexture lightmapTexture;
|
||||||
glm::vec2 lightmapParams{ 0.0f, 1.0f };
|
glm::vec2 lightmapParams{ 0.0f, 1.0f };
|
||||||
|
|
||||||
|
|
|
@ -255,6 +255,10 @@ void FBXReader::consolidateFBXMaterials() {
|
||||||
|
|
||||||
if (material.name.contains("body_mat") || material.name.contains("skin")) {
|
if (material.name.contains("body_mat") || material.name.contains("skin")) {
|
||||||
material._material->setScattering(1.0);
|
material._material->setScattering(1.0);
|
||||||
|
if (!material.emissiveTexture.isNull()) {
|
||||||
|
material.scatteringTexture = material.emissiveTexture;
|
||||||
|
material.emissiveTexture = FBXTexture();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (material.opacity <= 0.0f) {
|
if (material.opacity <= 0.0f) {
|
||||||
|
|
|
@ -700,7 +700,7 @@ bool compileShader(GLenum shaderDomain, const std::string& shaderSource, const s
|
||||||
}
|
}
|
||||||
qCWarning(gpugllogging) << "GLShader::compileShader - errors:";
|
qCWarning(gpugllogging) << "GLShader::compileShader - errors:";
|
||||||
qCWarning(gpugllogging) << temp;
|
qCWarning(gpugllogging) << temp;
|
||||||
delete[] temp;
|
delete[] temp;
|
||||||
|
|
||||||
glDeleteShader(glshader);
|
glDeleteShader(glshader);
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -487,6 +487,11 @@ NetworkMaterial::NetworkMaterial(const FBXMaterial& material, const QUrl& textur
|
||||||
setTextureMap(MapChannel::EMISSIVE_MAP, map);
|
setTextureMap(MapChannel::EMISSIVE_MAP, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!material.scatteringTexture.filename.isEmpty()) {
|
||||||
|
auto map = fetchTextureMap(textureBaseUrl, material.scatteringTexture, NetworkTexture::SCATTERING_TEXTURE, MapChannel::SCATTERING_MAP);
|
||||||
|
setTextureMap(MapChannel::SCATTERING_MAP, map);
|
||||||
|
}
|
||||||
|
|
||||||
if (!material.lightmapTexture.filename.isEmpty()) {
|
if (!material.lightmapTexture.filename.isEmpty()) {
|
||||||
auto map = fetchTextureMap(textureBaseUrl, material.lightmapTexture, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP);
|
auto map = fetchTextureMap(textureBaseUrl, material.lightmapTexture, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP);
|
||||||
_lightmapTransform = material.lightmapTexture.transform;
|
_lightmapTransform = material.lightmapTexture.transform;
|
||||||
|
@ -507,6 +512,7 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) {
|
||||||
const auto& occlusionName = getTextureName(MapChannel::OCCLUSION_MAP);
|
const auto& occlusionName = getTextureName(MapChannel::OCCLUSION_MAP);
|
||||||
const auto& emissiveName = getTextureName(MapChannel::EMISSIVE_MAP);
|
const auto& emissiveName = getTextureName(MapChannel::EMISSIVE_MAP);
|
||||||
const auto& lightmapName = getTextureName(MapChannel::LIGHTMAP_MAP);
|
const auto& lightmapName = getTextureName(MapChannel::LIGHTMAP_MAP);
|
||||||
|
const auto& scatteringName = getTextureName(MapChannel::SCATTERING_MAP);
|
||||||
|
|
||||||
if (!albedoName.isEmpty()) {
|
if (!albedoName.isEmpty()) {
|
||||||
auto url = textureMap.contains(albedoName) ? textureMap[albedoName].toUrl() : QUrl();
|
auto url = textureMap.contains(albedoName) ? textureMap[albedoName].toUrl() : QUrl();
|
||||||
|
@ -549,6 +555,12 @@ void NetworkMaterial::setTextures(const QVariantMap& textureMap) {
|
||||||
setTextureMap(MapChannel::EMISSIVE_MAP, map);
|
setTextureMap(MapChannel::EMISSIVE_MAP, map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!scatteringName.isEmpty()) {
|
||||||
|
auto url = textureMap.contains(scatteringName) ? textureMap[scatteringName].toUrl() : QUrl();
|
||||||
|
auto map = fetchTextureMap(url, NetworkTexture::SCATTERING_TEXTURE, MapChannel::SCATTERING_MAP);
|
||||||
|
setTextureMap(MapChannel::SCATTERING_MAP, map);
|
||||||
|
}
|
||||||
|
|
||||||
if (!lightmapName.isEmpty()) {
|
if (!lightmapName.isEmpty()) {
|
||||||
auto url = textureMap.contains(lightmapName) ? textureMap[lightmapName].toUrl() : QUrl();
|
auto url = textureMap.contains(lightmapName) ? textureMap[lightmapName].toUrl() : QUrl();
|
||||||
auto map = fetchTextureMap(url, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP);
|
auto map = fetchTextureMap(url, NetworkTexture::LIGHTMAP_TEXTURE, MapChannel::LIGHTMAP_MAP);
|
||||||
|
|
|
@ -51,6 +51,7 @@ public:
|
||||||
EMISSIVE_TEXTURE,
|
EMISSIVE_TEXTURE,
|
||||||
CUBE_TEXTURE,
|
CUBE_TEXTURE,
|
||||||
OCCLUSION_TEXTURE,
|
OCCLUSION_TEXTURE,
|
||||||
|
SCATTERING_TEXTURE = OCCLUSION_TEXTURE,
|
||||||
LIGHTMAP_TEXTURE,
|
LIGHTMAP_TEXTURE,
|
||||||
CUSTOM_TEXTURE
|
CUSTOM_TEXTURE
|
||||||
};
|
};
|
||||||
|
|
|
@ -450,7 +450,10 @@ void RenderDeferredSetup::run(const render::SceneContextPointer& sceneContext, c
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform) {
|
void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, bool points, bool spots) {
|
||||||
|
if (!points && !spots) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
auto args = renderContext->args;
|
auto args = renderContext->args;
|
||||||
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
gpu::doInBatch(args->_context, [&](gpu::Batch& batch) {
|
||||||
|
|
||||||
|
@ -492,7 +495,7 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
|
||||||
batch.setViewTransform(monoViewTransform);
|
batch.setViewTransform(monoViewTransform);
|
||||||
|
|
||||||
// Splat Point lights
|
// Splat Point lights
|
||||||
if (!deferredLightingEffect->_pointLights.empty()) {
|
if (points && !deferredLightingEffect->_pointLights.empty()) {
|
||||||
// POint light pipeline
|
// POint light pipeline
|
||||||
batch.setPipeline(deferredLightingEffect->_pointLight);
|
batch.setPipeline(deferredLightingEffect->_pointLight);
|
||||||
|
|
||||||
|
@ -524,7 +527,7 @@ void RenderDeferredLocals::run(const render::SceneContextPointer& sceneContext,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Splat spot lights
|
// Splat spot lights
|
||||||
if (!deferredLightingEffect->_spotLights.empty()) {
|
if (spots && !deferredLightingEffect->_spotLights.empty()) {
|
||||||
// Spot light pipeline
|
// Spot light pipeline
|
||||||
batch.setPipeline(deferredLightingEffect->_spotLight);
|
batch.setPipeline(deferredLightingEffect->_spotLight);
|
||||||
|
|
||||||
|
@ -603,16 +606,34 @@ void RenderDeferredCleanup::run(const render::SceneContextPointer& sceneContext,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RenderDeferred::RenderDeferred() :
|
||||||
|
_subsurfaceScatteringResource(std::make_shared<SubsurfaceScatteringResource>())
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void RenderDeferred::configure(const Config& config) {
|
||||||
|
|
||||||
|
glm::vec4 bentInfo(config.bentRed, config.bentGreen, config.bentBlue, config.bentScale);
|
||||||
|
_subsurfaceScatteringResource->setBentNormalFactors(bentInfo);
|
||||||
|
|
||||||
|
glm::vec2 curvatureInfo(config.curvatureOffset, config.curvatureScale);
|
||||||
|
_subsurfaceScatteringResource->setCurvatureFactors(curvatureInfo);
|
||||||
|
|
||||||
|
|
||||||
|
_enablePointLights = config.enablePointLights;
|
||||||
|
_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 DeferredFrameTransformPointer& deferredTransform) {
|
||||||
if (!_subsurfaceScatteringResource) {
|
if (!_subsurfaceScatteringResource->getScatteringTable()) {
|
||||||
_subsurfaceScatteringResource = std::make_shared<SubsurfaceScatteringResource>();
|
|
||||||
_subsurfaceScatteringResource->generateScatteringTable(renderContext->args);
|
_subsurfaceScatteringResource->generateScatteringTable(renderContext->args);
|
||||||
}
|
}
|
||||||
|
|
||||||
setupJob.run(sceneContext, renderContext, deferredTransform, _subsurfaceScatteringResource);
|
setupJob.run(sceneContext, renderContext, deferredTransform, _subsurfaceScatteringResource);
|
||||||
lightsJob.run(sceneContext, renderContext, deferredTransform);
|
|
||||||
|
lightsJob.run(sceneContext, renderContext, deferredTransform, _enablePointLights, _enableSpotLights);
|
||||||
|
|
||||||
cleanupJob.run(sceneContext, renderContext);
|
cleanupJob.run(sceneContext, renderContext);
|
||||||
}
|
}
|
||||||
|
|
|
@ -122,7 +122,7 @@ class RenderDeferredLocals {
|
||||||
public:
|
public:
|
||||||
using JobModel = render::Job::ModelI<RenderDeferredLocals, DeferredFrameTransformPointer>;
|
using JobModel = render::Job::ModelI<RenderDeferredLocals, DeferredFrameTransformPointer>;
|
||||||
|
|
||||||
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform);
|
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const DeferredFrameTransformPointer& frameTransform, bool points, bool spots);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -133,9 +133,47 @@ public:
|
||||||
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
|
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
class RenderDeferredConfig : public render::Job::Config {
|
||||||
|
Q_OBJECT
|
||||||
|
Q_PROPERTY(float bentRed MEMBER bentRed NOTIFY dirty)
|
||||||
|
Q_PROPERTY(float bentGreen MEMBER bentGreen NOTIFY dirty)
|
||||||
|
Q_PROPERTY(float bentBlue MEMBER bentBlue NOTIFY dirty)
|
||||||
|
Q_PROPERTY(float bentScale MEMBER bentScale NOTIFY dirty)
|
||||||
|
|
||||||
|
Q_PROPERTY(float curvatureOffset MEMBER curvatureOffset NOTIFY dirty)
|
||||||
|
Q_PROPERTY(float curvatureScale MEMBER curvatureScale NOTIFY dirty)
|
||||||
|
|
||||||
|
|
||||||
|
Q_PROPERTY(bool enablePointLights MEMBER enablePointLights NOTIFY dirty)
|
||||||
|
Q_PROPERTY(bool enableSpotLights MEMBER enableSpotLights NOTIFY dirty)
|
||||||
|
public:
|
||||||
|
RenderDeferredConfig() : render::Job::Config(true) {}
|
||||||
|
|
||||||
|
float bentRed{ 1.5f };
|
||||||
|
float bentGreen{ 0.8f };
|
||||||
|
float bentBlue{ 0.3f };
|
||||||
|
float bentScale{ 1.5f };
|
||||||
|
|
||||||
|
float curvatureOffset{ 0.08f };
|
||||||
|
float curvatureScale{ 0.8f };
|
||||||
|
|
||||||
|
bool enablePointLights{ true };
|
||||||
|
bool enableSpotLights{ true };
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void dirty();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class RenderDeferred {
|
class RenderDeferred {
|
||||||
public:
|
public:
|
||||||
using JobModel = render::Job::ModelI<RenderDeferred, DeferredFrameTransformPointer>;
|
using Config = RenderDeferredConfig;
|
||||||
|
using JobModel = render::Job::ModelI<RenderDeferred, DeferredFrameTransformPointer, Config>;
|
||||||
|
|
||||||
|
RenderDeferred();
|
||||||
|
|
||||||
|
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 DeferredFrameTransformPointer& frameTransform);
|
||||||
|
|
||||||
|
@ -143,7 +181,11 @@ public:
|
||||||
RenderDeferredLocals lightsJob;
|
RenderDeferredLocals lightsJob;
|
||||||
RenderDeferredCleanup cleanupJob;
|
RenderDeferredCleanup cleanupJob;
|
||||||
|
|
||||||
|
protected:
|
||||||
SubsurfaceScatteringResourcePointer _subsurfaceScatteringResource;
|
SubsurfaceScatteringResourcePointer _subsurfaceScatteringResource;
|
||||||
|
|
||||||
|
bool _enablePointLights{ true };
|
||||||
|
bool _enableSpotLights{ true };
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_DeferredLightingEffect_h
|
#endif // hifi_DeferredLightingEffect_h
|
||||||
|
|
|
@ -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, pointMipSampler));
|
_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)));
|
||||||
_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);
|
||||||
|
|
|
@ -44,7 +44,7 @@ TexMapArray getTexMapArray() {
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
||||||
<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion)@>
|
<@func declareMaterialTextures(withAlbedo, withRoughness, withNormal, withMetallic, withEmissive, withOcclusion, withScattering)@>
|
||||||
|
|
||||||
<@if withAlbedo@>
|
<@if withAlbedo@>
|
||||||
uniform sampler2D albedoMap;
|
uniform sampler2D albedoMap;
|
||||||
|
@ -87,10 +87,18 @@ float fetchOcclusionMap(vec2 uv) {
|
||||||
return texture(occlusionMap, uv).r;
|
return texture(occlusionMap, uv).r;
|
||||||
}
|
}
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
|
||||||
|
<@if withScattering@>
|
||||||
|
uniform sampler2D scatteringMap;
|
||||||
|
float fetchScatteringMap(vec2 uv) {
|
||||||
|
return step(0.5, texture(scatteringMap, uv).r); // boolean scattering for now
|
||||||
|
}
|
||||||
|
<@endif@>
|
||||||
|
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
|
||||||
<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive)@>
|
<@func fetchMaterialTexturesCoord0(matKey, texcoord0, albedo, roughness, normal, metallic, emissive, scattering)@>
|
||||||
<@if albedo@>
|
<@if albedo@>
|
||||||
vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
|
vec4 <$albedo$> = (((<$matKey$> & (ALBEDO_MAP_BIT | OPACITY_MASK_MAP_BIT | OPACITY_TRANSLUCENT_MAP_BIT)) != 0) ? fetchAlbedoMap(<$texcoord0$>) : vec4(1.0));
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
@ -106,6 +114,9 @@ float fetchOcclusionMap(vec2 uv) {
|
||||||
<@if emissive@>
|
<@if emissive@>
|
||||||
vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0));
|
vec3 <$emissive$> = (((<$matKey$> & EMISSIVE_MAP_BIT) != 0) ? fetchEmissiveMap(<$texcoord0$>) : vec3(0.0));
|
||||||
<@endif@>
|
<@endif@>
|
||||||
|
<@if scattering@>
|
||||||
|
float <$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? fetchScatteringMap(<$texcoord0$>) : 0.0);
|
||||||
|
<@endif@>
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@>
|
<@func fetchMaterialTexturesCoord1(matKey, texcoord1, occlusion, lightmapVal)@>
|
||||||
|
@ -191,4 +202,10 @@ vec3 fetchLightmapMap(vec2 uv) {
|
||||||
}
|
}
|
||||||
<@endfunc@>
|
<@endfunc@>
|
||||||
|
|
||||||
|
<@func evalMaterialScattering(fetchedScattering, materialScattering, matKey, scattering)@>
|
||||||
|
{
|
||||||
|
<$scattering$> = (((<$matKey$> & SCATTERING_MAP_BIT) != 0) ? <$fetchedScattering$> : <$materialScattering$>);
|
||||||
|
}
|
||||||
|
<@endfunc@>
|
||||||
|
|
||||||
<@endif@>
|
<@endif@>
|
|
@ -217,6 +217,20 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ShapePipeline::Locat
|
||||||
batch.setResourceTexture(ShapePipeline::Slot::MAP::OCCLUSION, nullptr);
|
batch.setResourceTexture(ShapePipeline::Slot::MAP::OCCLUSION, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Scattering map
|
||||||
|
if (materialKey.isScatteringMap()) {
|
||||||
|
auto scatteringMap = textureMaps[model::MaterialKey::SCATTERING_MAP];
|
||||||
|
if (scatteringMap && scatteringMap->isDefined()) {
|
||||||
|
batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, scatteringMap->getTextureView());
|
||||||
|
|
||||||
|
// texcoord are assumed to be the same has albedo
|
||||||
|
} else {
|
||||||
|
batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, textureCache->getWhiteTexture());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
batch.setResourceTexture(ShapePipeline::Slot::MAP::SCATTERING, nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
// Emissive / Lightmap
|
// Emissive / Lightmap
|
||||||
if (materialKey.isLightmapMap()) {
|
if (materialKey.isLightmapMap()) {
|
||||||
auto lightmapMap = textureMaps[model::MaterialKey::LIGHTMAP_MAP];
|
auto lightmapMap = textureMaps[model::MaterialKey::LIGHTMAP_MAP];
|
||||||
|
|
|
@ -123,8 +123,8 @@ 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 scatteringInputs = render::Varying(SubsurfaceScattering::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", deferredFrameTransform);
|
||||||
|
@ -147,7 +147,7 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
|
||||||
// Debugging stages
|
// Debugging stages
|
||||||
{
|
{
|
||||||
// Debugging Deferred buffer job
|
// Debugging Deferred buffer job
|
||||||
const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(diffusedCurvatureFramebuffer, scatteringFramebuffer));
|
const auto debugFramebuffers = render::Varying(DebugDeferredBuffer::Inputs(diffusedCurvatureFramebuffer, curvatureFramebuffer));
|
||||||
addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers);
|
addJob<DebugDeferredBuffer>("DebugDeferredBuffer", debugFramebuffers);
|
||||||
|
|
||||||
// Scene Octree Debuging job
|
// Scene Octree Debuging job
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<@include model/Material.slh@>
|
<@include model/Material.slh@>
|
||||||
|
|
||||||
<@include MaterialTextures.slh@>
|
<@include MaterialTextures.slh@>
|
||||||
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION)$>
|
<$declareMaterialTextures(ALBEDO, ROUGHNESS, NORMAL, _SCRIBE_NULL, EMISSIVE, OCCLUSION, SCATTERING)$>
|
||||||
|
|
||||||
in vec4 _position;
|
in vec4 _position;
|
||||||
in vec2 _texCoord0;
|
in vec2 _texCoord0;
|
||||||
|
@ -29,7 +29,7 @@ in vec3 _color;
|
||||||
void main(void) {
|
void main(void) {
|
||||||
Material mat = getMaterial();
|
Material mat = getMaterial();
|
||||||
int matKey = getMaterialKey(mat);
|
int matKey = getMaterialKey(mat);
|
||||||
<$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex)$>
|
<$fetchMaterialTexturesCoord0(matKey, _texCoord0, albedoTex, roughnessTex, normalTex, _SCRIBE_NULL, emissiveTex, scatteringTex)$>
|
||||||
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
|
<$fetchMaterialTexturesCoord1(matKey, _texCoord1, occlusionTex)$>
|
||||||
|
|
||||||
float opacity = 1.0;
|
float opacity = 1.0;
|
||||||
|
@ -50,6 +50,7 @@ void main(void) {
|
||||||
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
<$tangentToViewSpace(normalTex, _normal, _tangent, viewNormal)$>
|
||||||
|
|
||||||
float scattering = getMaterialScattering(mat);
|
float scattering = getMaterialScattering(mat);
|
||||||
|
<$evalMaterialScattering(scatteringTex, scattering, matKey, scattering)$>;
|
||||||
|
|
||||||
packDeferredFragment(
|
packDeferredFragment(
|
||||||
viewNormal,
|
viewNormal,
|
||||||
|
|
|
@ -91,14 +91,10 @@ vec3 getWorldNormal(vec2 texcoord) {
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) {
|
vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) {
|
||||||
vec3 normal0 = getWorldNormal(texcoord - delta);
|
return getWorldNormal(texcoord + delta) - getWorldNormal(texcoord - delta);
|
||||||
vec3 normal1 = getWorldNormal(texcoord + delta);
|
|
||||||
return normal1 - normal0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
float getEyeDepthDiff(vec2 texcoord, vec2 delta) {
|
float getEyeDepthDiff(vec2 texcoord, vec2 delta) {
|
||||||
vec3 normal0 = getWorldNormal(texcoord - delta);
|
|
||||||
vec3 normal1 = getWorldNormal(texcoord + delta);
|
|
||||||
return getZEyeLinear(texcoord + delta) - getZEyeLinear(texcoord - delta);
|
return getZEyeLinear(texcoord + delta) - getZEyeLinear(texcoord - delta);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,18 +114,19 @@ 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 = min(-Zeye / getCurvatureBasisScale(), 1.0);
|
||||||
|
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;
|
// 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
|
||||||
float perspectiveScale = max(0.5, (-getProjScaleEye() / Zeye));
|
// float perspectiveScale = max(0.5, (-getProjScaleEye() / Zeye));
|
||||||
// float perspectiveScale = max(0.5, (-getProjectionNear() / Zeye));
|
float perspectiveScale = max(0.5, (-getCurvatureBasisScale() * getProjectionNear() / Zeye));
|
||||||
|
|
||||||
// Calculate dF/du and dF/dv
|
// Calculate dF/du and dF/dv
|
||||||
vec2 viewportScale = perspectiveScale * getInvWidthHeight();
|
vec2 viewportScale = perspectiveScale * getInvWidthHeight();
|
||||||
|
@ -141,7 +138,7 @@ void main(void) {
|
||||||
|
|
||||||
float threshold = getCurvatureDepthThreshold();
|
float threshold = getCurvatureDepthThreshold();
|
||||||
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(du.x, du.y, 0.0, 1.0);
|
||||||
// outFragColor = vec4(viewportScale, 0.0, 1.0);
|
// outFragColor = vec4(viewportScale, 0.0, 1.0);
|
||||||
|
@ -160,14 +157,15 @@ void main(void) {
|
||||||
// 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 dist = getCurvatureBasisScale() * nearPlaneScale;
|
float axeLength = /*getCurvatureBasisScale() * */ nearPlaneScale;
|
||||||
vec4 px = vec4(worldPos, 1.0) + vec4(dist, 0.0f, 0.0f, 0.0f);
|
|
||||||
vec4 py = vec4(worldPos, 1.0) + vec4(0.0f, dist, 0.0f, 0.0f);
|
|
||||||
vec4 pz = vec4(worldPos, 1.0) + vec4(0.0f, 0.0f, dist, 0.0f);
|
|
||||||
|
|
||||||
px = frameTransform._view * px;
|
vec3 ax = (frameTransform._view[0].xyz * axeLength);
|
||||||
py = frameTransform._view * py;
|
vec3 ay = (frameTransform._view[1].xyz * axeLength);
|
||||||
pz = frameTransform._view * pz;
|
vec3 az = (frameTransform._view[2].xyz * axeLength);
|
||||||
|
|
||||||
|
vec4 px = vec4(eyePos + ax, 0.0);
|
||||||
|
vec4 py = vec4(eyePos + ay, 0.0);
|
||||||
|
vec4 pz = vec4(eyePos + az, 0.0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
if (texcoordPos.y > 0.5) {
|
if (texcoordPos.y > 0.5) {
|
||||||
|
@ -178,6 +176,33 @@ void main(void) {
|
||||||
return;
|
return;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
float nearZ = -getProjectionNear();
|
||||||
|
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) {
|
||||||
|
outFragColor = vec4(1.0, 0.0, 0.0, 1.0);
|
||||||
|
return;
|
||||||
|
} else if (py.z >= -nearPlaneScale) {
|
||||||
|
outFragColor = vec4(0.0, 1.0, 0.0, 1.0);
|
||||||
|
return;
|
||||||
|
} else if (pz.z >= -nearPlaneScale) {
|
||||||
|
outFragColor = vec4(0.0, 0.0, 1.0, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// Project px, py pz to homogeneous clip space
|
// Project px, py pz to homogeneous clip space
|
||||||
mat4 viewProj = getProjection(stereoSide.x);
|
mat4 viewProj = getProjection(stereoSide.x);
|
||||||
px = viewProj * px;
|
px = viewProj * px;
|
||||||
|
@ -200,17 +225,24 @@ void main(void) {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale * nearPlaneScale);
|
float pixPerspectiveScaleInv = 1.0 / (perspectiveScale * nearPlaneScale);
|
||||||
px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv;
|
px.xy = (px.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.x;
|
||||||
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv;
|
py.xy = (py.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.y;
|
||||||
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv;
|
pz.xy = (pz.xy - nclipPos) * pixPerspectiveScaleInv * axeSign.z;
|
||||||
|
|
||||||
// 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;
|
||||||
vec4 dFdy = dFdu * py.x + dFdv * py.y;
|
vec4 dFdy = dFdu * py.x + dFdv * py.y;
|
||||||
vec4 dFdz = dFdu * pz.x + dFdv * pz.y;
|
vec4 dFdz = dFdu * pz.x + dFdv * pz.y;
|
||||||
|
|
||||||
|
vec3 trace = vec3(dFdx.x, dFdy.y, dFdz.z);
|
||||||
|
|
||||||
|
if (dot(trace, trace) > params.curvatureInfo.w) {
|
||||||
|
outFragColor = vec4(dFdx.x, dFdy.y, dFdz.z, 1.0);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Calculate the mean curvature
|
// Calculate the mean curvature
|
||||||
float meanCurvature = ((dFdx.x + dFdy.y + dFdz.z) * 0.33333333333333333) * params.curvatureInfo.w;
|
float meanCurvature = ((trace.x + trace.y + trace.z) * 0.33333333333333333) * params.curvatureInfo.w;
|
||||||
|
|
||||||
outFragColor = vec4(vec3(worldNormal + 1.0) * 0.5, (meanCurvature + 1.0) * 0.5);
|
outFragColor = vec4(vec3(worldNormal + 1.0) * 0.5, (meanCurvature + 1.0) * 0.5);
|
||||||
}
|
}
|
||||||
|
|
|
@ -60,6 +60,7 @@ void ShapePlumber::addPipeline(const Filter& filter, const gpu::ShaderPointer& p
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("metallicMap"), Slot::MAP::METALLIC));
|
slotBindings.insert(gpu::Shader::Binding(std::string("metallicMap"), Slot::MAP::METALLIC));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), Slot::MAP::EMISSIVE_LIGHTMAP));
|
slotBindings.insert(gpu::Shader::Binding(std::string("emissiveMap"), Slot::MAP::EMISSIVE_LIGHTMAP));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("occlusionMap"), Slot::MAP::OCCLUSION));
|
slotBindings.insert(gpu::Shader::Binding(std::string("occlusionMap"), Slot::MAP::OCCLUSION));
|
||||||
|
slotBindings.insert(gpu::Shader::Binding(std::string("scatteringMap"), Slot::MAP::SCATTERING));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), Slot::BUFFER::LIGHT));
|
slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), Slot::BUFFER::LIGHT));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), Slot::MAP::LIGHT_AMBIENT));
|
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), Slot::MAP::LIGHT_AMBIENT));
|
||||||
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), Slot::NORMAL_FITTING));
|
slotBindings.insert(gpu::Shader::Binding(std::string("normalFittingMap"), Slot::NORMAL_FITTING));
|
||||||
|
|
|
@ -209,6 +209,7 @@ public:
|
||||||
EMISSIVE_LIGHTMAP,
|
EMISSIVE_LIGHTMAP,
|
||||||
ROUGHNESS,
|
ROUGHNESS,
|
||||||
OCCLUSION,
|
OCCLUSION,
|
||||||
|
SCATTERING,
|
||||||
LIGHT_AMBIENT,
|
LIGHT_AMBIENT,
|
||||||
|
|
||||||
NORMAL_FITTING = 10,
|
NORMAL_FITTING = 10,
|
||||||
|
|
|
@ -19,7 +19,7 @@ Column {
|
||||||
|
|
||||||
Column{
|
Column{
|
||||||
Repeater {
|
Repeater {
|
||||||
model: [ "Depth Threshold:depthThreshold:1.0", "Basis Scale:basisScale:1.0", "Curvature Scale:curvatureScale:200.0" ]
|
model: [ "Depth Threshold:depthThreshold:0.1", "Basis Scale:basisScale:2.0", "Curvature Scale:curvatureScale:10.0" ]
|
||||||
ConfigSlider {
|
ConfigSlider {
|
||||||
label: qsTr(modelData.split(":")[0])
|
label: qsTr(modelData.split(":")[0])
|
||||||
integral: false
|
integral: false
|
||||||
|
@ -44,31 +44,5 @@ Column {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column{
|
|
||||||
Repeater {
|
|
||||||
model: [ "Scattering Bent Red:Scattering:bentRed:2.0",
|
|
||||||
"Scattering Bent Green:Scattering:bentGreen:2.0",
|
|
||||||
"Scattering Bent Blue:Scattering:bentBlue:2.0",
|
|
||||||
"Scattering Bent Scale:Scattering:bentScale:2.0",
|
|
||||||
"Scattering Curvature Offset:Scattering:curvatureOffset:1.0",
|
|
||||||
"Scattering Curvature Scale:Scattering:curvatureScale:1.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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
CheckBox {
|
|
||||||
text: "Show scatteringLUT"
|
|
||||||
checked: false
|
|
||||||
onCheckedChanged: { Render.getConfig("Scattering").showLUT = checked }
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue