IUse the light stage finally for the scattering prototype

This commit is contained in:
samcake 2016-06-14 09:54:51 -07:00
parent 414c43c012
commit 8858f9dc82
7 changed files with 34 additions and 18 deletions

View file

@ -44,7 +44,7 @@ public:
const glm::quat& orientation = glm::quat(), float exponent = 0.0f, float cutoff = PI);
void prepare(RenderArgs* args);
void render(const render::RenderContextPointer& renderContext);
void render(const render::RenderContextPointer& renderContext, );
void setupKeyLightBatch(gpu::Batch& batch, int lightBufferUnit, int skyboxCubemapUnit);

View file

@ -88,8 +88,9 @@ const glm::mat4& LightStage::Shadow::getProjection() const {
}
const LightStage::LightPointer LightStage::addLight(model::LightPointer light) {
Shadow stageShadow{light};
LightPointer stageLight = std::make_shared<Light>(std::move(stageShadow));
// Shadow stageShadow{light};
LightPointer stageLight = std::make_shared<Light>(Shadow(light));
stageLight->light = light;
lights.push_back(stageLight);
return stageLight;
}

View file

@ -52,6 +52,8 @@ public:
glm::float32 scale = 1 / MAP_SIZE;
};
UniformBufferView _schemaBuffer = nullptr;
friend class Light;
};
using ShadowPointer = std::shared_ptr<Shadow>;

View file

