Beispiel #1
0
void BlurGI(RenderTarget *rt) {
	blurRT->Bind();
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	blurYShader.Bind();
	blurYShader.SetUniform("resolution", (float)blurRT->Size(), (float)blurRT->Size());
	// テクスチャ描画
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, rt->Texture());
	blurYShader.SetUniform("texture", (int)0);
	DrawTexture(0, 0, 1, 1);
	blurYShader.Unbind();	


	rt->Bind();
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	blurXShader.Bind();
	blurXShader.SetUniform("resolution", (float)rt->Size(), (float)rt->Size());
	// テクスチャ描画
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, blurRT->Texture());
	blurXShader.SetUniform("texture", (int)0);
	DrawTexture(0, 0, 1, 1);
	
	blurXShader.Unbind();	

}
Beispiel #2
0
void World::Render()
{
	ResourceManager* resourceManager = ResourceManager::GetInstance();
	glm::mat4 depthProj = glm::ortho<float>(-5, 5, -5, 5, -100, 100);
	glm::mat4 depthView = glm::lookAt(mCamera->GetPosition() - glm::normalize(glm::vec3(1.0f, -3.0f, 2.0f)) * 10.0f, mCamera->GetPosition(), glm::vec3(0, 1, 0));

	Shader* depthShader = resourceManager->GetShader("depth");
	Shader* defaultShader = resourceManager->GetShader("default");

	//			Depth map rendering
	mFbo->Bind();
	depthShader->Bind();
	RenderObjects(depthShader, depthProj, depthView, false);
	mFbo->Unbind();

	//			World rendering
	defaultShader->Bind();
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, mFbo->textureID);
	glUniform1i(defaultShader->GetUniformLocation("shadowMap"), 1);

	GLuint depthMVPLocation = defaultShader->GetUniformLocation("depthMVP");
	glUniformMatrix4fv(depthMVPLocation, 1, GL_FALSE, &(depthProj * depthView)[0][0]);

	RenderObjects(defaultShader, mProjection, mCamera->GetView(), true);
}
void RenderingEngine::ApplyFilter(const Shader& filter, const Texture& source, const Texture* dest)
{
	assert(&source != dest);
	if(dest == 0)
	{
		m_window->BindAsRenderTarget();
	}
	else
	{
		dest->BindAsRenderTarget();
	}
	
	SetTexture("filterTexture", source);
	
	m_altCamera.SetProjection(Matrix4f().InitIdentity());
	m_altCamera.GetTransform()->SetPos(Vector3f(0,0,0));
	m_altCamera.GetTransform()->SetRot(Quaternion(Vector3f(0,1,0),ToRadians(180.0f)));
	
//	const Camera* temp = m_mainCamera;
//	m_mainCamera = m_altCamera;

	glClear(GL_DEPTH_BUFFER_BIT);
	filter.Bind();
	filter.UpdateUniforms(m_planeTransform, m_planeMaterial, *this, m_altCamera);
	m_plane.Draw();
	
//	m_mainCamera = temp;
	SetTexture("filterTexture", 0);
}
Beispiel #4
0
		void Renderer::Draw(const VertexArray& va, const IndexBuffer& ib, const Shader& shader) const
		{
			shader.Bind();
			ib.Bind();
			va.Bind();
			GLCall(glDrawElements(GL_TRIANGLES, ib.GetCount(), GL_UNSIGNED_INT, 0));
		}
Beispiel #5
0
int Render() {
	RenderVPL();
	RenderVPLPos();
	RenderVPLNormal();
	RenderGI();
	for (int i = 0; i < 6; i ++)
		BlurGI(giRT);

	RenderShadowmap();
	RenderObject();

	
	glViewport(0, 0, windowWidth, windowHeight);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	postShader.Bind();
	// テクスチャ描画
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, cameraRT->Texture());
	postShader.SetUniform("texture", (int)0);
	postShader.SetUniform("resolution", (float)windowWidth, (float)windowHeight);
	postShader.SetUniform("time", (float)SDL_GetTicks());
	DrawTexture(0, 0, 1, 1);
	postShader.Unbind();	

	SDL_GL_SwapBuffers();
	return 0;
}
Beispiel #6
0
void RenderGI() {
	giRT->Bind();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_DEPTH_TEST);

	giShader.Bind();

	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, vplRT->Texture());
	giShader.SetUniform("vplTexture", (int)1);
	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, vplPosRT->Texture());
	giShader.SetUniform("vplPosTexture", (int)2);
	glActiveTexture(GL_TEXTURE3);
	glBindTexture(GL_TEXTURE_2D, vplNormalRT->Texture());
	giShader.SetUniform("vplNormalTexture", (int)3);

	SetMatrix(giShader);
	DrawObjects(giShader);

	giShader.Unbind();
}
Beispiel #7
0
Game::Game(Display* display)
{
	int height = GetSystemMetrics(SM_CYSCREEN);
	int width = GetSystemMetrics(SM_CXSCREEN);
	float borderwidth = (((150.0f / (float)height) * (float)width) - 120) / 2;

	this->display = display;
	Shader* shader = new Shader("./res/basicShader");
	shader->Bind();
	Camera* camera = new Camera(glm::vec3(0, 0, -3), 70.0f, (float)width / (float)height, 0.01f, 1000.0f);

	gameData = new GameData(shader, &controller, camera, new RandomNumber());

	display->Clear(0, 0, 0, 0);
	
	Texture loadingScreenTex("./res/loadingscreen.png");
	loadingScreen = new GameObject((int)((150.0f / (float)height) * (float)width), 150, GameData::LOADINGSCREEN, gameData);
	loadingScreen->Update(0.01f, 0.01f);
	loadingScreen->Draw();

	display->Update();

	gameData->LoadTextures();


	overlay = new GameObject(120, 142, GameData::OVERLAY, gameData);
	overlay->SetTexScrollSpeed(glm::vec2(0.0, -0.5));

	glow = new GameObject(120, 142, GameData::GLOW, gameData);
	glow->SetTexScrollSpeed(glm::vec2(0.0, -0.6));

	background = new GameObject(120, 142, GameData::BACKGROUND, gameData);
	background->SetTexScrollSpeed(glm::vec2(0.0, -0.2));

	border_left = new GameObject(67, 142, GameData::BORDER_L, gameData);
	border_left->SetPosition(glm::vec3(1.865, 0, 0));

	border_right = new GameObject(67, 142, GameData::BORDER_R, gameData);
	border_right->SetPosition(glm::vec3(-1.865, 0, 0));

	timer = new Timer();

	player = new Player(7, 7, GameData::PLAYER, gameData, true);
	player->SetHitbox(0.05f);

	hud = new HUD(gameData, player);

	enemyHandler = new Enemies(gameData, player);
	menu = new Menu(gameData);

	state = GameState::MENU;

}
Beispiel #8
0
void loop()
{
	//base.Bind();
	
	phong.Bind();
	phong.SetAmbience(vec3(0.1, 0.1, 0.1));
	trans.GetRot().y = 180;
	while (!window.IsCloseRequested()){
		update();
		render();
	}
}
Beispiel #9
0
void RenderVPLNormal() {
	vplNormalRT->Bind();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_DEPTH_TEST);
	vpl_normalShader.Bind();

	SetMatrix(vpl_normalShader);
	DrawObjects(vpl_normalShader);

	vpl_normalShader.Unbind();
}
Beispiel #10
0
void RenderShadowmap() {
	lightRT->Bind();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_DEPTH_TEST);

	lightShader.Bind();

	SetMatrix(lightShader);
	 DrawObjects(lightShader);

	lightShader.Unbind();
}
Beispiel #11
0
void RenderVPL() {
	vplRT->Bind();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_DEPTH_TEST);

	vplShader.Bind();

	vplShader.SetUniform("uLightIntensity", lightIntensity[0], lightIntensity[1], lightIntensity[2], lightIntensity[3]);

	SetMatrix(vplShader);
	DrawObjects(vplShader);

	vplShader.Unbind();
}
Beispiel #12
0
void RenderObject() {
	cameraRT->Bind();

	glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glEnable(GL_DEPTH_TEST);

	shader.Bind();
	shader.SetUniform("resolution", (float)cameraRT->Size(),  (float)cameraRT->Size());
	shader.SetUniform("uAmbient", ambient[0], ambient[1], ambient[2], ambient[3]);
	shader.SetUniform("uLightIntensity", lightIntensity[0], lightIntensity[1], lightIntensity[2], lightIntensity[3]);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, lightRT->Texture());
	shader.SetUniform("shadowMap", (int)0);

	
	glActiveTexture(GL_TEXTURE1);
	glBindTexture(GL_TEXTURE_2D, giRT->Texture());
	shader.SetUniform("giTexture", (int)1);


	SetMatrix(shader);
	DrawObjects(shader);

	shader.Unbind();

	// テクスチャ描画
	const float aspect = (float)windowWidth / windowHeight;
	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_2D, lightRT->Texture());
	DrawTexture(0.9f, -0.8f, 0.1f, 0.1f * aspect);
	
	glBindTexture(GL_TEXTURE_2D, vplRT->Texture());
	DrawTexture(0.6f, -0.8f, 0.1f, 0.1f * aspect);
	
	glBindTexture(GL_TEXTURE_2D, vplPosRT->Texture());
	DrawTexture(0.3f, -0.8f, 0.1f, 0.1f * aspect);
	
	glBindTexture(GL_TEXTURE_2D, vplNormalRT->Texture());
	DrawTexture(0.0f, -0.8f, 0.1f, 0.1f * aspect);
	
	glBindTexture(GL_TEXTURE_2D, giRT->Texture());
	DrawTexture(-0.3f, -0.8f, 0.1f, 0.1f * aspect);
}
Beispiel #13
0
int main(){
	try{
		ILogger::Init();
		Settings::Call().Parse();
		ResourceManager::Call().AddPath("Data/shaders", "Shader");
		ResourceManager::Call().AddPath("Data/textures", "Image");

		{
			Window myWindow;
			Image Crate;
			Texture CrateTexture;
			Text FPSText, MousePosText;
			Clock FrameClock, FpsClock;
		
			Input myInput;
			myInput.Init(myWindow);

			Renderer& myRenderer = Renderer::Call();
			myRenderer.Init(myWindow);
		
			Crate.LoadFromFile("crate.jpg");
			CrateTexture.LoadFromImage(Crate);

			Light l;
			l.SetPosition(Vector3F(1,3,1.5));
			l.SetDiffuse(Color(1.f,1.f,1.f));
			l.SetRange(8);

			Shader ColorShader;
			ColorShader.Compile("shaderColor.vs", "shaderColor.fs");
			ColorShader.Bind();
			ColorShader.SendColor("ambientColor", myRenderer.GetSpecifications().mAmbientColor);
			ColorShader.SendFloat("constantAtt", l.GetAttenuationConstant());
			ColorShader.SendFloat("linearAtt", l.GetAttenuationLinear());
			ColorShader.SendFloat("quadraticAtt", l.GetAttenuationQuadratic());
			ColorShader.SendFloat("range", l.GetRange());
	
			ColorShader.SendVector3("lightPosition", l.GetPosition());
			ColorShader.SendColor("lightColor", l.GetDiffuse());
			ColorShader.UnBind();

			Object obj1;
			obj1.MakeCube("cube", ColorShader);
			obj1.GetMaterial().mAmbient = Color(0.f, 0.08f, 0.08f);
			obj1.GetMaterial().mDiffuse = Color(0.f, 0.8f, 0.8f);
			obj1.GetMaterial().mSpecular = Color(0.0f, 0.5f, 0.5f);
			obj1.GetMaterial().mShininess = 50.f;

			Camera cam;
			cam.LookAt(Vector3F(0.5f,0,1), Vector3F(-2.5f,2,4));
		
			FPSText.SetSize(12);
			FPSText.SetPosition(10,10);
			MousePosText.SetSize(12);
			MousePosText.SetPosition(10,22);

			while(myWindow.IsOpened()){
				ElapsedTime = FrameClock.GetElapsedTime();
				FrameClock.Reset();

				if(FpsClock.GetElapsedTime() > 1.f){
					FPSText.SetText(String(1.f/ElapsedTime));
					FpsClock.Reset();
				}

			
				while(myInput.GetEvent()){
					if(myInput.GetEventType() == sf::Event::Closed)
						myWindow.Close();

					if(myInput.IsKeyHit(Space))
						if(!paused){
							paused = true;
							FrameClock.Pause();
						}else{
							paused = false;
							FrameClock.Resume();
						}
				}

				MousePosText.SetText(String("X : ")+myInput.GetMouseX()+" Y : "+myInput.GetMouseY());
			
				MousePosText.Draw();
				FPSText.Draw();
				obj1.Draw();

				myRenderer.BeginScene(myRenderer.GetSpecifications().mAmbientColor);
					myRenderer.Render();
				myRenderer.EndScene();
			}
		}
	}catch(Exception e){
		std::cout << e.what() << std::endl;
		system("PAUSE");
	}

	Renderer::Kill();
	ResourceManager::Kill();
	Settings::Kill();
	ILogger::Kill();
	#ifdef _DEBUG
		MemoryManager::Kill();
	#endif

    return 0;
}
Beispiel #14
0
void display_handler(void) {
    // clear scene
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glColor3f(1,1,1);
	shader.Bind();

	// pass uniform variables to shader
	GLint projectionMatrix_location    = glGetUniformLocation(shader.ID(), "projectionMatrix");
	GLint viewMatrix_location          = glGetUniformLocation(shader.ID(), "viewMatrix");
	GLint modelMatrix_location         = glGetUniformLocation(shader.ID(), "modelMatrix");
	GLint normalMatrix_location        = glGetUniformLocation(shader.ID(), "normalMatrix");
	GLint materialAmbient_location     = glGetUniformLocation(shader.ID(), "materialAmbient");
	GLint materialDiffuse_location     = glGetUniformLocation(shader.ID(), "materialDiffuse");
	GLint materialSpecular_location    = glGetUniformLocation(shader.ID(), "materialSpecular");
	GLint lightPosition_location       = glGetUniformLocation(shader.ID(), "lightPosition");
	GLint lightAmbient_location        = glGetUniformLocation(shader.ID(), "lightAmbient");
	GLint lightDiffuse_location        = glGetUniformLocation(shader.ID(), "lightDiffuse");
	GLint lightSpecular_location       = glGetUniformLocation(shader.ID(), "lightSpecular");
	GLint lightGlobal_location         = glGetUniformLocation(shader.ID(), "lightGlobal");
	GLint materialShininess_location   = glGetUniformLocation(shader.ID(), "materialShininess");
	GLint constantAttenuation_location = glGetUniformLocation(shader.ID(), "constantAttenuation");
	GLint linearAttenuation_location   = glGetUniformLocation(shader.ID(), "linearAttenuation");
	GLint useTexture_location          = glGetUniformLocation(shader.ID(), "useTexture");
	glUniformMatrix4fv( projectionMatrix_location, 1, GL_FALSE, &projectionMatrix[0][0]);
	glUniformMatrix4fv( viewMatrix_location,       1, GL_FALSE, &viewMatrix[0][0]);
	glUniformMatrix4fv( modelMatrix_location,      1, GL_FALSE, &modelMatrix[0][0]);
	glUniformMatrix3fv( normalMatrix_location,     1, GL_FALSE, &normalMatrix[0][0]);
    glUniform3fv(       materialAmbient_location,  1, materialAmbient);
    glUniform3fv(       materialDiffuse_location,  1, materialDiffuse);
    glUniform3fv(       materialSpecular_location, 1, materialSpecular);
    glUniform3fv(       lightPosition_location,    1, lightPosition);
    glUniform3fv(       lightAmbient_location,     1, lightAmbient);
    glUniform3fv(       lightDiffuse_location,     1, lightDiffuse);
    glUniform3fv(       lightSpecular_location,    1, lightSpecular);
    glUniform3fv(       lightGlobal_location,      1, lightGlobal);
    glUniform1f(        materialShininess_location,   materialShininess);
    glUniform1f(        constantAttenuation_location, constantAttenuation);
    glUniform1f(        linearAttenuation_location,   linearAttenuation);
    glUniform1i(        useTexture_location,          useTexture);

    // bind texture to shader
    GLint texture0_location = glGetAttribLocation(shader.ID(), "texture0");
    if (texture0_location != -1) {
        glActiveTexture(GL_TEXTURE0);
        glBindTexture(GL_TEXTURE_2D, textureID);
        glUniform1i(texture0_location, 0);
    }
    // bind vertex uv coordinates to shader
	GLint uv_location = glGetAttribLocation(shader.ID(), "vertex_uv");
	if (uv_location != -1) {
        glEnableVertexAttribArray(uv_location);
        glBindBuffer(GL_ARRAY_BUFFER, vertex_uv_buffer);
        glVertexAttribPointer(uv_location, 2, GL_FLOAT, GL_FALSE, 0, 0);
    }
    // bind vertex positions to shader
	GLint position_location = glGetAttribLocation(shader.ID(), "vertex_position");
	if (position_location != -1) {
        glEnableVertexAttribArray(position_location);
        glBindBuffer(GL_ARRAY_BUFFER, vertex_position_buffer);
        glVertexAttribPointer(position_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
    }
    // bind vertex normals to shader
	GLint normal_location = glGetAttribLocation(shader.ID(), "vertex_normal");
	if (normal_location != -1) {
        glEnableVertexAttribArray(normal_location);
        glBindBuffer(GL_ARRAY_BUFFER, vertex_normal_buffer);
        glVertexAttribPointer(normal_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
    }

    // draw the scene
	glDrawArrays(GL_TRIANGLES, 0, trig.VertexCount());
	glDisableVertexAttribArray(position_location);
	glDisableVertexAttribArray(uv_location);
	glDisableVertexAttribArray(normal_location);
	shader.Unbind();
	glFlush();
}