void Shader::BindCamera(const std::shared_ptr<SceneNode> &camNode) { Vector4 camPos = camNode->GetWorldPosition(); if (auto camera = camNode->GetComponent<Camera>()) { BindFloat("camera_pos", camPos.x, camPos.y, camPos.z); BindFloat("camera_far", camera->GetFar()); BindFloat("camera_near", camera->GetNear()); BindMatrix(Matrix4::INVERT_VIEW_MATRIX, &camNode->GetInvertWorldMatrix().Raw[0]); BindMatrix(Matrix4::PROJECTION_MATRIX, &camera->GetProjectionMatrix().Raw[0]); } }
void PrelightPipeline::DrawRenderable(const std::shared_ptr<Pass> &pass, const std::shared_ptr<SceneNode> &node) { auto render = node->GetComponent<MeshRender>(); if (render == nullptr || !render->GetRenderable()) return; auto mesh = render->GetMesh(); auto material = render->GetMaterial(); auto shader = material->GetShaderForPass(pass->GetRenderIndex()); if (shader == nullptr) shader = pass->GetShader(material->GetShaderType()); if (shader == nullptr) { LOGW << "Failed to draw " << node->GetName() << ", data incomplete!"; return; } shader->Bind(); shader->BindCamera(m_CurrentCamera); shader->BindMatrix(Matrix4::WORLD_MATRIX, node->GetWorldMatrix()); shader->BindMesh(mesh); shader->BindMaterial(material); for (unsigned int i = 0; i < pass->GetTextureCount(true); i++) { auto ptr = pass->GetTextureAt(i, true); shader->BindTexture(ptr->GetName(), ptr); } glDrawElements(GL_TRIANGLES, mesh->Indices.Data.size(), GL_UNSIGNED_INT, 0); shader->UnBind(); m_DrawCall++; }
void Shader::BindMatrix(const std::string &name, const Matrix4 &matrix) { BindMatrix(name, &matrix.Raw[0]); }
/** Bind a value to a uniform floatNxM input-parameter of the fragmentprogram of this pass * The value of the input-parameter must be given as a float-array of length N*N. * The entries in the array must be given in row-major order (unless you set transpose=true) * * @param[in] parameterName the name of the input-parameter in the fragment program * @param[in] n columns * @param[in] m rows * @param[in] floatmatrix the array with the matrix values * @param[in] transpose (optional) wether the matrix is given in column-major order (the C++ way) * @exception PPEResourceException thrown if the matrix is not 2*2, 3*3 or 4*4 */ void FragmentProgram::BindMatrix(string parameterName, int n, int m, vector<float> floatmatrix, const bool transpose) { vector<vector<float> > floatmatrices; floatmatrices.push_back(floatmatrix); BindMatrix(parameterName, n, m, floatmatrices, transpose); }