Exemple #1
0
void Renderer::RenderScene()	{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer
	glUseProgram(currentShader->GetProgram());				//Switch on our shader


	//First off, some familiar code to simply draw our boxes scene graph
	viewMatrix  = camera->BuildViewMatrix();
	projMatrix	= Matrix4::Perspective(1.0f,15000.0f,(float)width/(float)height,45.0f);
	UpdateShaderMatrices();

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);	//New! and to move...
	DrawNode(root);

	//We also set their colours to white - in the following code we set boxes under our mouse
	//to blue, so they'll be drawn blue in the 'next' frame, and then reset by this code.
	for(vector<SceneNode*>::const_iterator i = root->GetChildIteratorStart(); i != root->GetChildIteratorEnd(); ++i) {
		(*i)->SetColour(Vector4(1,1,1,1));
	}
	//If the left mouse button is held down, we're going to do some picking!
	if(Window::GetMouse()->ButtonHeld(MOUSE_LEFT))	{
		//We start by getting a normalised direction vector from the camera and mouse...
		Vector3 dir = GetMouseDirectionVector3((float)width/(float)height,45.0f, *camera);

		//And then forming a ray out of it, starting at the camera's position
		Ray r = Ray(camera->GetPosition(),dir);

		//Now we're going to test our ray against our node hierarchy
		r.IntersectsNodes(*root);

		//If it has collided against any nodes, set them to blue
		for(unsigned int i = 0; i < r.collisions.size(); ++i ) {
			r.collisions.at(i).node->SetColour(Vector4(0,0,1,1));
		}

		//In case you didn't quite know how, here's how to draw a textured 'mouse
		//pointer' in OpenGL. We go to an orthographic perspective, with a range 
		//of 0-width on the x-axis, and 0-height on the y axis. Then we draw
		//a shape at the mouse position. See how we still use the near plane of
		//-1, so that a mouse pointer drawn at a z of 0 will definitely show up!

		Vector2 mpos = Window::GetMouse()->GetAbsolutePosition();
		viewMatrix.ToIdentity();
		projMatrix	= Matrix4::Orthographic(-1.0f,1.0f,(float)width,0.0f,(float)height,0.0f);
		modelMatrix = Matrix4::Translation(Vector3(mpos.x,height - mpos.y,0)) * 
			Matrix4::Scale(Vector3(25,25,25));

		UpdateShaderMatrices();

		triangle->Draw();
	}
	//That's everything!
	glUseProgram(0);
	SwapBuffers();	
}
Exemple #2
0
void Renderer :: RenderScene () {

	glClear ( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT );

	if( usingScissor ) {
		glEnable ( GL_SCISSOR_TEST );
		glScissor (( float ) width / 2.5f , ( float ) height / 2.5f ,( float ) width / 5.0f , ( float ) height / 5.0f );
	}
	glUseProgram ( currentShader -> GetProgram ());
	UpdateShaderMatrices ();

	glUniform1i ( glGetUniformLocation ( currentShader -> GetProgram () ,"diffuseTex") , 0);

	if( usingStencil ) {
		glEnable ( GL_STENCIL_TEST );

		glColorMask ( GL_FALSE , GL_FALSE , GL_FALSE , GL_FALSE );
		glStencilFunc ( GL_ALWAYS , 2 , ~0);
		glStencilOp ( GL_REPLACE , GL_REPLACE , GL_REPLACE );

		quad -> Draw ();

		glColorMask ( GL_TRUE , GL_TRUE , GL_TRUE , GL_TRUE );
		glStencilFunc ( GL_EQUAL , 2 , ~0);
		glStencilOp ( GL_KEEP , GL_KEEP , GL_KEEP );
	}

	triangle -> Draw ();

	glUseProgram (0);
	glDisable ( GL_SCISSOR_TEST );
	glDisable ( GL_STENCIL_TEST );

	SwapBuffers ();
}
void Renderer::DrawWater()
{
	SetCurrentShader(reflectShader);
	SetShaderLight(*light);
	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, (float*)&camera->GetPosition());

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "cubeTex"), 2);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMap);

	float heightX = (RAW_WIDTH * HEIGHTMAP_X / 2.0f);

	float heightY = 256 * HEIGHTMAP_Y / 3.0f;

	float heightZ = (RAW_HEIGHT * HEIGHTMAP_Z /2.0f);

	modelMatrix =
		Matrix4::Translation(Vector3(heightX, heightY, heightZ)) * 
		Matrix4::Scale(Vector3(heightX, 1, heightZ)) *
		Matrix4::Rotation(90, Vector3(1.0f, 0.0f, 0.0f));

	textureMatrix = Matrix4::Scale(Vector3(10.0f,10.0f,10.0f)) *
				Matrix4::Rotation(waterRotate, Vector3(0.0f, 0.0f, 1.0f));

	UpdateShaderMatrices();
	
	quad->Draw();

	glUseProgram(0);
}
//Performs a fog effect based upon a linearized depth buffer
void Renderer::Fog(){
	//Bind our processing FBO and attach the next buffer to be drawn to to it
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
		GL_TEXTURE_2D, GetDrawTarget(), 0);

	//Clear it
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	SetCurrentShader(fogShader);
	glUniform2f(glGetUniformLocation(currentShader->GetProgram(), "pixelSize"),
		1.0f / width, 1.0f / height);
	UpdateShaderMatrices();

	glUniform1f(glGetUniformLocation(currentShader->GetProgram(),
		"threshold"), 0.2f);

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(),
		"depthTex"), 2);

	glUniform1f(glGetUniformLocation(currentShader->GetProgram(),
		"nearPlane"), 1.0);

	glUniform1f(glGetUniformLocation(currentShader->GetProgram(),
		"farPlane"), 15000.0f);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, bufferDepthTex);

	quad->SetTexture(GetLastDrawn());

	quad->Draw();
	PPDrawn();
}
//Presents which ever scene was the last to be drawn to to the back buffer
void Renderer::PresentScene(){
	//We draw the final result to the default framebuffer (the back buffer)
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	//We must render the final texture orthographically in front of the screen
	SetCurrentShader(passThrough);
	projMatrix = Matrix4::Orthographic(-1,1,1,-1,-1,1);
	viewMatrix.ToIdentity();
	modelMatrix.ToIdentity();
	UpdateShaderMatrices();

	//The results of post processing is held in bufferColourTex[0]
	if (Window::GetKeyboard()->KeyDown(KEYBOARD_NUMPAD4)){
		quad->SetTexture(lightEmissiveTex);
	} else if (Window::GetKeyboard()->KeyDown(KEYBOARD_NUMPAD5)) {
		quad->SetTexture(lightSpecularTex);
	} else if (Window::GetKeyboard()->KeyDown(KEYBOARD_NUMPAD6)) {
		quad->SetTexture(bufferNormalTex);
	} else {
		quad->SetTexture(GetLastDrawn());

	}

	quad->Draw();

	glUseProgram(0);

}
void Scene::DrawCominedScene()
{
	SetCurrentShader(SceneShader);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "bumpTex"), 1);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "shadowTex1"), 2);
	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, (float*)&m_Camera->GetPosition());

	SetShaderLightList(lightList);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, shadowTex);
	//glActiveTexture(GL_TEXTURE3);
	//glBindTexture(GL_TEXTURE_2D, shadowTexs[0]);
	projMatrix = Matrix4::Perspective(1.0f, 1000.0f, (float)width / (float)height, 45.0f);
	viewMatrix = m_Camera->BuildViewMatrix();
	/*Vector3 translate = Vector3((lightList.at(0)).GetPosition());
	translate += Vector3(0, 90, 0);
	viewMatrix = Matrix4::BuildViewMatrix((lightList.at(0)).GetPosition(), translate);*/

	UpdateShaderMatrices();

	//draw the object
	DrawNodes(true);

	glUseProgram(0);
}
void	Renderer::RenderScene()	{
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);
	
	if(camera) {
		SetCurrentShader(simpleShader);
		glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

		textureMatrix.ToIdentity();
		modelMatrix.ToIdentity();
		viewMatrix		= camera->BuildViewMatrix();
		projMatrix		= Matrix4::Perspective(1.0f,10000.0f,(float)width / (float) height, 60.0f);
		frameFrustum.FromMatrix(projMatrix * viewMatrix);
		UpdateShaderMatrices();

		//Return to default 'usable' state every frame!
		glEnable(GL_DEPTH_TEST);
		glEnable(GL_CULL_FACE);
		glDisable(GL_STENCIL_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		BuildNodeLists(root); 
		SortNodeLists();
		DrawNodes();
		ClearNodeLists();
	}

	glUseProgram(0);
	SwapBuffers();
}
void Renderer::DrawPostProcess() {
	glBindFramebuffer(GL_FRAMEBUFFER, processFBO);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bufferColourTex[1], 0);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	SetCurrentShader(combineShader);
	projMatrix = Matrix4::Orthographic(-1, 1, 1, -1, -1, 1);
	viewMatrix.ToIdentity();
	UpdateShaderMatrices();

	glDisable(GL_DEPTH_TEST);
	glUniform2f(glGetUniformLocation(currentShader->GetProgram(), "pixelSize"), 1.0f / width, 1.0f / height);

	for (int i = 0; i < POST_PASSES; ++i) {
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bufferColourTex[1], 0);
		glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "isVertical"), 0);

		quad->SetTexture(bufferColourTex[0]);
		quad->Draw();

		// swap buffers, second blur pass
		glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "isVertical"), 1);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, bufferColourTex[0], 0);

		quad->SetTexture(bufferColourTex[1]);
		quad->Draw();
	}

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glUseProgram(0);

	glEnable(GL_DEPTH_TEST);
}
Exemple #9
0
void Renderer :: RenderScene () {
	glClear ( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
	glUseProgram ( currentShader -> GetProgram ());
	UpdateShaderMatrices ();
	glUniform1i ( glGetUniformLocation ( currentShader -> GetProgram (),"diffuseTex"), 1);
	DrawNode (root);
	glUseProgram(0);
	SwapBuffers();
}
void Renderer::PresentScene() {
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);
	SetCurrentShader(sceneShader);
	projMatrix = Matrix4::Orthographic(-1, 1, 1, -1, -1, 1);
	viewMatrix.ToIdentity();
	UpdateShaderMatrices();
	quad->SetTexture(bufferColourTex[1]);
	quad->Draw();
	glUseProgram(0);
}
void Renderer::DrawSkybox()
{
	glDepthMask(GL_FALSE);
	SetCurrentShader(skyboxShader);

	UpdateShaderMatrices();
	quad->Draw();

	glUseProgram(0);
	glDepthMask(GL_TRUE);
}
void Scene::DrawParticleList(ParticleEmitter* n)
{
	for (auto emitterChild : n->GetChildren()) {

		glUniform1f(glGetUniformLocation(currentShader->GetProgram(), "particleSize"), emitterChild->GetParticleSize());

		UpdateShaderMatrices();

		emitterChild->Draw();
	}
}
Exemple #13
0
void Renderer::RenderScene()	{
	//We start off simply, by just drawing the triangle using a perspective
	//projection. You should recognise what all of this code does!!!
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		// Clear Screen And Depth Buffer

	glUseProgram(currentShader->GetProgram());			//Switch on our shader

	viewMatrix  = camera->BuildViewMatrix();
	projMatrix	= Matrix4::Perspective(1.0f,10000.0f,(float)width/(float)height,45.0f);
	modelMatrix = Matrix4::Scale(Vector3(50,50,50));

	UpdateShaderMatrices();

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);	//New! and to move...

	triangle->Draw();

	//So far, so normal! What we're going to do now though, is work out
	//The triangle's origin position in screen space, and draw a targetting
	//Reticle around it using an orthographic matrix.


	Vector3 screenPos = WorldPosToScreenPos(modelMatrix.GetPositionVector());

	//We now have the screen position, now to draw a quad. We simply set
	//up the orthographic matrix to go from 0-width and 0-height, and
	//draw a quad at screePos (scaled to some appropriate size).

	viewMatrix.ToIdentity();
	projMatrix	= Matrix4::Orthographic(-1,1,width,0,height,0);
	modelMatrix = Matrix4::Translation(screenPos) *
				  Matrix4::Scale(Vector3(25,25,25));

	UpdateShaderMatrices();

	quad->Draw();

	glUseProgram(0);

	SwapBuffers();	
}
void Renderer::DrawScene() {
	glBindFramebuffer(GL_FRAMEBUFFER, bufferFBO);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	SetCurrentShader(sceneShader);
	projMatrix = Matrix4::Perspective(1.0f, 10000.0f, (float)width / (float)height, 45.0f);
	UpdateShaderMatrices();

	heightMap->Draw();

	glUseProgram(0);
	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
}

void Renderer::UpdateScene(float msec) {
	camera -> UpdateCamera(msec);
	viewMatrix = camera -> BuildViewMatrix();
	root->Update(msec);
	/*root->SetTransform(Matrix4::Rotation(f, Vector3(1, 3, 5)));*/
}
void Renderer::RenderScene() {
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	
	glUseProgram(currentShader -> GetProgram());
	UpdateShaderMatrices();
	glUniform1i(glGetUniformLocation(currentShader -> GetProgram(),"diffuseTex"), 0);
	heightMap -> Draw();
Exemple #16
0
void Renderer::RenderScene(){

	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	glUseProgram(currentShader->GetProgram());

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "weightTex"), MD5_WEIGHT_TEXNUM); glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "transformTex"), MD5_TRANSFORM_TEXNUM);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

	UpdateShaderMatrices();
	hellNode->Draw(*this);

	glUseProgram(0);
	SwapBuffers();
}
Exemple #17
0
void Renderer::RenderScene(){
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	glUseProgram(currentShader->GetProgram());
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "bumpTex"), 1);
	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1,(float*)&camera->GetPosition());

	UpdateShaderMatrices();
	SetShaderLight(*light);

	heightMap->Draw();

	glUseProgram(0);
	SwapBuffers();
}
//Blooms each fragment based on its local fragments
void Renderer::Bloom(){
	//Bind our processing FBO and attach the next buffer to be drawn to to it
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
		GL_TEXTURE_2D, GetDrawTarget(), 0);

	//Clear it
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	SetCurrentShader(bloomShader);
	glUniform2f(glGetUniformLocation(currentShader->GetProgram(), "pixelSize"),
		1.0f / width, 1.0f / height);
	UpdateShaderMatrices();

	quad->SetTexture(GetLastDrawn());

	quad->Draw();
	PPDrawn();

}
void Renderer::DrawHeightMap()
{
	SetCurrentShader(lightShader);
	SetShaderLight(*light);
	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, (float*)&camera->GetPosition());

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "bumpTex"), 1);

	modelMatrix.ToIdentity();
	textureMatrix.ToIdentity();

	UpdateShaderMatrices();

	heightMap->Draw();

	glUseProgram(0);
}
//Performs a gaussian blur on the FBO
void Renderer::Blur(){
	//Bind our processing FBO and attach bufferColourTex[1] to it
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
		GL_TEXTURE_2D, GetDrawTarget(), 0);

	//Clear it
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT);

	SetCurrentShader(blurShader);
	glUniform2f(glGetUniformLocation(currentShader->GetProgram(), "pixelSize"),
		1.0f / width, 1.0f / height);
	UpdateShaderMatrices();

	//One pass is actually 2!
	for (int i=0; i < BLUR_PASSES*2; ++i){
		//Bind our buffer colortex[1] to it as a colour attachment
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			GL_TEXTURE_2D, GetDrawTarget(), 0);

		glUniform1i(glGetUniformLocation(currentShader->GetProgram(),
			"isVertical"), 0);

		quad->SetTexture(GetLastDrawn());

		//Draw the scene and blur horizontally
		quad->Draw();
		PPDrawn();

		//Swap the buffers round between being textures and colour buffer
		glUniform1i(glGetUniformLocation(currentShader->GetProgram(),
			"isVertical"), 1);
		glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
			GL_TEXTURE_2D, GetDrawTarget(), 0);

		quad->SetTexture(GetLastDrawn());

		//Draw the scene and blur vertically
		quad->Draw();
		PPDrawn();
	}
}
Exemple #21
0
void Renderer::DrawCombinedScene(){
	SetCurrentShader(sceneShader);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "bumpTex"), 1);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "shadowTex"), 2);

	glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, (float*)&camera->GetPosition());

	SetShaderLight(*light);

	glActiveTexture(GL_TEXTURE2);
	glBindTexture(GL_TEXTURE_2D, shadowTex);

	viewMatrix = camera->BuildViewMatrix();
	UpdateShaderMatrices();

	DrawFloor();
	DrawMesh();

	glUseProgram(0);
}
void Renderer::RenderScene()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);// | = bitwise or, e.g, 010 | 001 = 011, 
																			   // could set 32 T/F options this way without needing a ton of
																			   //parameter variables

	if(usingScissor) 
	{
		glEnable(GL_SCISSOR_TEST);
		glScissor((float)width / 2.5f, (float)height / 2.5f, (float)width / 5.0f, (float)height / 5.0f);
	}

	glUseProgram(currentShader->GetProgram());
	UpdateShaderMatrices();

	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseText"), 0);

	if(usingStencil)
	{
		glEnable(GL_STENCIL_TEST);

		glColorMask(GL_FALSE,GL_FALSE,GL_FALSE,GL_FALSE);
		glStencilFunc(GL_ALWAYS,2, ~0);
		glStencilOp(GL_REPLACE, GL_REPLACE, GL_REPLACE);

		quad->Draw();

		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE,GL_TRUE);
		glStencilFunc(0x205, 2, ~0);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	}
	triangle->Draw();

	glUseProgram(0);
	glDisable(GL_SCISSOR_TEST);
	glDisable(GL_STENCIL_TEST);

	SwapBuffers();
}
//Uploads the specific skybox uniforms and draws it
void Renderer::DrawSkybox(){

	glDepthMask(GL_FALSE);
	glDisable(GL_CULL_FACE);
	SetCurrentShader(skyboxShader);

	//No need to change model matrix
	modelMatrix = Matrix4::GetIdentitiy();
	viewMatrix = camera->BuildViewMatrix();
	projMatrix = cameraProjMat;

	glUniform1f(glGetUniformLocation(currentShader->GetProgram(),
		"blend"), skyboxLight);

	UpdateShaderMatrices();

	quad->Draw();

	glUseProgram(0);
	glDepthMask(GL_TRUE);
	glEnable(GL_CULL_FACE);
}
void Renderer::RenderScene()	{
	glClearColor(0,0,0,1);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glUseProgram(currentShader->GetProgram());
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

	SetShaderParticleSize(emitter->GetParticleSize());
	emitter->SetParticleSize(8.0f);
	emitter->SetParticleVariance(25.0f);
	emitter->SetLaunchParticles(8);
	emitter->SetParticleLifetime(150.0f);
	emitter->SetParticleSpeed(0.3f);
	UpdateShaderMatrices();

	emitter->Draw();



	glUseProgram(0);

	SwapBuffers();
}
Exemple #25
0
void Renderer::DrawShadowScene(){
	glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
	glClear(GL_DEPTH_BUFFER_BIT);

	glViewport(0, 0, SHADOWSIZE, SHADOWSIZE);

	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

	SetCurrentShader(shadowShader);

	viewMatrix = Matrix4::BuildViewMatrix(light->GetPosition(), Vector3(0,0,0));
	textureMatrix = biasMatrix * (projMatrix * viewMatrix);

	UpdateShaderMatrices();
	DrawFloor();
	DrawMesh();

	glUseProgram(0);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glViewport(0, 0, width, height);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}
