Finish the integration of the diffusion pass in the SurfaceGeometryPass job, clean up ui

This commit is contained in:
samcake 2016-07-19 10:34:06 -07:00
parent 18ec4aa4e2
commit 36d58a2b82
6 changed files with 29 additions and 86 deletions

View file

@ -11,6 +11,8 @@
<@if not DEFERRED_BUFFER_SLH@>
<@def DEFERRED_BUFFER_SLH@>
<@include gpu/PackedNormal.slh@>
// Unpack the metallic-mode value
const float FRAG_PACK_SHADED_NON_METALLIC = 0.0;
const float FRAG_PACK_SHADED_METALLIC = 0.1;
@ -63,44 +65,7 @@ float packUnlit() {
return FRAG_PACK_UNLIT;
}
vec2 signNotZero(vec2 v) {
return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
}
vec2 float32x3_to_oct(in vec3 v) {
vec2 p = v.xy * (1.0 / (abs(v.x) + abs(v.y) + abs(v.z)));
return ((v.z <= 0.0) ? ((1.0 - abs(p.yx)) * signNotZero(p)) : p);
}
vec3 oct_to_float32x3(in vec2 e) {
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
if (v.z < 0) {
v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
}
return normalize(v);
}
vec3 snorm12x2_to_unorm8x3(vec2 f) {
vec2 u = vec2(round(clamp(f, -1.0, 1.0) * 2047.0 + 2047.0));
float t = floor(u.y / 256.0);
return floor(vec3(
u.x / 16.0,
fract(u.x / 16.0) * 256.0 + t,
u.y - t * 256.0
)) / 255.0;
}
vec2 unorm8x3_to_snorm12x2(vec3 u) {
u *= 255.0;
u.y *= (1.0 / 16.0);
vec2 s = vec2( u.x * 16.0 + floor(u.y),
fract(u.y) * (16.0 * 256.0) + u.z);
return clamp(s * (1.0 / 2047.0) - 1.0, vec2(-1.0), vec2(1.0));
}
<!
uniform sampler2D normalFittingMap;
vec3 bestFitNormal(vec3 normal) {
@ -119,14 +84,6 @@ vec3 bestFitNormal(vec3 normal) {
return (cN * 0.5 + 0.5);
}
vec3 packNormal(in vec3 n) {
return snorm12x2_to_unorm8x3(float32x3_to_oct(n));
}
vec3 unpackNormal(in vec3 p) {
return oct_to_float32x3(unorm8x3_to_snorm12x2(p));
}
!>
<@endif@>

View file

@ -137,18 +137,9 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
const auto midCurvatureNormalFramebuffer = surfaceGeometryPassOutputs.getN<SurfaceGeometryPass::Outputs>(2);
const auto lowCurvatureNormalFramebuffer = surfaceGeometryPassOutputs.getN<SurfaceGeometryPass::Outputs>(3);
// Simply update the scattering resource
const auto scatteringResource = addJob<SubsurfaceScattering>("Scattering");
/* const auto curvatureRangeTimer = addJob<BeginGPURangeTimer>("BeginCurvatureRangeTimer");
// TODO: Push this 2 diffusion stages into surfaceGeometryPass as they are working together
const auto diffuseCurvaturePassInputs = BlurGaussianDepthAware::Inputs(curvatureFramebuffer, halfLinearDepthTexture).hasVarying();
const auto midCurvatureNormalFramebuffer = addJob<render::BlurGaussianDepthAware>("DiffuseCurvatureMid", diffuseCurvaturePassInputs);
const auto lowCurvatureNormalFramebuffer = addJob<render::BlurGaussianDepthAware>("DiffuseCurvatureLow", diffuseCurvaturePassInputs, true); // THis blur pass generates it s render resource
addJob<EndGPURangeTimer>("CurvatureRangeTimer", curvatureRangeTimer);
*/
// AO job
addJob<AmbientOcclusionEffect>("AmbientOcclusion");

View file

@ -383,7 +383,11 @@ void SurfaceGeometryPass::configure(const Config& config) {
if (!_surfaceGeometryFramebuffer) {
_surfaceGeometryFramebuffer = std::make_shared<SurfaceGeometryFramebuffer>();
}
_surfaceGeometryFramebuffer->setResolutionLevel(config.resolutionLevel);
if (config.resolutionLevel != getResolutionLevel()) {
_parametersBuffer.edit<Parameters>().resolutionInfo.w = config.resolutionLevel;
}
_diffusePass.getParameters()->setFilterRadiusScale(config.diffuseFilterScale);
_diffusePass.getParameters()->setDepthThreshold(config.diffuseDepthThreshold);

View file

@ -165,7 +165,7 @@ public:
float depthThreshold{ 5.0f }; // centimeters
float basisScale{ 1.0f };
float curvatureScale{ 10.0f };
int resolutionLevel{ 0 };
int resolutionLevel{ 1 };
float diffuseFilterScale{ 0.2f };
float diffuseDepthThreshold{ 1.0f };
@ -189,9 +189,11 @@ public:
void configure(const Config& config);
void run(const render::SceneContextPointer& sceneContext, const render::RenderContextPointer& renderContext, const Inputs& inputs, Outputs& outputs);
float getCurvatureDepthThreshold() const { return _parametersBuffer.get<Parameters>().curvatureInfo.x; }
float getCurvatureBasisScale() const { return _parametersBuffer.get<Parameters>().curvatureInfo.y; }
float getCurvatureScale() const { return _parametersBuffer.get<Parameters>().curvatureInfo.w; }
int getResolutionLevel() const { return (int)_parametersBuffer.get<Parameters>().resolutionInfo.w; }
private:
typedef gpu::BufferView UniformBufferView;
@ -200,7 +202,7 @@ private:
class Parameters {
public:
// Resolution info
glm::vec4 resolutionInfo { -1.0f, 0.0f, 0.0f, 0.0f };
glm::vec4 resolutionInfo { 0.0f, 0.0f, 0.0f, 1.0f }; // Default Curvature & Diffusion is running half res
// Curvature algorithm
glm::vec4 curvatureInfo{ 0.0f };

View file

@ -12,6 +12,8 @@
<@include DeferredTransform.slh@>
<$declareDeferredFrameTransform()$>
<@include gpu/PackedNormal.slh@>
struct SurfaceGeometryParams {
// Resolution info
vec4 resolutionInfo;
@ -35,6 +37,10 @@ float getCurvatureScale() {
return params.curvatureInfo.w;
}
bool isFullResolution() {
return params.resolutionInfo.w == 0.0;
}
uniform sampler2D linearDepthMap;
float getZEye(ivec2 pixel) {
@ -44,29 +50,6 @@ float getZEyeLinear(vec2 texcoord) {
return -texture(linearDepthMap, texcoord).x;
}
vec2 signNotZero(vec2 v) {
return vec2((v.x >= 0.0) ? +1.0 : -1.0, (v.y >= 0.0) ? +1.0 : -1.0);
}
vec3 oct_to_float32x3(in vec2 e) {
vec3 v = vec3(e.xy, 1.0 - abs(e.x) - abs(e.y));
if (v.z < 0) {
v.xy = (1.0 - abs(v.yx)) * signNotZero(v.xy);
}
return normalize(v);
}
vec2 unorm8x3_to_snorm12x2(vec3 u) {
u *= 255.0;
u.y *= (1.0 / 16.0);
vec2 s = vec2( u.x * 16.0 + floor(u.y),
fract(u.y) * (16.0 * 256.0) + u.z);
return clamp(s * (1.0 / 2047.0) - 1.0, vec2(-1.0), vec2(1.0));
}
vec3 unpackNormal(in vec3 p) {
return oct_to_float32x3(unorm8x3_to_snorm12x2(p));
}
vec2 sideToFrameTexcoord(vec2 side, vec2 texcoordPos) {
return vec2((texcoordPos.x + side.x) * side.y, texcoordPos.y);
}
@ -78,10 +61,12 @@ vec3 getRawNormal(vec2 texcoord) {
}
vec3 getWorldNormal(vec2 texcoord) {
// vec3 rawNormal = getRawNormal(texcoord);
// return unpackNormal(rawNormal);
vec3 rawNormal = getRawNormal(texcoord);
return normalize((rawNormal - vec3(0.5)) * 2.0);
if (isFullResolution()) {
return unpackNormal(rawNormal);
} else {
return normalize((rawNormal - vec3(0.5)) * 2.0);
}
}
vec3 getWorldNormalDiff(vec2 texcoord, vec2 delta) {

View file

@ -30,7 +30,6 @@ Column {
model: [
"Basis Scale:basisScale:2.0:false",
"Curvature Scale:curvatureScale:100.0:false",
"Downscale:resolutionLevel:4:true"
]
ConfigSlider {
label: qsTr(modelData.split(":")[0])
@ -41,6 +40,11 @@ Column {
min: 0.0
}
}
CheckBox {
text: "Half Resolution"
checked: Render.getConfig("SurfaceGeometry")["resolutionLevel"]
onCheckedChanged: { Render.getConfig("SurfaceGeometry")["resolutionLevel"] = checked }
}
Repeater {
model: [ "Diffusion Scale:SurfaceGeometry:diffuseFilterScale:2.0",