本文整理汇总了C++中ShaderProgram::SetUniform方法的典型用法代码示例。如果您正苦于以下问题:C++ ShaderProgram::SetUniform方法的具体用法?C++ ShaderProgram::SetUniform怎么用?C++ ShaderProgram::SetUniform使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ShaderProgram
的用法示例。
在下文中一共展示了ShaderProgram::SetUniform方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Render
void SimpleRender::Render(ICamera* camera, const Vector4f& lightPosition) {
ShaderProgram* shader = isAo ? m_aoShader : m_simpleShader;
// bind shader of the batch.
shader->Bind();
m_vertexBuffer->EnableVertexAttribInterleavedWithBind();
shader->SetUniform("textureArray", 0);
Texture::SetActiveTextureUnit(0);
m_arrayTexture->Bind();
shader->SetUniform("aoOnly", 1.0f);
Matrix4f modelMatrix = Matrix4f::CreateIdentity(); //geoObj->GetModelMatrix();
shader->SetPhongUniforms(
modelMatrix
, camera, lightPosition);
for(size_t i = 0; i < m_chunks.size(); ++i) {
Chunk* chunk = m_chunks[i];
chunk->m_indexBuffer->Bind();
chunk->m_indexBuffer->DrawIndices(GL_TRIANGLES, (chunk->m_numTriangles)*3);
chunk->m_indexBuffer->Unbind();
}
m_vertexBuffer->DisableVertexAttribInterleavedWithBind();
m_arrayTexture->Unbind();
}
示例2: PreRender
void MeshRenderer::PreRender(const ShaderProgram& shader, const Material& material, const glm::mat4& parent) {
shader.SetUniform("model" , parent * owner->matrix);
shader.SetUniform("diffuseColor", material.diffuseColor);
shader.SetUniform("hasTexture" , material.hasTexture);
if (material.hasTexture)
material.texture->Bind(GL_TEXTURE0);
}
示例3: Flush
void Font::Flush(float deltaTime)
{
//flush all of the vertices to the GPU for drawing
if (!preRenderStage)
{
timer += deltaTime;
if (timer > 1.f / 60.f) //60fps text updating
{
timer = 0;
preRenderStage = true;
//clear out the memory to start rendering new ones
vertices = new vector<Vertex>();
indices = new vector<int>();
}
}
else
{
m->SetVertices(vertices, GL_STREAM_DRAW, true);
m->SetIndices(indices, GL_STREAM_DRAW, true);
m->FlushBuffers();
preRenderStage = false;
}
glEnable(GL_BLEND);
renderer->Ready();
ShaderProgram *prog = renderer->GetProgram();
prog->SetUniform("MVP", (void*)value_ptr(guiCam->Get()));
renderer->Render();
glDisable(GL_BLEND);
}
示例4: Draw
void Planet::Draw(ShaderProgram &shaderProgram, Camera *camera, Texture moonTexture)
{
// modelMatrix has to be set
// moonModelMatrices have to be set
shaderProgram.UseProgram();
shaderProgram.SetUniform("mvpMatrix", camera->GetMVP(modelMatrix));
modelData->Draw();
for(GLint i = 0; i < moonModelMatrices.size(); i++)
{
moonTexture.Bind(0);
shaderProgram.SetUniform("mvpMatrix", camera->GetMVP(moonModelMatrices[i]));
modelData->Draw();
}
shaderProgram.DisUseProgram();
}
示例5: Render
void GameObject::Render(Camera *camera)
{
if (!renderer)
return;
renderer->Ready();
ShaderProgram *program = renderer->GetProgram();
program->SetUniform("Model", value_ptr(modelMatrix));
mat4 VP = camera->Get();
program->SetUniform("VP", value_ptr(VP));
mat4 MVP = VP * GetModelMatrix();
program->SetUniform("MVP", value_ptr(MVP));
vec3 camPos = camera->GetPos();
program->SetUniform("cameraPosition", &camPos);
vec3 lightDir = normalize(camPos - pos);
program->SetUniform("lightDirection", &lightDir);
vec4 ambMatColor(1, 0, 0, 1);
program->SetUniform("ambientMaterialColor", &ambMatColor);
vec4 difMatColor(1, 0, 0, 1);
program->SetUniform("diffuseMaterialColor", &difMatColor);
vec4 specMatColor(1, 1, 1, 1);
program->SetUniform("specularMaterialColor", &specMatColor);
float power = 25;
program->SetUniform("specularPower", &power);
vec4 ambLightColor(1, 0, 0, 1);
program->SetUniform("ambientLightColor", &ambLightColor);
vec4 difLightColor(1, 0, 0, 1);
program->SetUniform("diffuseLightColor", &difLightColor);
vec4 specLightColor(1, 1, 1, 1);
program->SetUniform("specularLightColor", &specLightColor);
float heightScale = 5.0f;
program->SetUniform("heightScale", &heightScale);
for (auto it = components.begin(); it != components.end(); it++)
(*(it->second)).OnRender(camera);
renderer->Render();
}