fixing the shadow

This commit is contained in:
samcake 2018-02-28 17:46:22 -08:00
parent b90af9e3b5
commit a7542d5b90
4 changed files with 35 additions and 5 deletions

View file

@ -672,7 +672,7 @@ void initZPassPipelines(ShapePlumber& shapePlumber, gpu::StatePointer state) {
auto skinPixel = skin_model_shadow_frag::getShader(); auto skinPixel = skin_model_shadow_frag::getShader();
gpu::ShaderPointer skinProgram = gpu::Shader::createProgram(skinVertex, skinPixel); gpu::ShaderPointer skinProgram = gpu::Shader::createProgram(skinVertex, skinPixel);
shapePlumber.addPipeline( shapePlumber.addPipeline(
ShapeKey::Filter::Builder().withSkinned().withoutFade(), ShapeKey::Filter::Builder().withSkinned().withoutDualQuatSkinned().withoutFade(),
skinProgram, state); skinProgram, state);
auto modelFadeVertex = model_shadow_fade_vert::getShader(); auto modelFadeVertex = model_shadow_fade_vert::getShader();
@ -686,8 +686,21 @@ void initZPassPipelines(ShapePlumber& shapePlumber, gpu::StatePointer state) {
auto skinFadePixel = skin_model_shadow_fade_frag::getShader(); auto skinFadePixel = skin_model_shadow_fade_frag::getShader();
gpu::ShaderPointer skinFadeProgram = gpu::Shader::createProgram(skinFadeVertex, skinFadePixel); gpu::ShaderPointer skinFadeProgram = gpu::Shader::createProgram(skinFadeVertex, skinFadePixel);
shapePlumber.addPipeline( shapePlumber.addPipeline(
ShapeKey::Filter::Builder().withSkinned().withFade(), ShapeKey::Filter::Builder().withSkinned().withoutDualQuatSkinned().withFade(),
skinFadeProgram, state); skinFadeProgram, state);
//Added for dual quaternions
auto skinModelShadowDualQuatVertex = skin_model_shadow_dq_vert::getShader();
gpu::ShaderPointer skinModelShadowDualQuatProgram = gpu::Shader::createProgram(skinModelShadowDualQuatVertex, skinPixel);
shapePlumber.addPipeline(
ShapeKey::Filter::Builder().withSkinned().withDualQuatSkinned().withoutFade(),
skinModelShadowDualQuatProgram, state);
/*
auto skinModelShadowFadeDualQuatVertex = skin_model_shadow_fade_dq_vert::getShader();
gpu::ShaderPointer skinModelShadowFadeDualQuatProgram = gpu::Shader::createProgram(skinModelShadowFadeDualQuatVertex, skinFadePixel);
shapePlumber.addPipeline(
ShapeKey::Filter::Builder().withSkinned().withDualQuatSkinned().withFade(),
skinModelShadowFadeDualQuatProgram, state);*/
} }
#include "RenderPipelines.h" #include "RenderPipelines.h"

View file

