Protoype done

This commit is contained in:
samcake 2016-06-14 18:29:06 -07:00
parent 8858f9dc82
commit 42eaaf742d
8 changed files with 68 additions and 56 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

@ -113,6 +113,9 @@ RenderDeferredTask::RenderDeferredTask(CullFunctor cullFunctor) {
// Opaque all rendered, generate surface geometry buffers
const auto curvatureFramebufferAndDepth = addJob<SurfaceGeometryPass>("SurfaceGeometry", deferredFrameTransform);
const auto theCurvatureVarying = curvatureFramebufferAndDepth[0];
#define SIMPLE_BLUR 1
#if SIMPLE_BLUR
const auto curvatureFramebuffer = addJob<render::BlurGaussian>("DiffuseCurvature", curvatureFramebufferAndDepth.get<SurfaceGeometryPass::Outputs>().first);

View file

@ -34,7 +34,7 @@ enum ScatteringShaderMapSlots {
ScatteringTask_AlbedoMapSlot,
ScatteringTask_LinearMapSlot,
SCatteringTask_IBLMapSlot,
ScatteringTask_IBLMapSlot,
};
@ -84,6 +84,8 @@ gpu::PipelinePointer SubsurfaceScattering::getScatteringPipeline() {
slotBindings.insert(gpu::Shader::Binding(std::string("albedoMap"), ScatteringTask_AlbedoMapSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("linearDepthMap"), ScatteringTask_LinearMapSlot));
slotBindings.insert(gpu::Shader::Binding(std::string("skyboxMap"), ScatteringTask_IBLMapSlot));
gpu::Shader::makeProgram(*program, slotBindings);
gpu::StatePointer state = gpu::StatePointer(new gpu::State());
@ -194,8 +196,12 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext,
batch.setUniformBuffer(ScatteringTask_FrameTransformSlot, frameTransform->getFrameTransformBuffer());
batch.setUniformBuffer(ScatteringTask_ParamSlot, _parametersBuffer);
if (theLight->light)
if (theLight->light) {
batch.setUniformBuffer(ScatteringTask_LightSlot, theLight->light->getSchemaBuffer());
if (theLight->light->getAmbientMap()) {
batch.setResourceTexture(ScatteringTask_IBLMapSlot, theLight->light->getAmbientMap());
}
}
batch.setResourceTexture(ScatteringTask_ScatteringTableSlot, _scatteringTable);
batch.setResourceTexture(ScatteringTask_CurvatureMapSlot, curvatureFramebuffer->getRenderBuffer(0));
batch.setResourceTexture(ScatteringTask_DiffusedCurvatureMapSlot, diffusedFramebuffer->getRenderBuffer(0));
@ -203,7 +209,6 @@ void SubsurfaceScattering::run(const render::SceneContextPointer& sceneContext,
batch.setResourceTexture(ScatteringTask_AlbedoMapSlot, framebufferCache->getDeferredColorTexture());
batch.setResourceTexture(ScatteringTask_LinearMapSlot, framebufferCache->getDepthPyramidTexture());
batch.draw(gpu::TRIANGLE_STRIP, 4);
if (_showLUT) {

View file

@ -35,12 +35,12 @@ public:
float bentRed{ 1.5f };
float bentGreen{ 0.8f };
float bentBlue{ 0.3f };
float bentScale{ 1.0f };
float bentScale{ 1.5f };
float curvatureOffset{ 0.012f };
float curvatureScale{ 0.25f };
float curvatureOffset{ 0.08f };
float curvatureScale{ 0.8f };
bool showLUT{ true };
bool showLUT{ false };
signals:
void dirty();

View file

@ -14,7 +14,9 @@
<$declareDeferredFrameTransform()$>
<@include model/Light.slh@>
<@include DeferredGlobalLight.slh@>
<$declareEvalGlobalSpecularIrradiance(0, 1, 0)$>
uniform sampler2D linearDepthMap;
float getZEye(ivec2 pixel) {
@ -26,35 +28,6 @@ float getZEyeLinear(vec2 texcoord) {
<@include DeferredBufferRead.slh@>
vec3 fresnelSchlick(vec3 fresnelColor, vec3 lightDir, vec3 halfDir) {
return fresnelColor + (1.0 - fresnelColor) * pow(1.0 - clamp(dot(lightDir, halfDir), 0.0, 1.0), 5);
}
float specularDistribution(float roughness, vec3 normal, vec3 halfDir) {
float ndoth = clamp(dot(halfDir, normal), 0.0, 1.0);
float gloss2 = pow(0.001 + roughness, 4);
float denom = (ndoth * ndoth*(gloss2 - 1) + 1);
float power = gloss2 / (3.14159 * denom * denom);
return power;
}
// Frag Shading returns the diffuse amount as W and the specular rgb as xyz
vec4 evalPBRShading(vec3 fragNormal, vec3 fragLightDir, vec3 fragEyeDir, float metallic, vec3 fresnel, float roughness) {
// Diffuse Lighting
float diffuse = clamp(dot(fragNormal, 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 * diffuse;
return vec4(specular, (1.0 - metallic) * diffuse * (1 - fresnelColor.x));
}
vec2 sideToFrameTexcoord(vec2 side, vec2 texcoordPos) {
return vec2((texcoordPos.x + side.x) * side.y, texcoordPos.y);
}
@ -132,10 +105,10 @@ void main(void) {
// --> Calculate the light vector.
Light light = getLight();
vec3 lightVector = -getLightDirection(light); //normalize(uniformLightVector); //normalize(lightPos - sourcePos.xyz);
vec3 fragLightDir = -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);
// _fragColor = vec4(fetchBRDF(dot(bentNormalR, fragLightDir), abs(diffusedCurvature.w * 2 - 1)), 1.0);
// _fragColor = vec4(vec3(abs(dot(bentNormalR, fragLightDir))), 1.0);
// _fragColor = vec4(vec3(varTexCoord0, 0.0), 1.0);
// _fragColor = vec4(vec3(bentNormalR * 0.5 + 0.5), 1.0);
@ -147,7 +120,7 @@ void main(void) {
vec3 gN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.y));
vec3 bN = normalize(mix(bentNormalHigh, bentNormalLow, bendFactorSpectrum.z));
vec3 NdotLSpectrum = vec3(dot(rN, lightVector), dot(gN, lightVector), dot(bN, lightVector));
vec3 NdotLSpectrum = vec3(dot(rN, fragLightDir), dot(gN, fragLightDir), dot(bN, fragLightDir));
// --> Look up the pre-integrated curvature-dependent BDRF textures
vec3 bdrf = fetchBRDFSpectrum(NdotLSpectrum, curvature);
@ -174,11 +147,37 @@ void main(void) {
fresnel = fragment.diffuse;
fragment.metallic = 1.0;
}
vec3 albedo = fragment.diffuse;
vec3 fragNormal = fragment.normal;
//vec4 shading = evalPBRShading(rS, lightVector, fragEyeDir, fragment.metallic, fresnel, fragment.roughness);
_fragColor = vec4(fragment.diffuse * vec3(bdrf.xyz), 1.0);
vec4 shading;
{ // Key Sun Lighting
// Diffuse Lighting
float diffuse = clamp(dot(fragNormal, fragLightDir), 0.0, 1.0);
// Specular Lighting
vec3 halfDir = normalize(fragEyeDir + fragLightDir);
vec3 fresnelColor = fresnelSchlick(fresnel, fragLightDir,halfDir);
float power = specularDistribution(fragment.roughness, fragNormal, halfDir);
vec3 specular = power * fresnelColor * diffuse;
shading = vec4(specular, (1.0 - fragment.metallic) * diffuse * (1 - fresnelColor.x));
}
vec3 color = vec3(albedo * vec3(bdrf.xyz) + shading.rgb) * getLightColor(light) * getLightIntensity(light);
// Diffuse from ambient
color += (1 - fragment.metallic) * albedo * evalSphericalLight(getLightAmbientSphere(light), bentNormalHigh).xyz * 1.0 * getLightAmbientIntensity(light);
// Specular highlight from ambient
vec3 specularLighting = evalGlobalSpecularIrradiance(light, fragEyeDir, fragNormal, fragment.roughness, fresnel, 1.0);
color += specularLighting;
//_fragColor = vec4(evalSkyboxLight(rS, 0.0).rgb, 1.0);
_fragColor = vec4(color, 1.0);
}

View file

@ -77,7 +77,7 @@ class BlurGaussianConfig : public Job::Config {
Q_PROPERTY(float filterScale MEMBER filterScale NOTIFY dirty) // expose enabled flag
public:
float filterScale{ 1.0f };
float filterScale{ 1.2f };
signals :
void dirty();

View file

@ -27,14 +27,14 @@ void TaskConfig::refresh() {
namespace render{
template <> void varyingGet(const VaryingPairBase& data, uint8_t index, Varying& var) {
template <> void varyingGet(const VaryingPairBase* data, uint8_t index, Varying& var) {
if (index == 0) {
var = data.first;
var = data->first;
} else {
var = data.second;
var = data->second;
}
}
template <> uint8_t varyingLength(const VaryingPairBase& data) { return 2; }
template <> uint8_t varyingLength(const VaryingPairBase* data) { return 2; }
}

View file

@ -31,8 +31,8 @@ namespace render {
class Varying;
template <class T> void varyingGet(const T& data, uint8_t index, Varying& var) {}
template <class T> uint8_t varyingLength(const T& data) { return 0; }
template <class T> void varyingGet(const T* data, uint8_t index, Varying& var) {}
template <class T> uint8_t varyingLength(const T* data) { return 0; }
// A varying piece of data, to be used as Job/Task I/O
// TODO: Task IO
@ -65,6 +65,8 @@ protected:
template <class T> class Model : public Concept {
public:
using Data = T;
// using VarContainer = std::enable_if<T::VarContainer>;
//using VarContainer = std::conditional<std::enable_if<T::VarContainer>, T::VarContainer, T>;
Model(const Data& data) : _data(data) {}
virtual ~Model() = default;
@ -72,10 +74,10 @@ protected:
virtual Varying operator[] (uint8_t index) const {
Varying var;
varyingGet<T>(_data, index, var);
// varyingGet<VarContainer>(&_data, index, var);
return var;
}
virtual uint8_t length() const { return varyingLength<T>(_data); }
virtual uint8_t length() const { return varyingLength<T>(&_data); }
Data _data;
};
@ -89,13 +91,14 @@ protected:
using VaryingPairBase = std::pair<Varying, Varying>;
template <> void varyingGet(const VaryingPairBase& data, uint8_t index, Varying& var);
template <> uint8_t varyingLength(const VaryingPairBase& data);
template <> void varyingGet(const VaryingPairBase* data, uint8_t index, Varying& var);
template <> uint8_t varyingLength(const VaryingPairBase* data);
template < class T0, class T1 >
template < typename T0, typename T1 >
class VaryingPair : public VaryingPairBase {
public:
using Parent = VaryingPairBase;
using VarContainer = VaryingPairBase;
VaryingPair() : Parent(Varying(T0()), Varying(T1())) {}
VaryingPair(const VaryingPair& pair) : Parent(pair.first, pair.second) {}
@ -108,6 +111,7 @@ public:
T1& editSecond() { return second.edit<T1>(); }
};
template <class T0, class T1, class T2>
class VaryingTrio : public std::tuple<Varying, Varying,Varying>{
public:
@ -496,4 +500,5 @@ protected:
}
#endif // hifi_render_Task_h