@ -15,12 +15,15 @@
#include "FramebufferCache.h"
#include "DeferredLightingEffect.h"
#include "subsurfaceScattering_makeLUT_frag.h"
#include "subsurfaceScattering_drawScattering_frag.h"
enum ScatteringShaderBufferSlots {
ScatteringTask_FrameTransformSlot = 0,
ScatteringTask_ParamSlot,
ScatteringTask_LightSlot,
};
enum ScatteringShaderMapSlots {
ScatteringTask_ScatteringTableSlot = 0,
@ -30,6 +33,8 @@ enum ScatteringShaderMapSlots {
ScatteringTask_AlbedoMapSlot,
ScatteringTask_LinearMapSlot,
SCatteringTask_IBLMapSlot,
};
@ -69,6 +74,7 @@ gpu::PipelinePointer SubsurfaceScattering::getScatteringPipeline() {
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("deferredFrameTransformBuffer"), ScatteringTask_FrameTransformSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("scatteringParamsBuffer"), ScatteringTask_ParamSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("lightBuffer"), ScatteringTask_LightSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("scatteringLUT"), ScatteringTask_ScatteringTableSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("curvatureMap"), ScatteringTask_CurvatureMapSlot));
@ -174,6 +180,8 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext,
return;
}
const auto theLight = DependencyManager::get<DeferredLightingEffect>()->getLightStage().lights[0];
gpu::doInBatch(args->_context, [=](gpu::Batch& batch) {
batch.enableStereo(false);
@ -186,7 +194,8 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext,
batch.setUniformBuffer(ScatteringTask_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
batch.setUniformBuffer(ScatteringTask_ParamSlot, _parametersBuffer);
if (theLight->light)
batch.setUniformBuffer(ScatteringTask_LightSlot, theLight->light->getSchemaBuffer());
batch.setResourceTexture(ScatteringTask_ScatteringTableSlot, _scatteringTable);
batch.setResourceTexture(ScatteringTask_CurvatureMapSlot, curvatureFramebuffer->getRenderBuffer(0));
batch.setResourceTexture(ScatteringTask_DiffusedCurvatureMapSlot, diffusedFramebuffer->getRenderBuffer(0));

View file

@ -14,6 +14,8 @@
<$declareDeferredFrameTransform()$>
<@include model/Light.slh@>
uniform sampler2D linearDepthMap;
float getZEye(ivec2 pixel) {
return -texelFetch(linearDepthMap, pixel, 0).x;
@ -109,7 +111,7 @@ float unpackCurvature(float packedCurvature) {
in vec2 varTexCoord0;
out vec4 _fragColor;
uniform vec3 uniformLightVector = vec3(1.0);
//uniform vec3 uniformLightVector = vec3(1.0);
void main(void) {
@ -128,7 +130,9 @@ void main(void) {
// _fragColor = vec4(vec3(diffusedCurvature.xyz), 1.0);
// --> Calculate the light vector.
vec3 lightVector = normalize(uniformLightVector); //normalize(lightPos - sourcePos.xyz);
Light light = getLight();
vec3 lightVector = -getLightDirection(light); //normalize(uniformLightVector); //normalize(lightPos - sourcePos.xyz);
// _fragColor = vec4(fetchBRDF(dot(bentNormalR, lightVector), abs(diffusedCurvature.w * 2 - 1)), 1.0);
// _fragColor = vec4(vec3(abs(dot(bentNormalR, lightVector))), 1.0);
@ -160,19 +164,19 @@ void main(void) {
// Fetch the z under the pixel (stereo or not)
float Zeye = getZEye(framePixelPos);
vec3 worldNormal = getWorldNormal(frameTexcoordPos);
vec3 worldNormal = fragment.normal;
// The position of the pixel fragment in Eye space then in world space
vec3 eyePos = evalEyePositionFromZeye(stereoSide.x, Zeye, texcoordPos);
vec3 fragEyeDir = -(frameTransform._viewInverse * vec4(normalize(eyePos), 0.0)).xyz;
vec3 fresnel = vec3(0.03); // Default Di-electric fresnel value
if (fragment.metallic > 0.5) {
fresnel = albedo;
fresnel = fragment.diffuse;
fragment.metallic = 1.0;
}
vec4 shading = evalPBRShading(rS, lightVector, fragEyeDir, fragment.metallic, fresnel, fragment.roughness);
_fragColor = vec4(shading.w * albedo * vec3(bdrf.xyz), 1.0);
//vec4 shading = evalPBRShading(rS, lightVector, fragEyeDir, fragment.metallic, fresnel, fragment.roughness);
_fragColor = vec4(fragment.diffuse * vec3(bdrf.xyz), 1.0);
}

View file

@ -306,8 +306,8 @@ void BlurGaussianDepthAware::run(const SceneContextPointer& sceneContext, const
RenderArgs* args = renderContext->args;
auto& sourceFramebuffer = SourceAndDepth.first. template get<gpu::FramebufferPointer>();//getFirst();
auto& depthTexture = SourceAndDepth.second. template get<gpu::TexturePointer>();//getSecond();
auto& sourceFramebuffer = SourceAndDepth.getFirst();
auto& depthTexture = SourceAndDepth.getSecond();
BlurInOutResource::Resources blurringResources;
if (!_inOutResources.updateResources(sourceFramebuffer, blurringResources)) {

View file

@ -117,14 +117,14 @@ public:
VaryingTrio(const VaryingTrio& trio) : Parent(std::get<0>(trio), std::get<1>(trio), std::get<2>(trio)) {}
VaryingTrio(const Varying& first, const Varying& second, const Varying& third) : Parent(first, second, third) {}
const T0& getFirst() const { return std::get<0>((*this)).get<T0>(); }
T0& editFirst() { return std::get<0>((*this)).edit<T0>(); }
const T0& getFirst() const { return std::get<0>((*this)).template get<T0>(); }
T0& editFirst() { return std::get<0>((*this)).template edit<T0>(); }
const T1& getSecond() const { return std::get<1>((*this)).get<T1>(); }
T1& editSecond() { return std::get<1>((*this)).edit<T1>(); }
const T1& getSecond() const { return std::get<1>((*this)).template get<T1>(); }
T1& editSecond() { return std::get<1>((*this)).template edit<T1>(); }
const T2& getThird() const { return std::get<2>((*this)).get<T2>(); }
T2& editThird() { return std::get<2>((*this)).edit<T2>(); }
const T2& getThird() const { return std::get<2>((*this)).template get<T2>(); }
T2& editThird() { return std::get<2>((*this)).template edit<T2>(); }
};
/*
template <class... _Types>