50 SkinningShader::SkinningShader(
Renderer* renderer): mutex(
"skinningshader-mutex")
76 "shader/" + shaderVersion +
"/skinning",
109 auto& skinningContext =
contexts[contextIdx];
110 if (skinningContext.running ==
false) {
111 skinningContext.running =
true;
121 auto node = objectNodeMesh->
node;
123 auto id = node->getModel()->getId() +
"." + node->getId();
125 auto cacheIt =
cache.find(
id);
126 if (cacheIt ==
cache.end()) {
129 auto created =
false;
130 auto skinning = node->getSkinning();
131 const auto& verticesJointsWeights = skinning->getVerticesJointsWeights();
132 const auto& weights = skinning->getWeights();
137 modelSkinningCache.
vboIds = vboManaged->getVBOIds();
142 auto vboManaged =
Engine::getVBOManager()->
addVBO(
"skinning_compute_shader." +
id +
".vbos.matrices." + to_string(i), 1,
false,
false, created);
143 modelSkinningCache.
matricesVboIds.push_back(vboManaged->getVBOIds());
147 modelSkinningCache.
matricesVboIds.push_back(vboManaged->getVBOIds());
163 auto ibVerticesJoints = ObjectBuffer::getByteBuffer(contextIdx, vertices.size() * 1 *
sizeof(
int))->asIntBuffer();
164 for (
auto nodeVertexIndex = 0; nodeVertexIndex < vertices.size(); nodeVertexIndex++) {
165 auto vertexJoints = verticesJointsWeights[nodeVertexIndex].size();
167 ibVerticesJoints.put((
int)vertexJoints);
174 auto ibVerticesVertexJointsIdxs = ObjectBuffer::getByteBuffer(contextIdx, vertices.size() * 4 *
sizeof(
float))->asIntBuffer();
175 for (
auto nodeVertexIndex = 0; nodeVertexIndex < vertices.size(); nodeVertexIndex++) {
176 const auto& vertexJointsWeight = verticesJointsWeights[nodeVertexIndex];
178 for (
auto i = 0; i < 4; i++) {
179 auto jointIndex = i < vertexJointsWeight.size()?vertexJointsWeight[i].getJointIndex():-1;
180 ibVerticesVertexJointsIdxs.put((
int)jointIndex);
188 auto fbVerticesVertexJointsWeights = ObjectBuffer::getByteBuffer(contextIdx, vertices.size() * 4 *
sizeof(
float))->asFloatBuffer();
189 for (
auto nodeVertexIndex = 0; nodeVertexIndex < vertices.size(); nodeVertexIndex++) {
190 const auto& vertexJointsWeight = verticesJointsWeights[nodeVertexIndex];
192 for (
auto i = 0; i < 4; i++) {
193 fbVerticesVertexJointsWeights.put(
static_cast<float>(i < vertexJointsWeight.size()?weights[vertexJointsWeight[i].getWeightIndex()]:0.0f));
200 cache[id] = modelSkinningCache;
201 modelSkinningCacheCached = &
cache[id];
203 modelSkinningCacheCached = &cacheIt->second;
222 auto skinning = node->getSkinning();
223 const auto& skinningJoints = skinning->getJoints();
224 auto fbMatrices = ObjectBuffer::getByteBuffer(contextIdx, objectBase->
instances * skinningJoints.size() * 16 *
sizeof(
float))->asFloatBuffer();
225 for (
auto i = 0; i < objectBase->
instances; i++) {
229 if (jointSkinningMatrix !=
nullptr) {
251 (
int)Math::ceil(vertices.size() / 16.0f),
252 (
int)Math::ceil(objectBase->
instances / 16.0f),
261 for (
auto& skinningContext:
contexts) skinningContext.running =
false;
267 for (
const auto& [cacheId, cacheEntry]:
cache) {
static VBOManager * getVBOManager()
static int getThreadCount()
Representation of a 3D model.
const vector< Vector3 > & getVertices() const
Skinning definition for nodes.
VBOManager_VBOManaged * addVBO(const string &vboId, int32_t ids, bool useGPUMemory, bool shared, bool &created)
Adds a VBO to manager or retrieve VBO if existing.
void removeVBO(const string &vboId)
Removes a VBO from manager.
virtual int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string())=0
Loads a shader.
virtual void memoryBarrier()=0
Memory barrier.
virtual void bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning vertex joint indices buffer object.
virtual bool isSupportingMultithreadedRendering()=0
int32_t SHADER_COMPUTE_SHADER
int32_t UNIFORM_CL_SKINNING_MATRIX_COUNT
virtual int32_t createProgram(int type)=0
Creates a shader program.
int32_t UNIFORM_CL_SKINNING_VERTEX_COUNT
virtual void bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning matrices result buffer object.
int32_t UNIFORM_CL_SKINNING_INSTANCE_COUNT
virtual void bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning vertices result buffer object.
virtual void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual bool linkProgram(int32_t programId)=0
Links attached shaders to a program.
virtual void bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning normal buffer object.
void setLighting(int contextIdx, int32_t lighting)
Set current lighting model.
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
virtual void bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning normals result buffer object.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
virtual void bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning vertex joints buffer object.
virtual void bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning vertices buffer object.
virtual void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data)=0
Upload skinning buffer object.
virtual void dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ)=0
Dispatch compute.
virtual void bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId)=0
Bind skinning vertex joint weights buffer object.
virtual void useProgram(int contextIdx, int32_t programId)=0
Use shader program.
virtual bool isGLCLAvailable()=0
virtual const string getShaderVersion()=0
vector< bool > instanceEnabled
void setCurrentInstance(int currentInstance)
Set current instance.
const Matrix4x4 & getTransformMatrix() const
Buffers used to transfer data between main memory to graphics board memory.
Object node mesh specifically for rendering.
void setupNormalsBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up normals buffer.
void setupVerticesBuffer(Renderer *renderer, int contextIdx, int32_t vboId)
Set up vertices buffer.
vector< vector< Matrix4x4 * > > jointsSkinningMatrices
ObjectNodeRenderer * objectNodeRenderer
Object node VBO renderer.
vector< int32_t > * vboBaseIds
Interface to compute shader skinning shader program.
void initialize()
Initialize renderer.
int32_t uniformInstanceCount
void computeSkinning(int contextIdx, ObjectBase *objectBase, ObjectNodeMesh *objectNodeMesh)
Compute skinning.
int32_t uniformVertexCount
int32_t uniformMatrixCount
map< string, ModelSkinningCache > cache
void useProgram()
Use skinning program.
void unUseProgram()
Unuse skinning program.
vector< SkinningContext > contexts
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Matrix4x4 & set(float r0c0, float r0c1, float r0c2, float r0c3, float r1c0, float r1c1, float r1c2, float r1c3, float r2c0, float r2c1, float r2c2, float r2c3, float r3c0, float r3c1, float r3c2, float r3c3)
Sets this matrix by its components.
const array< float, 16 > & getArray() const
const array< float, 3 > & getArray() const
void unlock()
Unlocks this mutex.
void lock()
Locks the mutex, additionally mutex locks will block until other locks have been unlocked.
vector< int32_t > * vboIds
vector< vector< int32_t > * > matricesVboIds