Uniform buffer for skeleton joint bind pose

This commit is contained in:
samcake 2015-10-05 23:33:58 -07:00
parent 894c8c0a93
commit 4270b83c0f
3 changed files with 33 additions and 43 deletions

View file

@ -170,6 +170,8 @@ void ModelRender::RenderPipelineLib::addRenderPipeline(ModelRender::RenderKey ke
gpu::ShaderPointer& pixelShader) {
gpu::Shader::BindingSet slotBindings;
slotBindings.insert(gpu::Shader::Binding(std::string("skinClusterBuffer"), ModelRender::SKINNING_GPU_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("materialBuffer"), ModelRender::MATERIAL_GPU_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("diffuseMap"), ModelRender::DIFFUSE_MAP_SLOT));
slotBindings.insert(gpu::Shader::Binding(std::string("normalMap"), ModelRender::NORMAL_MAP_SLOT));
@ -258,9 +260,7 @@ void ModelRender::RenderPipelineLib::initLocations(gpu::ShaderPointer& program,
locations.emissiveTextureUnit = program->getTextures().findLocation("emissiveMap");
locations.materialBufferUnit = program->getBuffers().findLocation("materialBuffer");
locations.lightBufferUnit = program->getBuffers().findLocation("lightBuffer");
locations.clusterMatrices = program->getUniforms().findLocation("clusterMatrices");
locations.clusterIndices = program->getInputs().findLocation("inSkinClusterIndex");
locations.clusterWeights = program->getInputs().findLocation("inSkinClusterWeight");
locations.skinClusterBufferUnit = program->getBuffers().findLocation("skinClusterBuffer");
}
@ -322,10 +322,6 @@ namespace render {
template <> void payloadRender(const MeshPartPayload::Pointer& payload, RenderArgs* args) {
return payload->render(args);
}
/* template <> const model::MaterialKey& shapeGetMaterialKey(const MeshPartPayload::Pointer& payload) {
return payload->model->getPartMaterial(payload->meshIndex, payload->partIndex);
}*/
}
using namespace render;
@ -502,28 +498,20 @@ void MeshPartPayload::bindMaterial(gpu::Batch& batch, const ModelRender::Locatio
}
void MeshPartPayload::bindTransform(gpu::Batch& batch, const ModelRender::Locations* locations) const {
Transform transform;
// Still relying on the raw data from the
// Still relying on the raw data from the model
const Model::MeshState& state = model->_meshStates.at(meshIndex);
if (_isSkinned) {
const float* bones;
if (model->_cauterizeBones) {
bones = (const float*)state.cauterizedClusterMatrices.constData();
} else {
bones = (const float*)state.clusterMatrices.constData();
}
batch._glUniformMatrix4fv(locations->clusterMatrices, state.clusterMatrices.size(), false, bones);
transform.preTranslate(model->_translation);
Transform transform;
if (state.clusterBuffer) {
batch.setUniformBuffer(ModelRender::SKINNING_GPU_SLOT, state.clusterBuffer);
} else {
if (model->_cauterizeBones) {
transform = Transform(state.cauterizedClusterMatrices[0]);
} else {
transform = Transform(state.clusterMatrices[0]);
}
transform.preTranslate(model->_translation);
}
transform.preTranslate(model->_translation);
batch.setModelTransform(transform);
}

View file

@ -24,7 +24,8 @@ class Model;
class ModelRender {
public:
static const int SKINNING_GPU_SLOT = 2;
static const int MATERIAL_GPU_SLOT = 3;
static const int DIFFUSE_MAP_SLOT = 0;
static const int NORMAL_MAP_SLOT = 1;
@ -34,7 +35,6 @@ public:
class Locations {
public:
int tangent;
int alphaThreshold;
int texcoordMatrices;
int diffuseTextureUnit;
@ -45,9 +45,7 @@ public:
int glowIntensity;
int normalFittingMapUnit;
int materialBufferUnit;
int clusterMatrices;
int clusterIndices;
int clusterWeights;
int skinClusterBufferUnit;
int lightBufferUnit;
};
@ -159,7 +157,7 @@ public:
};
static RenderPipelineLib _renderPipelineLib;
static const ModelRender::RenderPipelineLib& ModelRender::getRenderPipelineLib();
static const RenderPipelineLib& getRenderPipelineLib();
};

View file

@ -1,21 +1,25 @@
<!
// Skinning.slh
// libraries/render-utils/src
//
// Created by Sam Gateau on 10/5/15.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
!>
<@if not SKINNING_SLH@>
<!
// Skinning.slh
// libraries/render-utils/src
//
// Created by Sam Gateau on 10/5/15.
// Copyright 2013 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
!>
<@if not SKINNING_SLH@>
<@def SKINNING_SLH@>
const int MAX_TEXCOORDS = 2;
const int MAX_CLUSTERS = 128;
const int INDICES_PER_VERTEX = 4;
uniform mat4 clusterMatrices[MAX_CLUSTERS];
//uniform mat4 clusterMatrices[MAX_CLUSTERS];
layout(std140) uniform skinClusterBuffer {
mat4 clusterMatrices[MAX_CLUSTERS];
};
void skinPosition(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, out vec4 skinnedPosition) {
vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0);
@ -43,8 +47,8 @@ void skinPositionNormal(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPo
skinnedPosition = newPosition;
skinnedNormal = newNormal.xyz;
}
}
void skinPositionNormalTangent(vec4 skinClusterIndex, vec4 skinClusterWeight, vec4 inPosition, vec3 inNormal, vec3 inTangent,
out vec4 skinnedPosition, out vec3 skinnedNormal, out vec3 skinnedTangent) {
vec4 newPosition = vec4(0.0, 0.0, 0.0, 0.0);
@ -62,7 +66,7 @@ void skinPositionNormalTangent(vec4 skinClusterIndex, vec4 skinClusterWeight, ve
skinnedPosition = newPosition;
skinnedNormal = newNormal.xyz;
skinnedTangent = newTangent.xyz;
}
}
<@endif@>