//int frame_idx = 0;
void Scene::RenderScene()
{
	//Check to see if the window has been resized
	if (m_ScreenTexWidth != width || m_ScreenTexHeight != height)
	{
		BuildScreenFBO();
	}


	//Reset all varying data
	textureMatrix.ToIdentity();
	modelMatrix.ToIdentity();
	viewMatrix = m_Camera->BuildViewMatrix();
	projMatrix = Matrix4::Perspective(0.01f, 1000.0f, (float)width / (float)height, 45.0f);
	m_FrameFrustum.FromMatrix(projMatrix * viewMatrix);



	//Update all Object's World Transform
	UpdateWorldMatrices(m_RootGameObject, Matrix4());

	NCLDebug::SetDebugDrawData(projMatrix * viewMatrix, m_Camera->GetPosition());

	

	//Setup Default Shader Uniforms
	Vector3 camPos = m_Camera->GetPosition();
	//Vector3 lightPos = m_InvLightDirection * -100.0f;
	
	Vector3 lightPos = m_InvLightDirection * -100.0f;

	Vector4 lightPosEyeSpace = viewMatrix * Vector4(lightPos.x, lightPos.y, lightPos.z, 1.0f);

	//SetCurrentShader(m_DefaultLightShader);
	//UpdateShaderMatrices();
	//glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	//glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "ambientColour"), 1, &m_AmbientColour.x);
	//glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "invLightDir"), 1, &m_InvLightDirection.x);
	//glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "cameraPos"), 1, &camPos.x);
	//glUniform1f(glGetUniformLocation(currentShader->GetProgram(), "specularIntensity"), m_SpecularIntensity);

	//SetCurrentShader(m_DefaultShadowShader);
	//UpdateShaderMatrices();
	//glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);
	//glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "ambientColour"), 1, &m_AmbientColour.x);

	//SetCurrentShader(m_ShadowVolumeShader);
	//UpdateShaderMatrices();
	//glUniform3fv(glGetUniformLocation(currentShader->GetProgram(), "invLightDir"), 1, &m_InvLightDirection.x);


	////Setup Render FBO/OpenGL States
	//glBindFramebuffer(GL_FRAMEBUFFER, m_ScreenFBO);
	//glStencilFunc(GL_ALWAYS, 0, 0xFF);
	//glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);

	//glClearColor(clearcolor.x, clearcolor.y, clearcolor.z, clearcolor.w);
	glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);

	/////////////////////////////////////////////////
	glDisable(GL_CULL_FACE);
	glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS);
	//glDepthFunc(GL_ALWAYS);
	glDepthMask(GL_FALSE);//disable the depth buffer, it won't write on depth buffer
	SetCurrentShader(m_skyboxShader);//set skyboxShader to be currentShader


	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "cubeTex"), 0);

	glActiveTexture(GL_TEXTURE0);
	glBindTexture(GL_TEXTURE_CUBE_MAP, cubeMap);

	UpdateShaderMatrices(); //update "modelMatrix" "viewMatrix" "projMatrix" "textureMatrix"


	//SetTextureRepeating(quad->GetTexture(), true);
	quad->Draw(false);

	glUseProgram(0);
	glDepthMask(GL_TRUE);//enable depth buffer

	//glDepthFunc(GL_LEQUAL);
	/////////////////////////////////////////////////

	//glEnable(GL_MULTISAMPLE);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_DEPTH_CLAMP);
	//glEnable(GL_STENCIL_TEST);
	glEnable(GL_CULL_FACE);
	//glEnable(GL_BLEND);
	//glDepthFunc(GL_LEQUAL);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

	//Build Render List
	BuildNodeLists(m_RootGameObject);
	SortNodeLists();

	//Render the Scene in the Dark (As if it were a shadow)
	//SetCurrentShader(m_DefaultShadowShader);
	//DrawNodes(false);

	//Render the Shadow Volumes to the Stencil Buffer
	//SetCurrentShader(m_ShadowVolumeShader);
	//glDepthFunc(GL_LESS);
	//glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);
	//glDepthMask(GL_FALSE);

	//glStencilFunc(GL_ALWAYS, 0, 0xFF);
	//glStencilOpSeparate(GL_FRONT, GL_KEEP, GL_INCR_WRAP, GL_KEEP);
	//glStencilOpSeparate(GL_BACK, GL_KEEP, GL_DECR_WRAP, GL_KEEP);

	//glDisable(GL_CULL_FACE);
	//DrawNodes(false);
	//glEnable(GL_CULL_FACE);
	//

	////Finally Render the Light Sections of the scene where the shadow volumes overlapped
	//glDepthFunc(GL_LEQUAL);
	//glStencilFunc(GL_EQUAL, 0, 0xFF);
	//glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
	//glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	//glDepthMask(GL_TRUE);

	//SetCurrentShader(m_DefaultLightShader);
	//DrawNodes(true);
	viewMatrix = m_Camera->BuildViewMatrix();
	projMatrix = Matrix4::Perspective(1.0f, 1000.0f, (float)width / (float)height, 45.0f);
	DrawShadowScene();
	DrawCominedScene();
	//Clear Render List
	ClearNodeLists();


	//Finally draw all debug data to FBO (this fbo has anti-aliasing and the screen buffer does not)
	glDisable(GL_DEPTH_TEST);
	glStencilFunc(GL_ALWAYS, 0, 0xFF);
	PhysicsEngine::Instance()->DebugRender();

	NCLDebug::SortDebugLists();
	NCLDebug::DrawDebugLists();
	NCLDebug::ClearDebugLists();

	/////////////////////////////////////////////////
	//PARTICLE
	/////////////////////////////////////////////////
	//glClearColor(0, 0, 0, 1);
	//glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glEnable(GL_BLEND);
	glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glEnable(GL_DEPTH_TEST);
	glDepthMask(GL_FALSE);
	SetCurrentShader(m_ParticleShader);
	glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);

	DrawParticleList(m_RootParticleList);

	glDepthMask(GL_TRUE);
	/*glUniform1f(glGetUniformLocation(currentShader->GetProgram(), "particleSize"), emitter->GetParticleSize());
	emitter->SetParticleSize(0.5f);
	emitter->SetParticleVariance(1.0f);
	emitter->SetLaunchParticles(16.0f);
	emitter->SetParticleLifetime(100.0f);
	emitter->SetParticleSpeed(0.1f);
	emitter->SetSourcePosition(Vector3(0, 0, 0));
	UpdateShaderMatrices();

	emitter->Draw();*/


	//-------------------------------------------------------------
	//SetCurrentShader(m_ParticleShader);
	//glUniform1i(glGetUniformLocation(currentShader->GetProgram(), "diffuseTex"), 0);



	/*glUniform1f(glGetUniformLocation(currentShader->GetProgram(), "particleSize"), emitter1->GetParticleSize());
	emitter1->SetParticleSize(5.0f);
	emitter1->SetParticleVariance(1.0f);
	emitter1->SetLaunchParticles(16.0f);
	emitter1->SetParticleLifetime(100.0f);
	emitter1->SetParticleSpeed(0.1f);
	emitter1->SetSourcePosition(Vector3(10, 10, 10));
	UpdateShaderMatrices();

	emitter1->Draw();*/


	/////////////////////////////////////////////////
	//glDepthMask(GL_TRUE);



	////Present our Screen
	//glBindFramebuffer(GL_FRAMEBUFFER, 0);
	//PresentScreenFBO();

	////Swap Buffers and get ready to repeat the process
	//glUseProgram(0);
	SwapBuffers();
}
void Scene::DrawShadowScene()
{
	//Matrix4 tempMatrix = Matrix4::Translation(Vector3((200 * 150) / 2.0f, -90.0f, (200 * 150) / 2));
	Vector3 translate = Vector3((lightList.at(0)).GetPosition());
	//Matrix4 pushMatrix = Matrix4::Translation(translate);
	//Matrix4 popMatrix = Matrix4::Translation(-translate);
	translate += Vector3(-5, -175, 0); //top
	glBindFramebuffer(GL_FRAMEBUFFER, shadowFBO);
	glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, shadowTex, 0);
	glClear(GL_DEPTH_BUFFER_BIT);
	glDrawBuffer(GL_NONE);
	glViewport(0, 0, SHADOWSIZE, SHADOWSIZE);

	glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE);

	SetCurrentShader(ShadowShader);

	/*if (loop < 4) {
	tempMatrix = pushMatrix *
	Matrix4::Rotation(90.0f * loop, Vector3(0.0f, 1.0f, 0.0f))
	* popMatrix;
	}
	else {
	tempMatrix = pushMatrix *
	Matrix4::Rotation(90.0f * (loop == 4 ? 1 : -1), Vector3(1.0f, 0.0f, 0.0f))
	* popMatrix;
	}*/
	//if (loop == 0)
	//	translate += Vector3(-5,-90,0); //top
	//if (loop == 1)
	//	translate += Vector3(-5, 90,0); // floor
	//if (loop == 2)
	//	translate += Vector3(200,-5,0);
	//if (loop == 3)
	//	translate += Vector3(-200,-5,0);
	//if (loop == 4)
	//	translate += Vector3(0,-5,150);
	//if (loop == 5)
	//	translate += Vector3(0,-5,-150);

	//from the light to the middle of the height map
	//viewMatrix = Matrix4::BuildViewMatrix(lightList.at(10).GetPosition(), MiddleOfScene);
	projMatrix = Matrix4::Perspective(1.0f, 15000.0f, (float)width / (float)height, 200.0f);
	//Vector3 pos = tempMatrix.GetPositionVector();
	//Vector3 pos = translate;
	//translate += Vector3(-5,-5,-5);
	//cout << translate << endl;
	viewMatrix = Matrix4::BuildViewMatrix((lightList.at(0)).GetPosition(), translate);
	//ShadowTransMatrix = biasMatrix*(projMatrix * viewMatrix);

	//viewMatrix = Matrix4::BuildViewMatrix(lightList.at(0).GetPosition(), Vector3(0,0,0));
	//textureMatrix = biasMatrix * (projMatrix * viewMatrix);
	(lightList.at(0)).SetlightViewProjMat(biasMatrix * (projMatrix * viewMatrix));

	//Texture matrix is really  = biasMatrix * (light proj Matrix * light view Matrix)

	UpdateShaderMatrices();

	//draw a shadow of each things
	DrawNodes(true);

	glUseProgram(0);
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
	glViewport(0, 0, width, height);

	glBindFramebuffer(GL_FRAMEBUFFER, 0);
}