Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void SMaterial::Use(glm::mat4 &m, std::vector<SLight*> &l)
- {
- //Use the material
- glUseProgram(programId);
- //Set the defaul uniforms,the material settings could request to dont do so
- if (matSettings->setDefaultAttributes)
- {
- rendMang->SetUniform(programId, "uModel", kMat4, glm::value_ptr(m), modelLocation);
- //Set lights
- int cLights = l.size();
- glUniform1i(rendMang->GetUniform(programId,"uCurLights"),cLights);
- for (unsigned int i = 0; i < l.size(); i++)
- {
- //Set color
- std::string lColName = "uLights[" + std::to_string(i) + "].lColor";
- rendMang->SetUniform(programId, lColName.c_str(), kFloat3, glm::value_ptr(l[i]->GetLightInfo().lCol),
- rendMang->GetUniform(programId, lColName.c_str()));
- //For sun light
- if (l[i]->GetLightInfo().lType == kSun)
- {
- //Set light direction
- std::string lDirName = "uLights[" + std::to_string(i) + "].lDir";
- rendMang->SetUniform(programId, lDirName.c_str(), kFloat3, glm::value_ptr(l[i]->GetLightInfo().lDir),
- rendMang->GetUniform(programId, lDirName.c_str()));
- //Set light matrix
- std::string lMatName = "uLights[" + std::to_string(i) + "].lMatrix";
- rendMang->SetUniform(programId, lMatName.c_str(), kMat4, glm::value_ptr(l[i]->GetLightMatrix()),
- rendMang->GetUniform(programId, lMatName.c_str()));
- //Set light shadow map
- std::string lShadowName = "uLights[" + std::to_string(i) + "].uShadowMaps";
- int lShadowLoc = rendMang->GetUniform(programId,lShadowName.c_str());
- //int lShadowLoc = rendMang->GetUniform(programId,"uShadowMaps");
- int lShadowId = l[i]->GetShadowMapId();
- rendMang->SetTexture(20+i,k2DTexture,lShadowId,lShadowLoc);
- }
- }
- }
- //Set the attributes of the material settings
- matSettings->SetLocations(programId);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement