Apply fix to gl41 backend needed for proper Resource BUffer on gl41

This commit is contained in:
sam gateau 2018-09-20 16:09:08 -07:00
parent b04cbbb0ac
commit 5d80a89094
6 changed files with 130 additions and 40 deletions

View file

@ -59,4 +59,4 @@ void applyBlendshapeOffset(int i, vec4 inPosition, out vec4 position
<@endfunc@>
<@endif@>
<@endif@> // if not BLENDSHAPE_SLH

View file

@ -0,0 +1,91 @@
<!
// MeshDeformer.slh
// Created by Sam Gateau on 9/20/2018
// Copyright 2018 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 MESH_DEFORMER_SLH@>
<@def MESH_DEFORMER_SLH@>
// MeshDeformer.slh
<@include Skinning.slh@>
<@include Blendshape.slh@>
<@func declareMeshDeformer(USE_NORMAL, USE_TANGENT, USE_SKINNING, USE_DUAL_QUATERNION, USE_BLENDSHAPE)@>
<@if USE_SKINNING@>
<$declareUseDualQuaternionSkinning($USE_DUAL_QUATERNION$) $>
<@endif@>
<!
<@include ender-utils/Blendshape.slh@>
<$declareApplyBlendshapeOffsets($USE_NORMAL$, $USE_TANGENT$)$>
!>
<@func evalMeshDeformer(inPosition, outPosition, inNormal, outNormal, inTangent, outTangent, inSkinClusterIndex, inSkinClusterWeight, vertexIndex)@>
{
<@if USE_BLENDSHAPE@>
vec4 _deformedPosition = vec4(0.0, 0.0, 0.0, 0.0);
<@if USE_NORMAL@>
vec3 _deformedNormal = vec3(0.0, 0.0, 0.0);
<@endif@>
<@if USE_TANGENT@>
vec3 _deformedTangent = vec3(0.0, 0.0, 0.0);
<@endif@>
<@if USE_TANGENT@>
applyBlendshapeOffset(<$vertexIndex$>, <$inPosition$>, _deformedPosition, <$inNormal$>, _deformedNormal, <$inTangent$>, _deformedTangent);
<@else@>
<@if USE_NORMAL@>
applyBlendshapeOffset(<$vertexIndex$>, <$inPosition$>, _deformedPosition, <$inNormal$>, _deformedNormal);
<@else@>
applyBlendshapeOffset(vertexIndex, <$inPosition$>, _deformedPosition);
<@endif@>
<@endif@>
<@else@>
vec4 _deformedPosition = <$inPosition$>;
<@if USE_NORMAL@>
vec3 _deformedNormal = <$inNormal$>;
<@endif@>
<@if USE_TANGENT@>
vec3 _deformedTangent = <$inTangent$>;
<@endif@>
<@endif@>
<@if USE_SKINNING@>
<@if USE_TANGENT@>
skinPositionNormalTangent(<$inSkinClusterIndex$>, <$inSkinClusterWeight$>, _deformedPosition, _deformedNormal, _deformedTangent, _deformedPosition, _deformedNormal, _deformedTangent);
<@else@>
<@if USE_NORMAL@>
skinPositionNormal(<$inSkinClusterIndex$>, <$inSkinClusterWeight$>, _deformedPosition, _deformedNormal, _deformedPosition, _deformedNormal);
<@else@>
skinPosition(<$inSkinClusterIndex$>, <$inSkinClusterWeight$>, _deformedPosition, _deformedPosition);
<@endif@>
<@endif@>
<@endif@>
<$outPosition$> = _deformedPosition;
<@if USE_NORMAL@>
<$outNormal$> = _deformedNormal;
<@endif@>
<@if USE_TANGENT@>
<$outTangent$> = _deformedTangent;
<@endif@>
}
<@endfunc@>
<@endif@> // if not MESH_DEFORMER_SLH

View file

@ -208,11 +208,6 @@ ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, in
bool useDualQuaternionSkinning = model->getUseDualQuaternionSkinning();
auto buffer = model->_blendshapeBuffers.find(meshIndex);
if (buffer != model->_blendshapeBuffers.end()) {
_blendshapeBuffer = buffer->second;
}
auto& modelMesh = model->getGeometry()->getMeshes().at(_meshIndex);
const Model::MeshState& state = model->getMeshState(_meshIndex);
@ -242,6 +237,17 @@ ModelMeshPartPayload::ModelMeshPartPayload(ModelPointer model, int meshIndex, in
updateTransformForSkinnedMesh(renderTransform, transform);
initCache(model);
if (_isBlendShaped) {
auto buffer = model->_blendshapeBuffers.find(meshIndex);
if (buffer != model->_blendshapeBuffers.end()) {
_blendshapeBuffer = buffer->second;
}
if (!_isSkinned) {
qWarning() << "MeshPArt Payload is blendshape but not skinned";
}
}
}
void ModelMeshPartPayload::initCache(const ModelPointer& model) {

View file

@ -308,9 +308,7 @@ bool Model::updateGeometry() {
state.clusterDualQuaternions.resize(mesh.clusters.size());
state.clusterMatrices.resize(mesh.clusters.size());
_meshStates.push_back(state);
if (_blendshapeBuffers.find(i) == _blendshapeBuffers.end()) {
initializeBlendshapes(mesh, i);
}
initializeBlendshapes(mesh, i);
i++;
}
_blendshapeBuffersInitialized = true;
@ -1585,12 +1583,22 @@ const render::ItemIDs& Model::fetchRenderItemIDs() const {
}
void Model::initializeBlendshapes(const FBXMesh& mesh, int index) {
_blendshapeBuffers[index] = std::make_shared<gpu::Buffer>();
QVector<BlendshapeOffset> blendshapeOffset;
blendshapeOffset.fill(BlendshapeOffset(), 3 * mesh.vertices.size());
const auto blendshapeOffsetsSize = blendshapeOffset.size() * sizeof(BlendshapeOffset);
_blendshapeBuffers[index]->setData(blendshapeOffsetsSize, (const gpu::Byte*) blendshapeOffset.constData());
_blendshapeOffsets[index] = blendshapeOffset;
if (mesh.blendshapes.empty()) {
// mesh doesn't have blendshape, did we allocate one though ?
if (_blendshapeBuffers.find(index) != _blendshapeBuffers.end()) {
qWarning() << "Mesh does not have Blendshape yet a blendshapeOffset buffer is allocated ?";
}
return;
}
// Mesh has blendshape, let s allocate the local buffer if not done yet
if (_blendshapeBuffers.find(index) == _blendshapeBuffers.end()) {
_blendshapeBuffers[index] = std::make_shared<gpu::Buffer>();
QVector<BlendshapeOffset> blendshapeOffset;
blendshapeOffset.fill(BlendshapeOffset(), 3 * mesh.vertices.size());
const auto blendshapeOffsetsSize = blendshapeOffset.size() * sizeof(BlendshapeOffset);
_blendshapeBuffers[index]->setData(blendshapeOffsetsSize, (const gpu::Byte*) blendshapeOffset.constData());
_blendshapeOffsets[index] = blendshapeOffset;
}
}
void Model::createRenderItemSet() {
@ -1631,9 +1639,7 @@ void Model::createRenderItemSet() {
// Create the render payloads
int numParts = (int)mesh->getNumParts();
for (int partIndex = 0; partIndex < numParts; partIndex++) {
if (_blendshapeBuffers.find(i) == _blendshapeBuffers.end()) {
initializeBlendshapes(fbxGeometry.meshes[i], i);
}
initializeBlendshapes(fbxGeometry.meshes[i], i);
_modelMeshRenderItems << std::make_shared<ModelMeshPartPayload>(shared_from_this(), i, partIndex, shapeID, transform, offset);
auto material = getGeometry()->getShapeMaterial(shapeID);
_modelMeshMaterialNames.push_back(material ? material->getName() : "");

View file

@ -18,11 +18,8 @@
<@include graphics/MaterialTextures.slh@>
<$declareMaterialTexMapArrayBuffer()$>
<@include Skinning.slh@>
<$declareUseDualQuaternionSkinning()$>
<@include Blendshape.slh@>
<$declareApplyBlendshapeOffsets(1)$>
<@include MeshDeformer.slh@>
<$declareMeshDeformer(1, _SCRIBE_NULL, 1, 0, 1)$>
<@include render-utils/ShaderConstants.h@>
@ -35,11 +32,7 @@ layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color;
void main(void) {
vec4 deformedPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec3 deformedNormal = vec3(0.0, 0.0, 0.0);
applyBlendshapeOffset(gl_VertexID, inPosition, deformedPosition, inNormal.xyz, deformedNormal);
vec4 skinnedPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec3 skinnedNormal = vec3(0.0, 0.0, 0.0);
skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, deformedPosition, deformedNormal, skinnedPosition, skinnedNormal);
<$evalMeshDeformer(inPosition, deformedPosition, inNormal.xyz, deformedNormal, _SCRIBE_NULL, _SCRIBE_NULL, inSkinClusterIndex, inSkinClusterWeight, gl_VertexID);
// pass along the color
_color.rgb = color_sRGBToLinear(inColor.rgb);

View file

@ -18,11 +18,8 @@
<@include graphics/MaterialTextures.slh@>
<$declareMaterialTexMapArrayBuffer()$>
<@include Skinning.slh@>
<$declareUseDualQuaternionSkinning(1)$>
<@include Blendshape.slh@>
<$declareApplyBlendshapeOffsets(1)$>
<@include MeshDeformer.slh@>
<$declareMeshDeformer(1, _SCRIBE_NULL, 1, 1, 1)$>
<@include render-utils/ShaderConstants.h@>
@ -33,13 +30,10 @@ layout(location=RENDER_UTILS_ATTR_NORMAL_WS) out vec3 _normalWS;
layout(location=RENDER_UTILS_ATTR_COLOR) out vec4 _color;
void main(void) {
vec4 deformedPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec3 deformedNormal = vec3(0.0, 0.0, 0.0);
applyBlendshapeOffset(gl_VertexID, inPosition, deformedPosition, inNormal.xyz, deformedNormal);
vec4 skinnedPosition = vec4(0.0, 0.0, 0.0, 0.0);
vec3 skinnedNormal = vec3(0.0, 0.0, 0.0);
skinPositionNormal(inSkinClusterIndex, inSkinClusterWeight, deformedPosition, deformedNormal, skinnedPosition, skinnedNormal);
<$evalMeshDeformer(inPosition, deformedPosition, inNormal.xyz, deformedNormal, _SCRIBE_NULL, _SCRIBE_NULL, inSkinClusterIndex, inSkinClusterWeight, gl_VertexID);
// pass along the color
_color.rgb = color_sRGBToLinear(inColor.rgb);
@ -52,6 +46,6 @@ void main(void) {
// standard transform
TransformCamera cam = getTransformCamera();
TransformObject obj = getTransformObject();
<$transformModelToWorldAndEyeAndClipPos(cam, obj, skinnedPosition, _positionWS, _positionES, gl_Position)$>
<$transformModelToWorldDir(cam, obj, skinnedNormal, _normalWS.xyz)$>
<$transformModelToWorldAndEyeAndClipPos(cam, obj, deformedPosition, _positionWS, _positionES, gl_Position)$>
<$transformModelToWorldDir(cam, obj, deformedNormal, _normalWS.xyz)$>
}