@ -163,8 +163,10 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con
auto shadowPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder); auto shadowPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder);
auto shadowSkinnedPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withSkinned()); auto shadowSkinnedPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withSkinned());
auto shadowSkinnedDQPipeline = _shapePlumber->pickPipeline(args, defaultKeyBuilder.withSkinned().withDualQuatSkinned());
std::vector<ShapeKey> skinnedShapeKeys{}; std::vector<ShapeKey> skinnedShapeKeys{};
std::vector<ShapeKey> skinnedDQShapeKeys{};
std::vector<ShapeKey> ownPipelineShapeKeys{}; std::vector<ShapeKey> ownPipelineShapeKeys{};
// Iterate through all inShapes and render the unskinned // Iterate through all inShapes and render the unskinned
@ -172,7 +174,11 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con
batch.setPipeline(shadowPipeline->pipeline); batch.setPipeline(shadowPipeline->pipeline);
for (auto items : inShapes) { for (auto items : inShapes) {
if (items.first.isSkinned()) { if (items.first.isSkinned()) {
skinnedShapeKeys.push_back(items.first); if (items.first.isDualQuatSkinned()) {
skinnedDQShapeKeys.push_back(items.first);
} else {
skinnedShapeKeys.push_back(items.first);
}
} else if (!items.first.hasOwnPipeline()) { } else if (!items.first.hasOwnPipeline()) {
renderItems(renderContext, items.second); renderItems(renderContext, items.second);
} else { } else {
@ -187,6 +193,13 @@ void RenderShadowMap::run(const render::RenderContextPointer& renderContext, con
renderItems(renderContext, inShapes.at(key)); renderItems(renderContext, inShapes.at(key));
} }
// Reiterate to render the DQ skinned
args->_shapePipeline = shadowSkinnedDQPipeline;
batch.setPipeline(shadowSkinnedDQPipeline->pipeline);
for (const auto& key : skinnedDQShapeKeys) {
renderItems(renderContext, inShapes.at(key));
}
// Finally render the items with their own pipeline last to prevent them from breaking the // Finally render the items with their own pipeline last to prevent them from breaking the
// render state. This is probably a temporary code as there is probably something better // render state. This is probably a temporary code as there is probably something better
// to do in the render call of objects that have their own pipeline. // to do in the render call of objects that have their own pipeline.

View file

@ -30,6 +30,7 @@ out vec3 _normal;
out vec3 _tangent; out vec3 _tangent;
out vec3 _color; out vec3 _color;
out float _alpha; out float _alpha;
out vec4 _worldPosition;
void main(void) { void main(void) {
vec4 position = vec4(0.0, 0.0, 0.0, 0.0); vec4 position = vec4(0.0, 0.0, 0.0, 0.0);
@ -53,6 +54,7 @@ void main(void) {
TransformCamera cam = getTransformCamera(); TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject(); TransformObject obj = getTransformObject();
<$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$> <$transformModelToEyeAndClipPos(cam, obj, position, _position, gl_Position)$>
<$transformModelToWorldPos(obj, position, _worldPosition)$>
<$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedNormal.xyz, interpolatedNormal.xyz)$>
<$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$> <$transformModelToWorldDir(cam, obj, interpolatedTangent.xyz, interpolatedTangent.xyz)$>

View file

@ -135,8 +135,8 @@ public:
Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); } Builder& withSkinned() { _flags.set(SKINNED); _mask.set(SKINNED); return (*this); }
Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); } Builder& withoutSkinned() { _flags.reset(SKINNED); _mask.set(SKINNED); return (*this); }
Builder& withDualQuatSkinned() { _flags.set(DUAL_QUAT_SKINNED); _mask.set(SKINNED); return (*this); } Builder& withDualQuatSkinned() { _flags.set(DUAL_QUAT_SKINNED); _mask.set(DUAL_QUAT_SKINNED); return (*this); }
Builder& withoutDualQuatSkinned() { _flags.reset(DUAL_QUAT_SKINNED); _mask.set(SKINNED); return (*this); } Builder& withoutDualQuatSkinned() { _flags.reset(DUAL_QUAT_SKINNED); _mask.set(DUAL_QUAT_SKINNED); return (*this); }
Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } Builder& withDepthOnly() { _flags.set(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); }
Builder& withoutDepthOnly() { _flags.reset(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); } Builder& withoutDepthOnly() { _flags.reset(DEPTH_ONLY); _mask.set(DEPTH_ONLY); return (*this); }
@ -176,6 +176,7 @@ public:
bool isUnlit() const { return _flags[UNLIT]; } bool isUnlit() const { return _flags[UNLIT]; }
bool isTranslucent() const { return _flags[TRANSLUCENT]; } bool isTranslucent() const { return _flags[TRANSLUCENT]; }
bool isSkinned() const { return _flags[SKINNED]; } bool isSkinned() const { return _flags[SKINNED]; }
bool isDualQuatSkinned() const { return _flags[DUAL_QUAT_SKINNED]; }
bool isDepthOnly() const { return _flags[DEPTH_ONLY]; } bool isDepthOnly() const { return _flags[DEPTH_ONLY]; }
bool isDepthBiased() const { return _flags[DEPTH_BIAS]; } bool isDepthBiased() const { return _flags[DEPTH_BIAS]; }
bool isWireframe() const { return _flags[WIREFRAME]; } bool isWireframe() const { return _flags[WIREFRAME]; }
@ -216,6 +217,7 @@ inline QDebug operator<<(QDebug debug, const ShapeKey& key) {
<< "isUnlit:" << key.isUnlit() << "isUnlit:" << key.isUnlit()
<< "isTranslucent:" << key.isTranslucent() << "isTranslucent:" << key.isTranslucent()
<< "isSkinned:" << key.isSkinned() << "isSkinned:" << key.isSkinned()
<< "isDualQuatSkinned:" << key.isDualQuatSkinned()
<< "isDepthOnly:" << key.isDepthOnly() << "isDepthOnly:" << key.isDepthOnly()
<< "isDepthBiased:" << key.isDepthBiased() << "isDepthBiased:" << key.isDepthBiased()
<< "isWireframe:" << key.isWireframe() << "isWireframe:" << key.isWireframe()