当前位置: 首页>>代码示例>>C++>>正文


C++ Shader::GetVariable方法代码示例

本文整理汇总了C++中Shader::GetVariable方法的典型用法代码示例。如果您正苦于以下问题:C++ Shader::GetVariable方法的具体用法?C++ Shader::GetVariable怎么用?C++ Shader::GetVariable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Shader的用法示例。


在下文中一共展示了Shader::GetVariable方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: Render

void Scene::Render()
{
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//draw mesh
	glBindFramebuffer(GL_FRAMEBUFFER,_fbos[0]);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	Shader * curShader = shaders[0];
	curShader->TurnOn();
	initUniformVal(curShader);
	glm::mat4 model;
	// Floor cube
	model = glm::translate(model, glm::vec3(0.0, -1.0f, 0.0f));
	model = glm::scale(model, glm::vec3(20.0f, 1.0f, 20.0f));
	int modelId = curShader->GetVariable("model");
	curShader->SetMatrix4(modelId,1,false,glm::value_ptr(model));
	drawCub(cub);

	model = glm::mat4();
	model = glm::translate(model, glm::vec3(0.0f, 0.0f, 5.0));
	model = glm::rotate(model, -90.0f, glm::vec3(1.0, 0.0, 0.0));
	model = glm::scale(model, glm::vec3(0.5f));
	modelId = curShader->GetVariable("model");
	curShader->SetMatrix4(modelId,1,false,glm::value_ptr(model));
	_modes[0]->drawNode(curShader);

	curShader->TurnOff();
	glBindFramebuffer(GL_FRAMEBUFFER,0);

	//ssao shader
	glBindFramebuffer(GL_FRAMEBUFFER,_fbos[1]);
	glClear(GL_COLOR_BUFFER_BIT);
	curShader = shaders[1];
	curShader->TurnOn();
	initUniformVal(curShader);

	GLint location;
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,_textures[0]);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D,_textures[1]);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D,noiseTexture);
	for (GLuint i = 0; i < 64; ++i)
		glUniform3fv(glGetUniformLocation(curShader->getShaderId(), ("samples[" + std::to_string((long long)(i)) + "]").c_str()), 1, &ssaoKernel[i][0]);

	drawScreenQuad(screenQuatID);

	curShader->TurnOff();
	glBindFramebuffer(GL_FRAMEBUFFER,0);
	
	if(useBlur)
	{
		//Blur SSAO 
		glBindFramebuffer(GL_FRAMEBUFFER,_fbos[2]);
		glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
		curShader = shaders[2];
		curShader->TurnOn();
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D,_textures[3]);
		drawScreenQuad(screenQuatID);
		curShader->TurnOff();
		glBindFramebuffer(GL_FRAMEBUFFER,0);
	}
	
 
	//light 
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	curShader = shaders[3];
	curShader->TurnOn();

	location = shaders[3]->GetVariable("draw_mode");
	shaders[3]->SetInt(location,draw_mode);
	location = shaders[3]->GetVariable("gPositionDepth");
	shaders[3]->SetInt(location,0);
	location = shaders[3]->GetVariable("gNormal");
	shaders[3]->SetInt(location,1);
	location = shaders[3]->GetVariable("gAlbedo");
	shaders[3]->SetInt(location,2);
	location = shaders[3]->GetVariable("ssao");
	shaders[3]->SetInt(location,3);
	location = shaders[3]->GetVariable("light.Position");
	glm::vec3 lightPosView = glm::vec3(camera->GetViewMatrix() * glm::vec4(lightPos, 1.0));
	shaders[3]->SetFloat3V(location,1,glm::value_ptr(lightPosView));
	location = shaders[3]->GetVariable("light.Color");
	shaders[3]->SetFloat3V(location,1,glm::value_ptr(lightColor));
	location = shaders[3]->GetVariable("light.Linear");
	shaders[3]->SetFloat(location,0.09);
	location = shaders[3]->GetVariable("light.Quadratic");
	shaders[3]->SetFloat(location,0.032);
	location = shaders[3]->GetVariable("useSSAO");
	shaders[3]->SetInt(location,useSSAO);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D,_textures[0]);
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D,_textures[1]);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D,_textures[2]);
	glActiveTexture(GL_TEXTURE3);
//.........这里部分代码省略.........
开发者ID:xtmacbook,项目名称:OpenGL,代码行数:101,代码来源:Scene.cpp


注:本文中的Shader::GetVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。