diff --git a/libraries/render-utils/src/ModelRenderPayload.cpp b/libraries/render-utils/src/ModelRenderPayload.cpp index e4998e445a..31321f402f 100644 --- a/libraries/render-utils/src/ModelRenderPayload.cpp +++ b/libraries/render-utils/src/ModelRenderPayload.cpp @@ -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); } diff --git a/libraries/render-utils/src/ModelRenderPayload.h b/libraries/render-utils/src/ModelRenderPayload.h index 53285f5780..c193a77540 100644 --- a/libraries/render-utils/src/ModelRenderPayload.h +++ b/libraries/render-utils/src/ModelRenderPayload.h @@ -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(); }; diff --git a/libraries/render-utils/src/Skinning.slh b/libraries/render-utils/src/Skinning.slh index c1f45f951b..747f18ab34 100644 --- a/libraries/render-utils/src/Skinning.slh +++ b/libraries/render-utils/src/Skinning.slh @@ -1,21 +1,25 @@ - -<@if not SKINNING_SLH@> + +<@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@> \ No newline at end of file